public static async Task <string> GetFfmpegOutputAsync(string path, string args, string lineFilter = "") { Process process = OsUtils.NewProcess(true); process.StartInfo.Arguments = $"/C cd /D {GetAvPath().Wrap()} & ffmpeg.exe -hide_banner -y -stats -i {path.Wrap()} {args}"; return(await GetInfoAsync(path, process, lineFilter, false)); }
public static async Task <string> 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" : ""; string streamSelect = (streamIndex >= 0) ? $"-select_streams {streamIndex}" : ""; process.StartInfo.Arguments = $"/C cd /D {GetAvPath().Wrap()} & ffprobe -v quiet {showFormat} {showStreams} {streamSelect} {path.Wrap()}"; return(await GetInfoAsync(path, process, lineFilter, stripKeyName)); }
public static async Task <string> RunFfprobe(string args, LogMode logMode = LogMode.Hidden, string loglevel = "quiet") { bool show = Config.GetInt(Config.Key.cmdDebugMode) > 0; string processOutput = ""; Process ffprobe = OsUtils.NewProcess(!show); NmkdStopwatch timeSinceLastOutput = new NmkdStopwatch(); lastAvProcess = ffprobe; if (string.IsNullOrWhiteSpace(loglevel)) { loglevel = defLogLevel; } ffprobe.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffprobe -v {loglevel} {args}"; if (logMode != LogMode.Hidden) { Logger.Log("Running FFprobe...", false); } Logger.Log($"ffprobe -v {loglevel} {args}", true, false, "ffmpeg"); if (!show) { ffprobe.OutputDataReceived += (sender, outLine) => { AvOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, false); timeSinceLastOutput.sw.Restart(); }; ffprobe.ErrorDataReceived += (sender, outLine) => { AvOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, false); timeSinceLastOutput.sw.Restart(); }; } ffprobe.Start(); ffprobe.PriorityClass = ProcessPriorityClass.BelowNormal; if (!show) { ffprobe.BeginOutputReadLine(); ffprobe.BeginErrorReadLine(); } while (!ffprobe.HasExited) { await Task.Delay(10); } while (timeSinceLastOutput.ElapsedMs < 200) { await Task.Delay(50); } return(processOutput); }
public static string GetFfprobeOutput(string args) { Process ffprobe = OsUtils.NewProcess(true); ffprobe.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffprobe.exe {args}"; Logger.Log($"ffprobe {args}", true, false, "ffmpeg"); ffprobe.Start(); ffprobe.WaitForExit(); string output = ffprobe.StandardOutput.ReadToEnd(); string err = ffprobe.StandardError.ReadToEnd(); if (!string.IsNullOrWhiteSpace(err)) { output += "\n" + err; } return(output); }
public static async Task <string> RunFfmpeg(string args, string workingDir, LogMode logMode, string loglevel, bool reliableOutput = true, bool progressBar = false) { bool show = Config.GetInt(Config.Key.cmdDebugMode) > 0; string processOutput = ""; Process ffmpeg = OsUtils.NewProcess(!show); NmkdStopwatch timeSinceLastOutput = new NmkdStopwatch(); lastAvProcess = ffmpeg; if (string.IsNullOrWhiteSpace(loglevel)) { loglevel = defLogLevel; } string beforeArgs = $"-hide_banner -stats -loglevel {loglevel} -y"; if (!string.IsNullOrWhiteSpace(workingDir)) { ffmpeg.StartInfo.Arguments = $"{GetCmdArg()} cd /D {workingDir.Wrap()} & {Path.Combine(GetAvDir(), "ffmpeg.exe").Wrap()} {beforeArgs} {args}"; } else { ffmpeg.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffmpeg {beforeArgs} {args}"; } if (logMode != LogMode.Hidden) { Logger.Log("Running FFmpeg...", false); } Logger.Log($"ffmpeg {beforeArgs} {args}", true, false, "ffmpeg"); if (!show) { ffmpeg.OutputDataReceived += (sender, outLine) => { AvOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, progressBar); timeSinceLastOutput.sw.Restart(); }; ffmpeg.ErrorDataReceived += (sender, outLine) => { AvOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, progressBar); timeSinceLastOutput.sw.Restart(); }; } ffmpeg.Start(); ffmpeg.PriorityClass = ProcessPriorityClass.BelowNormal; if (!show) { ffmpeg.BeginOutputReadLine(); ffmpeg.BeginErrorReadLine(); } while (!ffmpeg.HasExited) { await Task.Delay(10); } while (reliableOutput && timeSinceLastOutput.ElapsedMs < 200) { await Task.Delay(50); } if (progressBar) { Program.mainForm.SetProgress(0); } return(processOutput); }