简体   繁体   中英

Combine audio and video files with FFMPEG in C#

I'm currently trying to combine two files, one audio and one video, in my C# program using FFMPEG with the following code:

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();
                }

My debug folder is set up like this: 在此处输入图片说明

So I don't get any runtime errors, however it just doesn't create the final output.mp4 file that I need it to.

I ended up solving it by doing the following:

 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();
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM