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

标签 c# asp.net video ffmpeg

以下代码将错误显示为“StandardOut 尚未重定向或进程尚未启动”。这段代码有什么问题?它需要任何改变吗?它总是通过捕获异常来清除进程。

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

最佳答案

将此设置为false:

info.RedirectStandardOutput = false;

文档说:

To use StandardOutput, you must set ProcessStartInfo..::.UseShellExecute to false, and you must set ProcessStartInfo..::.RedirectStandardOutput to true. Otherwise, reading from the StandardOutput stream throws an exception

关于c# - ffmpeg c# asp.net视频转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10431361/

相关文章:

asp.net - 为什么ASP.NET Identity中的注销使用POST而不是GET?

android - 视频适合android中的屏幕

matlab - 逐帧读取和显示视频文件

c# - 为值设置属性 [NonSerialized]

c# - 拖放 Accordion 面板? (ASP.Net)

asp.net - 优化了从网站请求时返回 404 的 bundle

asp.net - 如何计算 asp 转发器中的项目数?

iphone - 如何将视频添加到应用程序

C# 如果值不为 null,为什么 Linq 会因 Null 而崩溃?

c# - 重写 C# 的 Monitor.Enter 和 Monitor.Exit