弹来弹去跑马灯!

C# 调用FFmpeg 合并视频和音频

C#修改环境变量:

1
2
3
4
5
string pathStr = System.Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
            // 修改系统环境变量Path值
            System.Environment.SetEnvironmentVariable("Path", pathStr + ";D:\\KK", EnvironmentVariableTarget.Machine);
 
//D:\\KK 是新加的值

  

 

C#调用FFmpeg合并视频个音频:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
void Test()
        {
 
            string ffmpegPath = @"D:\Soft\ffmpeg\bin\ffmpeg.exe"// 替换为你的FFmpeg可执行文件路径
            string videoFile = @"C:\Users\Administrator\Desktop\work\1\idle.mp4"// 替换为要合并的视频文件路径
            string audioFile = @"D:\dl.mp3"// 替换为要合并的音频文件路径
            string outputFile = @"D:\ok.mp4"// 替换为输出文件的保存路径和名称
 
            string arguments = $"-i \"{videoFile}\" -i \"{audioFile}\" -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 \"{outputFile}\"";
 
            ProcessStartInfo psi = new ProcessStartInfo(ffmpegPath)
            {
                Arguments = arguments,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };
 
            Process process = new Process();
            process.StartInfo = psi;
            process.OutputDataReceived += (sender, eventArgs) =>
            {
                //Title=("FFmpeg output: " + eventArgs.Data);
            };
            process.ErrorDataReceived += (sender, eventArgs) =>
            {
               // Title=("FFmpeg error: " + eventArgs.Data);
            };
 
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();
 
            Title=("合并完成");
 
        }

  

posted @   wgscd  阅读(150)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2021-07-19 c#
2018-07-19 c# update check
点击右上角即可分享
微信分享提示