使用 Process class 的 C# 应用程序中的 ffmpeg - 标准错误中未显示用户提示

ffmpeg from a C# app using Process class - user prompt not shown in standardError

我正在使用 c# 为 运行 ffmpeg 编写应用程序。我的程序将 standardError 输出重定向到一个流,以便可以对其进行解析以获取进度信息。

在测试过程中我发现了一个问题:

如果输出显示在命令中 window 而不是重定向,ffmpeg 将显示正常 headers 后跟 "file c:\temp\testfile.mpg already exists. overwrite [y]" .如果我单击命令 window 并按 y,程序将继续对文件进行编码。

如果 StandardError 被重定向到我的处理程序,然后打印到控制台,我会看到在命令 window 中显示的相同 header 信息现在打印到控制台。 除了文件...已经存在提示。如果我单击命令 window 并按 y,程序将继续处理文件。

在提示操作员输入信息时是否使用了 standardOutput 或 standardError 以外的流,或者我是否遗漏了其他内容?

public void EncodeVideoWithProgress(string filename, string arguments, BackgroundWorker worker, DoWorkEventArgs e)
    {

        Process proc = new Process();

        proc.StartInfo.FileName = "ffmpeg";
        proc.StartInfo.Arguments = "-i " + " \"" + filename + "\" " + arguments;

        proc.StartInfo.UseShellExecute = false;
        proc.EnableRaisingEvents = true;

        proc.StartInfo.RedirectStandardError = true;
        proc.StartInfo.RedirectStandardOutput = false;
        proc.StartInfo.CreateNoWindow = false; //set to true for testing

        proc.ErrorDataReceived += new DataReceivedEventHandler(NetErrorDataHandler);

        proc.Start();
        proc.BeginErrorReadLine();


        StreamReader reader = proc.StandardOutput;
         string line;
         while ((line = reader.ReadLine()) != null)
        { Console.WriteLine(line); }
     proc.WaitForExit();
}

private static void NetErrorDataHandler(object sendingProcess,
               DataReceivedEventArgs errLine)
    {
        if (!String.IsNullOrEmpty(errLine.Data))
        {
            Console.WriteLine(errLine.Data);
        }
    }

与其遍历所有这些内容,不如在启动进程时使用“-y”命令行选项,这将强制 ffmpeg 覆盖现有文件。