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=("合併完成"); }