//创建并启动一个新进程
Process p = new Process();
//设置进程启动信息属性StartInfo,这是ProcessStartInfo类,包括了一些属性和方法:
p.StartInfo.FileName =AppDomain.CurrentDomain.BaseDirectory+"/ffmpeg.exe"; //程序名,可执行文件的存放路径
p.StartInfo.UseShellExecute =false;
//-y选项的意思是当输出文件存在的时候自动覆盖输出文件,不提示“y/n”这样才能自动化
p.StartInfo.Arguments ="-i "+srcFileName+"-y -ab 56 -ar22050 -b 800 -r 29.97 -s 420x340 "+destFileName; //执行参数 srcFileName为需要进行视频转换的源文件 , destFileName为转换后的文件名称
p.StartInfo.RedirectStandardInput =true; //对标准输入进行重定向
p.StartInfo.RedirectStandardOutput =true; //对标准输出进行重定向
p.StartInfo.RedirectStandardError =true;//把外部程序错误输出写到StandardError流中
p.ErrorDataReceived +=newDataReceivedEventHandler(p_ErrorDataReceived);
p.OutputDataReceived +=newDataReceivedEventHandler(p_OutputDataReceived);
p.Start();
p.BeginErrorReadLine();//开始异步读取
p.WaitForExit();//阻塞等待进程结束
p.Close();//关闭进程
p.Dispose();//释放资源
本文介绍了如何使用C#创建并启动FFMPEG进程,通过设置ProcessStartInfo来指定可执行文件路径、执行参数以及重定向标准输入、输出和错误流,实现自动化视频转换。
1016

被折叠的 条评论
为什么被折叠?



