Update FFmpegWrapper.cs (#200)

This commit is contained in:
rlauuzo 2024-06-14 17:11:04 +02:00 committed by GitHub
parent 508ab9897f
commit a9cdaf66b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -415,52 +415,46 @@ public static class FFmpegWrapper
RedirectStandardError = stderr RedirectStandardError = stderr
}; };
var ffmpeg = new Process using (var ffmpeg = new Process { StartInfo = info })
{ {
StartInfo = info Logger?.LogDebug("Starting ffmpeg with the following arguments: {Arguments}", ffmpeg.StartInfo.Arguments);
};
Logger?.LogDebug( ffmpeg.Start();
"Starting ffmpeg with the following arguments: {Arguments}",
ffmpeg.StartInfo.Arguments);
ffmpeg.Start(); try
try
{
ffmpeg.PriorityClass = Plugin.Instance?.Configuration.ProcessPriority ?? ProcessPriorityClass.BelowNormal;
}
catch (Exception e)
{
Logger?.LogDebug(
"ffmpeg priority could not be modified. {Message}",
e.Message);
}
using (MemoryStream ms = new MemoryStream())
{
var buf = new byte[4096];
var bytesRead = 0;
do
{ {
var streamReader = stderr ? ffmpeg.StandardError : ffmpeg.StandardOutput; ffmpeg.PriorityClass = Plugin.Instance?.Configuration.ProcessPriority ?? ProcessPriorityClass.BelowNormal;
bytesRead = streamReader.BaseStream.Read(buf, 0, buf.Length);
ms.Write(buf, 0, bytesRead);
} }
while (bytesRead > 0); catch (Exception e)
ffmpeg.WaitForExit(timeout);
var output = ms.ToArray();
// If caching is enabled, cache the output of this command.
if (cacheOutput)
{ {
File.WriteAllBytes(cacheFilename, output); Logger?.LogDebug("ffmpeg priority could not be modified. {Message}", e.Message);
} }
return output; using (var ms = new MemoryStream())
{
var buf = new byte[4096];
int bytesRead;
using (var streamReader = stderr ? ffmpeg.StandardError : ffmpeg.StandardOutput)
{
while ((bytesRead = streamReader.BaseStream.Read(buf, 0, buf.Length)) > 0)
{
ms.Write(buf, 0, bytesRead);
}
}
ffmpeg.WaitForExit(timeout);
var output = ms.ToArray();
// If caching is enabled, cache the output of this command.
if (cacheOutput)
{
File.WriteAllBytes(cacheFilename, output);
}
return output;
}
} }
} }