diff --git a/CodeLegacy/Media/GetVideoInfo.cs b/CodeLegacy/Media/GetVideoInfo.cs index 04e84fe..c7e9e0b 100644 --- a/CodeLegacy/Media/GetVideoInfo.cs +++ b/CodeLegacy/Media/GetVideoInfo.cs @@ -27,23 +27,18 @@ namespace Flowframes.Media public static async Task GetFfmpegOutputAsync(string path, string argsIn, string argsOut, string lineFilter = "", bool noCache = false) { - Process process = OsUtils.NewProcess(true); - process.StartInfo.Arguments = $"/C cd /D {AvProcess.GetAvDir().Wrap()} & " + - $"ffmpeg.exe -hide_banner -y {argsIn} {path.GetConcStr()} -i {path.Wrap()} {argsOut}"; + string cmd = $"ffmpeg -hide_banner -y {argsIn} {path.GetConcStr()} -i {path.Wrap()} {argsOut}"; + Process process = OsUtils.NewProcess(true, args: cmd); return await GetInfoAsync(path, process, lineFilter, noCache); } public static async Task GetFfprobeInfoAsync(string path, FfprobeMode mode, string lineFilter = "", int streamIndex = -1, bool stripKeyName = true) { - Process process = OsUtils.NewProcess(true); - string showFormat = mode == FfprobeMode.ShowBoth || mode == FfprobeMode.ShowFormat ? "-show_format" : ""; - string showStreams = mode == FfprobeMode.ShowBoth || mode == FfprobeMode.ShowStreams ? "-show_streams" : ""; - - process.StartInfo.Arguments = $"/C cd /D {AvProcess.GetAvDir().Wrap()} & " + - $"ffprobe -v quiet {path.GetConcStr()} {showFormat} {showStreams} {path.Wrap()}"; - + string showFormat = mode == FfprobeMode.ShowBoth || mode == FfprobeMode.ShowFormat ? "-show_format " : ""; + string showStreams = mode == FfprobeMode.ShowBoth || mode == FfprobeMode.ShowStreams ? "-show_streams " : ""; + string cmd = $"ffprobe -v quiet {path.GetConcStr()} {showFormat}{showStreams}{path.Wrap()}"; + Process process = OsUtils.NewProcess(true, args: cmd); string output = await GetInfoAsync(path, process, lineFilter, streamIndex, stripKeyName); - return output; } diff --git a/CodeLegacy/Os/OsUtils.cs b/CodeLegacy/Os/OsUtils.cs index d2a6033..20a68ed 100644 --- a/CodeLegacy/Os/OsUtils.cs +++ b/CodeLegacy/Os/OsUtils.cs @@ -1,5 +1,6 @@ using DiskDetector; using DiskDetector.Models; +using Flowframes.Extensions; using Flowframes.MiscUtils; using Microsoft.VisualBasic.Devices; using Microsoft.Win32; @@ -93,10 +94,19 @@ namespace Flowframes.Os } } - public static Process NewProcess(bool hidden, string filename = "cmd.exe") + public static Process NewProcess(bool hidden, string filename = "cmd.exe", string args = "", bool setFfEnv = true) { Process proc = new Process(); - return SetStartInfo(proc, hidden, filename); + proc = SetStartInfo(proc, hidden, filename); + proc.StartInfo.Arguments = args.IsEmpty() ? proc.StartInfo.Arguments : $"/C {args}"; + if (setFfEnv) + SetFfEnv(proc.StartInfo); + return proc; + } + + public static void SetFfEnv(ProcessStartInfo psi) + { + psi.AddPath(AvProcess.GetAvDir()); // Add A/V binaries to PATH to ensure bundled ffmpeg/ffprobe are used } public static void KillProcessTree(int pid)