Update FFmpegWrapper.cs

This commit is contained in:
rlauuzo 2024-06-14 16:42:15 +02:00 committed by TwistedUmbrellaX
parent b101d8f8a4
commit d351a6225e

View File

@ -417,55 +417,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)
if (ffmpeg.WaitForExit(timeout))
{ {
ffmpeg.Dispose(); Logger?.LogDebug("ffmpeg priority could not be modified. {Message}", e.Message);
} }
var output = ms.ToArray(); using (var ms = new MemoryStream())
// If caching is enabled, cache the output of this command.
if (cacheOutput)
{ {
File.WriteAllBytes(cacheFilename, output); var buf = new byte[4096];
} int bytesRead;
return output; 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;
}
} }
} }