C# 调用FFmpeg 合并视频和音频
C#修改环境变量:
string pathStr = System.Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
// 修改系统环境变量Path值
System.Environment.SetEnvironmentVariable("Path", pathStr + ";D:\\KK", EnvironmentVariableTarget.Machine);
//D:\\KK 是新加的值
C#调用FFmpeg合并视频个音频:
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=("合并完成");
}
fffffffffffffffff
test red font.