简体   繁体   English

ffmpeg c#asp.net视频转换错误

[英]ffmpeg c# asp.net video conversion error

The following code shows error as "StandardOut has not been redirected or the process hasn't started yet." 以下代码显示错误为“ StandardOut尚未重定向或进程尚未开始”。 What is the problem in this code? 这段代码有什么问题? It requires any changes? 需要任何更改吗? It always clear the process by catch exception. 它总是通过catch异常清除过程。

static void ExecuteAsync()
            {
                if (File.Exists("Videos/output.flv"))
                try
                {
                    File.Delete("Videos/output.flv");
                }
                catch
                {
                    return;
                }

            try
            {
                process = new Process();
                ProcessStartInfo info = new ProcessStartInfo(@"e:\ffmpeg\bin\ffmpeg.exe", "-i cars1.flv -same_quant intermediate1.mpg");
                info.CreateNoWindow = false;
                info.UseShellExecute = false;
                info.RedirectStandardError = true;
                info.RedirectStandardOutput = true;
                process.StartInfo = info;
                process.EnableRaisingEvents = true;
                process.ErrorDataReceived += new DataReceivedEventHandler(process_ErrorDataReceived);
                process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
                process.Exited += new EventHandler(process_Exited);
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
            }
            catch (Exception ex)
            {
                if (process != null) process.Dispose();
            }
        }
        static int lineCount = 0;
        static void process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            Console.WriteLine("Input line: {0} ({1:m:s:fff})", lineCount++, DateTime.Now);
            Console.WriteLine(e.Data);
            Console.WriteLine();
        }

        static void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            Console.WriteLine("Output Data Received.");
        }

        static void process_Exited(object sender, EventArgs e)
        {
            process.Dispose();
            Console.WriteLine("Bye bye!");
        }
    }

set this to false: 将此设置为false:

info.RedirectStandardOutput = false;

Documentation says : 文档说:

To use StandardOutput, you must set ProcessStartInfo..::.UseShellExecute to false, and you must set ProcessStartInfo..::.RedirectStandardOutput to true. 若要使用StandardOutput,必须将ProcessStartInfo .. ::。UseShellExecute设置为false,并且必须将ProcessStartInfo .. ::。RedirectStandardOutput设置为true。 Otherwise, reading from the StandardOutput stream throws an exception 否则,从StandardOutput流中读取将引发异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM