在C#中将音频和视频文件与FFMPEG合并 [英] Combine audio and video files with FFMPEG in C#

查看:437
本文介绍了在C#中将音频和视频文件与FFMPEG合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在我的C#程序中使用FFMPEG和以下代码合并两个文件,一个音频和一个视频:

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:

所以我没有遇到任何运行时错误,但是它并没有创建我需要的最终output.mp4文件.

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

这篇关于在C#中将音频和视频文件与FFMPEG合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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