我目前正在尝试在我的C#程序中使用FFMPEG和以下代码合并两个文件,一个音频和一个视频:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.FileName = "ffmpeg.exe";
startInfo.Arguments = "ffmpeg -i video.mp4 -i mic.wav -c:v copy -map 0:v:0 -map 1:a:0 -c:a aac -b:a 192k output.mp4";
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
所以我没有遇到任何运行时错误,但是它并没有创建我需要的最终output.mp4
文件。
答案 0 :(得分:2)
我最终通过执行以下操作解决了该问题:
string args = "/c ffmpeg -i \"video.mp4\" -i \"mic.wav\" -shortest outPutFile.mp4";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = @"" + outputPath;
startInfo.Arguments = args;
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
答案 1 :(得分:0)
出于某种原因,TermSpar 给出的答案根本不适合我,代码对我有用:
ProcessStartInfo startInfo = new()
{
CreateNoWindow = false,
FileName = @"C:\Users\User\Documents\ffmpeg.exe",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = string.Format(" -i {0} -i {1} -shortest {2} -y", @"C:\images\video.avi", @"C:\images\voice.wav", @"C:\images\result.avi")
};
using Process exeProcess = Process.Start(startInfo);
//debug
string StdOutVideo = exeProcess.StandardOutput.ReadToEnd();
string StdErrVideo = exeProcess.StandardError.ReadToEnd();
//
exeProcess.WaitForExit();
exeProcess.Close();