I am writing an application to run ffmpeg using C #. My program redirects the output of standardError to a stream, so it can be parsed for progress information.
During testing, I found a problem:
If the output is displayed in the command window and not redirected, ffmpeg will display its normal headers, and then "the 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 a 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, which now prints to the console. besides the file ... a request already exists . If I click in the command window and press y, the program will continue processing the file.
Is there a stream other than standardOutput or standardError, which is used when the operator requests 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); } }
source share