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

。_饼干妹妹 提交于 2019-12-23 03:45:30

问题


I am writing an app to run ffmpeg using c#. My program redirects the standardError output to a stream so it can be parsed for progress information.

During testing I have found a problem:

If the output is shown in a command window rather than being redirected ffmpeg will display it's normal headers followed by "file c:\temp\testfile.mpg already exists. overwrite [y]". If I click on the command window and press y the program continues to encode the file.

If the StandardError is redirected to my handler and then printed to the console, I see the same header information that was displayed in the command window now printed to the console. except for the file...already exists prompt. If I click in the command window and press y the program continues to process the file.

Is there a stream other than standardOutput or standardError that is used when the operator is prompted for information, or am I missing something else?

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);
        }
    }

回答1:


Rather than going through all this stuff, use the "-y" command line option when you start the process, which will force ffmpeg to overwrite existing files.



来源:https://stackoverflow.com/questions/36758899/ffmpeg-from-a-c-sharp-app-using-process-class-user-prompt-not-shown-in-standar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!