Retain original color space when encoding, cache ffmpeg/ffprobe outputs

This commit is contained in:
N00MKRAD
2021-05-06 12:08:03 +02:00
parent 58e3f3e4f0
commit 55c0f5904c
11 changed files with 274 additions and 46 deletions

View File

@@ -12,6 +12,9 @@ using DiskDetector;
using DiskDetector.Models;
using Microsoft.VisualBasic.Devices;
using Flowframes.Extensions;
using Flowframes.MiscUtils;
using System.Threading;
using System.Linq;
namespace Flowframes.OS
{
@@ -176,5 +179,32 @@ namespace Flowframes.OS
return children;
}
public static async Task<string> GetOutputAsync(Process process, bool onlyLastLine = false)
{
Logger.Log($"Getting output for {process.StartInfo.FileName} {process.StartInfo.Arguments}", true);
NmkdStopwatch sw = new NmkdStopwatch();
Stopwatch timeSinceLastOutput = new Stopwatch();
timeSinceLastOutput.Restart();
string output = "";
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => output += $"{e.Data}\n";
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => output += $"{e.Data}\n";
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
while (!process.HasExited) await Task.Delay(50);
while (timeSinceLastOutput.ElapsedMilliseconds < 100) await Task.Delay(50);
output = output.Trim('\r', '\n');
Logger.Log($"Output (after {sw.GetElapsedStr()}): " + output.Replace("\r", " / ").Replace("\n", " / "), true);
if (onlyLastLine)
output = output.SplitIntoLines().LastOrDefault();
return output;
}
}
}