0

I have a video.mp4 file of 20 seconds without audio stream, and I have 2 audio files audio1.mp3 and audio2.mp3. What I want is audio1 should start playe at 3 seconds for 5 seconds, and audio 2 should start play at 10 seconds for 6 seconds.

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

what I'm trying to achieve is the final output will be a 20 seconds video where audio1 will start palying at 3 seconds to 8 seconds and audio2 will start from 10 seconds to 16 seconds.

Javed Saifi
  • 71
  • 1
  • 15

2 Answers2

3

mix with silence (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
2

Use atrim to limit the audio duration for the MP3s and the final output.

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

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thank you @Gyan. tried above command but terminal stuck a some point. Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default) Metadata: encoder : Lavc57.107.100 aac – Javed Saifi Feb 15 '21 at 11:42
  • ffmpeg -i video1.mp4 -i audio1.mp3 -i audio2.mp3 -filter_complex "[1:a]atrim=0:5,adelay=3000|3000[a1];[2:a]atrim=0:6,adelay=10000|10000[a2];[a1][a2]concat=n=2:v=0:a=1[a]" -map 0:v -map "[a]" -codec:v copy -codec:a libmp3lame output.mp4 -y This script works for me but audio2 should start play from 10th second but It starts play at 18th second. – Javed Saifi Feb 15 '21 at 12:04