使用System.Diagnostics.Process执行ffmpeg命令时出错 [英] Error while executing ffmpeg command using System.Diagnostics.Process

查看:244
本文介绍了使用System.Diagnostics.Process执行ffmpeg命令时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临着一个非常棘手的问题,其中相同的命令在通过直接命令提示符手动执行时有效,但是在通过System.Diagnostics.Process运行命令时会发生错误.该命令涉及向视频添加水印 如下:

I am facing this really wierd issue wherein the same command works while manually executed via straight forward command prompt but an error occurs when running the command via System.Diagnostics.Process. The command involves adding a watermark to the video and is as follows:

ffmpeg -i〜Path〜\ Great.wmv" -f mp4 -vf"movie = AppImage.png [wm]; [in] [wm] overlay = main_w-overlay_w-10:main_h-overlay_h-10
  [out]" 〜Path〜\ Great_Output.mp4"

ffmpeg -i "~Path~\Great.wmv" -f mp4 -vf "movie=AppImage.png [wm];[in][wm] overlay=main_w-overlay_w-10:main_h-overlay_h-10
 [out]" "~Path~\Great_Output.mp4"

现在,提到的AppImage.png与ffmpeg exe位于同一目录中.该命令可以在命令提示符下完美执行,并且所生成的mp4视频带有水印.

Now the AppImage.png mentioned exists within the same directory as the ffmpeg exe. This command gets executed flawlessly on the command prompt and the mp4 video generated has the watermark.

现在这是我用来使用Diagnostics.Process执行同一命令的代码

Now here's the code I am using to execute the same command using Diagnostics.Process

string s ="\" movie = AppImage.png [wm]; [in] [wm] overlay = main_w-overlay_w-10:main_h-overlay_h-10 [out] \";
字符串参数="-f mp4 -vf" + s;
字符串FFMPEGPath =〜Path〜\\ ffmpeg.exe";
字符串CommandLine ="-i" +"\"〜Path〜\\ Great.wmv \" +" " +参数+" " +"\"〜Path〜\\ Great_Output.mp4 \"; 
System.Diagnostics.Process myProcess =新的System.Diagnostics.Process();
         

string s = "\"movie=AppImage.png [wm];[in][wm] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]\"";
string Params = "-f mp4 -vf " + s;
string FFMPEGPath = "~Path~\\ffmpeg.exe";
string CommandLine = "-i " + "\"~Path~\\Great.wmv\"" + " " + Params + " " + "\"~Path~\\Great_Output.mp4\""; 
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
          

myProcess.StartInfo.FileName = FFMPEGPath;
myProcess.StartInfo.Arguments =命令行;
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;

myProcess.StartInfo.FileName = FFMPEGPath;
myProcess.StartInfo.Arguments = CommandLine;
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;

myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.ErrorDialog = true;

myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.ErrorDialog = true;

myProcess.StartInfo.CreateNoWindow = false;
           
myProcess.Start();
字符串str1 = myProcess.StandardError.ReadToEnd();

myProcess.StartInfo.CreateNoWindow = false;
            
myProcess.Start();
string str1 = myProcess.StandardError.ReadToEnd();

现在上面给出的任何路径或转义字符都没有问题,我可以向您保证.在调试上述代码时遇到的StandardError是:

Now there is nothing wrong with any of the paths or escape characters given above I can assure you that. The StandardError that I get while debugging the above code is:

"无法avformat_open_input'AppImage.png'
使用参数'AppImage.png'初始化过滤器'电影'时出错
打开过滤器时出错!"

"Failed to avformat_open_input 'AppImage.png'
Error initializing filter 'movie' with args 'AppImage.png'
Error opening filters!"

请帮忙,因为自从过去两天以来我一直陷入困境!

Please help as I am stuck in this runt since the past two days!!

-谢谢

Tinu

推荐答案

可能您想将参数放在start方法中,例如

Probably you want to put the argument in the start method like

http://msdn.microsoft.com/en-us/library/h6ak8zt5.aspx

chanmm


这篇关于使用System.Diagnostics.Process执行ffmpeg命令时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆