C#调用ffmpeg

xiaoxiao2025-04-14  16

 public void ConvertVideo(string strArg)         {             Process p = new Process();//建立外部调用线程             p.StartInfo.FileName = ffmpegPath;//要调用外部程序的绝对路径             p.StartInfo.Arguments = strArg;             p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)             p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...这是我耗费了2个多月得出来的经验...mencoder就是用standardOutput来捕获的)             p.StartInfo.CreateNoWindow = false;//不创建进程窗口             p.ErrorDataReceived += new DataReceivedEventHandler(Output);//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN             p.Start();//启动线程             p.BeginErrorReadLine();//开始异步读取             p.WaitForExit();//阻塞等待进程结束             p.Close();//关闭进程             p.Dispose();//释放资源         }

 private void Output(object sendProcess, DataReceivedEventArgs output)         {             if (!String.IsNullOrEmpty(output.Data))             {                 //处理方法...                 Console.WriteLine(output.Data);             }         }

strArg 为ffmpeg 命令 可以在我的其他博客中查找

转载请注明原文地址: https://www.6miu.com/read-5028272.html

最新回复(0)