FFmpeg在混音中设置音量(mp4+mp3混音)

2,903 阅读1分钟

stackoverflow.com/questions/4…

我一直在尝试将音频 mp3 与视频 mp4 混合,同时保留 mp4 音频。

ffmpeg -y  -i video.mp4 -i audio.mp3
 -filter_complex "[0:a][1:a]amix=inputs=2:duration=longest[out]" 
 -map 0:v -map [out] output.mp4

我现在正在尝试调整声音文件(视频 0.5,音频 1)的音量作为混音的一部分。

ffmpeg  -i 020c276b-face-4bb3-9169-e8969c1232ba.mp4 -i test.mp3 -filter_complex 
 "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1]; 
  [1:a]aformat=sample_fmts fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2]; 
  [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]"-map 1:v -map [out]
  -c:v copy -c:a aac -strict -2  output2.mp4`

我收到错误!!!

有谁知道如何使我在上面编写的代码有效,还可以更改输入的音量吗?

回答1:(最佳答案)

如果您想使用,amix 我建议您像这样使用它:

video_path = "E:\pyvideo\"# 添加背景音乐
cmd = FFmpeg + ' -i %s\\out.mp4 -i %s\\1.mp3 -filter_complex "[0:a]volume=1[a0];[1:a]volume=0.2[a1];[a0][a1]amix=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -c:a aac -shortest %s\\output.mp4' % (video_path, video_path, video_path)
process = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE,universal_newlines=True, shell=True)
videoInfo = compute_progress_and_send_progress(process)

原回答:

ffmpeg -i video.mp4 -i audio.mp3 -filter_complex \
"[0:a]volume=0.8[a0]; \
[1:a]volume=0.8[a1]; \
[a0][a1]amix=inputs=2[a]" \
-map 0:v -map "[a]" -c:v copy -c:a aac -shortest output.mp4 ;

对于amerge方法:

ffmpeg -i video.mp4 -i audio.mp3 -filter_complex \
"[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a0]; \
[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a1]; \
[a0][a1]amerge,pan=stereo|c0<c0+c2|c1<c1+c3 [a]" \
-map 0:v -map "[a]" -c:v copy -c:a aac -strict -2 -shortest output.mp4 ;

amerge

amix

默认情况下

,以最短的输入(总是)

终止并以最长的输入终止。

因此,当流的长度不同时,前者将始终截断。

-y出于测试目的省略标志。

回答2:

这个答案有效

superuser.com/questions/7…

> ffmpeg -i audio.mp3 -i  video.mp4 -filter_complex
> "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.5[a1];
> [1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.8[a2];
> [a1][a2]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]" -map 1:v -map
> "[out]" -c:v copy -c:a aac -strict -2 -shortest output.mp4