Merge pull request #1335 from Bond-009/ffmpeglimit
Limit amount of ffmpeg processes extracting images at once
This commit is contained in:
commit
2216a271bb
|
@ -53,7 +53,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
private readonly int DefaultImageExtractionTimeoutMs;
|
private readonly int DefaultImageExtractionTimeoutMs;
|
||||||
private readonly string StartupOptionFFmpegPath;
|
private readonly string StartupOptionFFmpegPath;
|
||||||
|
|
||||||
private readonly SemaphoreSlim _thumbnailResourcePool = new SemaphoreSlim(1, 1);
|
private readonly SemaphoreSlim _thumbnailResourcePool = new SemaphoreSlim(2, 2);
|
||||||
private readonly List<ProcessWrapper> _runningProcesses = new List<ProcessWrapper>();
|
private readonly List<ProcessWrapper> _runningProcesses = new List<ProcessWrapper>();
|
||||||
private readonly ILocalizationManager _localization;
|
private readonly ILocalizationManager _localization;
|
||||||
|
|
||||||
|
@ -582,19 +582,27 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
{
|
{
|
||||||
bool ranToCompletion;
|
bool ranToCompletion;
|
||||||
|
|
||||||
StartProcess(processWrapper);
|
await _thumbnailResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
try
|
||||||
var timeoutMs = ConfigurationManager.Configuration.ImageExtractionTimeoutMs;
|
|
||||||
if (timeoutMs <= 0)
|
|
||||||
{
|
{
|
||||||
timeoutMs = DefaultImageExtractionTimeoutMs;
|
StartProcess(processWrapper);
|
||||||
|
|
||||||
|
var timeoutMs = ConfigurationManager.Configuration.ImageExtractionTimeoutMs;
|
||||||
|
if (timeoutMs <= 0)
|
||||||
|
{
|
||||||
|
timeoutMs = DefaultImageExtractionTimeoutMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
ranToCompletion = await process.WaitForExitAsync(timeoutMs).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!ranToCompletion)
|
||||||
|
{
|
||||||
|
StopProcess(processWrapper, 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
ranToCompletion = await process.WaitForExitAsync(timeoutMs).ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (!ranToCompletion)
|
|
||||||
{
|
{
|
||||||
StopProcess(processWrapper, 1000);
|
_thumbnailResourcePool.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1;
|
var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1;
|
||||||
|
@ -625,7 +633,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
return time.ToString(@"hh\:mm\:ss\.fff", UsCulture);
|
return time.ToString(@"hh\:mm\:ss\.fff", UsCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ExtractVideoImagesOnInterval(string[] inputFiles,
|
public async Task ExtractVideoImagesOnInterval(
|
||||||
|
string[] inputFiles,
|
||||||
string container,
|
string container,
|
||||||
MediaStream videoStream,
|
MediaStream videoStream,
|
||||||
MediaProtocol protocol,
|
MediaProtocol protocol,
|
||||||
|
@ -636,8 +645,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
int? maxWidth,
|
int? maxWidth,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var resourcePool = _thumbnailResourcePool;
|
|
||||||
|
|
||||||
var inputArgument = GetInputArgument(inputFiles, protocol);
|
var inputArgument = GetInputArgument(inputFiles, protocol);
|
||||||
|
|
||||||
var vf = "fps=fps=1/" + interval.TotalSeconds.ToString(UsCulture);
|
var vf = "fps=fps=1/" + interval.TotalSeconds.ToString(UsCulture);
|
||||||
|
@ -701,7 +708,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
|
|
||||||
_logger.LogInformation(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
|
_logger.LogInformation(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
|
||||||
|
|
||||||
await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
await _thumbnailResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
bool ranToCompletion = false;
|
bool ranToCompletion = false;
|
||||||
|
|
||||||
|
@ -742,7 +749,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
resourcePool.Release();
|
_thumbnailResourcePool.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1;
|
var exitCode = ranToCompletion ? processWrapper.ExitCode ?? 0 : -1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user