如何在特定时间为特定持续时间向视频添加多个音频

How to add multiple audio to a video at specific time for specific duration

我有一个20秒没有音频流的video.mp4文件,我有2个音频文件audio1.mp3和audio2.mp3。我想要的是音频 1 应该在 3 秒开始播放 5 秒,音频 2 应该在 10 秒开始播放 6 秒。

ffmpeg -y -i video1.mp4 -i audio1.mp3 -i audio2.mp3 -filter_complex "[1]adelay=3000|3000[aud1];[2]adelay=10000|10000[aud2];[aud1][aud2]amix=2,apad[a];
[0][a]amix=duration=first[a]" -map 0:v -map "[a]" -c:v copy -ac 2 output.mp4

我想要实现的是最终输出将是一个 20 秒的视频,其中音频 1 将在 3 秒到 8 秒开始播放,音频 2 将从 10 秒到 16 秒开始播放。

混合静音 (aevalsrc=0):

ffmpeg -hide_banner \
-i video1.mp4 \
-i audio1.mp3 \
-i audio2.mp3 \
-filter_complex "
aevalsrc=0:d=20[bga];
[1:a]adelay=3000|3000,aresample=async=1:first_pts=0[1a];
[2:a]adelay=10000|10000,aresample=async=1:first_pts=0[2a];
[bga][1a][2a]amix=3[a]
" -map 0:v -map [a] -c:v copy -c:a aac -q:a 4 -y /tmp/output.mp4

使用 atrim 限制 MP3 和最终输出的音频持续时间。

ffmpeg -y -i video1.mp4 -i audio1.mp3 -i audio2.mp3 -filter_complex "[1]atrim=0:5,adelay=3000|3000[aud1];[2]atrim=0:6,adelay=10000|10000[aud2];[aud1][aud2]amix=2,apad,atrim=0:20[a]" -map 0:v -map "[a]" -c:v copy -ac 2 output.mp4