我尝试使用System.Diagnostics.Process执行以下代码(来源:http://geekswithblogs.net/PearlFactory/archive/2011/11/23/convert-mp3-to-aacflac-to-aac-or-any-other-combination.aspx)。它在命令行中运行良好。但是在C#中它失败了字符。
var myProcess = new Process();
var p = new ProcessStartInfo();
var sArgs = " -i emp.mp3 -f wav - | neroAacEnc -ignorelength -q 0.5 -if - -of emp.mp4";
p.FileName = "ffmpeg.exe";
p.CreateNoWindow = false;
p.RedirectStandardOutput = false;
p.UseShellExecute = false;
p.Arguments = sArgs;
myProcess.StartInfo = p;
myProcess.Start();
myProcess.WaitForExit();
它出现以下错误:
无法为' |':无效参数
找到合适的输出格式
我在stackoverflow上环顾四周,发现了以下提示,但它也无效:
var psi = new ProcessStartInfo("ffmpeg.exe");
psi.Arguments = "\"-i emp.mp3 -f wav -\" | \"neroAacEnc -ignorelength -q 0.5 -if - -of emp.mp4\"";
psi.CreateNoWindow = false;
psi.UseShellExecute = false;
var process = new Process { StartInfo = psi };
process.Start();
process.WaitForExit();
给出以下错误:
无法识别的选项'我emp.mp3 -f wav - '
无法设置值' |'选项'我emp.mp3 -f wav - '
答案 0 :(得分:5)
感谢Lee他的评论,问题已得到解决。只需调用cmd.exe并将完整命令传递给它:
var myProcess = new Process();
var p = new ProcessStartInfo("cmd.exe");
var sArgs = "/C ffmpeg.exe -i emp.mp3 -f wav - | neroAacEnc -ignorelength -q 0.5 -if - -of emp.mp4";
p.CreateNoWindow = false;
p.RedirectStandardOutput = false;
p.UseShellExecute = false;
p.Arguments = sArgs;
myProcess.StartInfo = p;
myProcess.Start();
myProcess.WaitForExit();