使用Process类的C#应用程序中的ffmpeg-用户提示未显示在standardError中

本文关键字:提示 显示 standardError 用户 类的 Process 应用程序 使用 ffmpeg- | 更新日期: 2024-10-23 07:19:21

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

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

如果输出显示在命令窗口中,而不是重定向,则ffmpeg将显示它的正常标头,后跟"文件c:''temp''testfile.mpg已存在。overwrite[y]"。如果我点击命令窗口并按y,程序将继续对文件进行编码。

如果StandardError被重定向到我的处理程序,然后打印到控制台,我会看到与现在打印到控制台的命令窗口中显示的标题信息相同的标题信息除了文件。。。已存在提示。如果我在命令窗口中单击并按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);
        }
    }

使用Process类的C#应用程序中的ffmpeg-用户提示未显示在standardError中

在启动进程时使用"-y"命令行选项,而不是浏览所有这些内容,这将强制ffmpeg覆盖现有文件。