Ffmpeg - how to combine multiple time-shifted audios in a video?

I want to use FFMPEG to create multiple audio and one video.

Materials:

  • two short audio clips (short-clip-1.3gp, short-clip-2.3gp),
  • one video clip (1.mp4) with sound,
  • and one audio clip (1.mp3) that is the same length as the video clip.

Demand:

  • Remove video clip sound
  • add 1.mp3
  • add a short clip-1.3gp with a time stamp of 0 sec, a short clip-2.3gp with a time stamp of 10 seconds.

The requirement is depicted as shown below.

<- short-clip-1.3gp time duration β†’ <- short-clip-2.3gp time duration β†’

<-------------------------------------- 1.mp3 ---- ---- --------------------------------------------->

<-------------------------------------- 1.mp4 ---- ---- --------------------------------------------->

The command I'm using is below, but it doesn't work as expected. ffmpeg -i 1.mp4 -i 1.3gp -itsoffset 00:00:10 -i 2.3gp -i 1.mp3 -map 0:v -map 1:a -map 2:a -map 3:a -c:v copy -c:a copy result.mp4

Any hints are appreciated!

+3


source to share


2 answers


You need to mix audio streams:



ffmpeg -i 1.mp4 -i 1.3gp -i 2.3gp -i 1.mp3
  -filter_complex "[2]adelay=10000|10000[s2];[3:a][1:a][s2]amix=3[a]"
  -map 0:v -map "[a]" -c:v copy result.mp4

      

+3


source


Thanks to Mulvia's decision. Here's some additional information on how to mix multiple audio streams with a latency requirement:

ffmpeg -i 1.mp3 -i 1.3gp -i 2.3gp -i 3.3gp -i 4.3gp -i 5.3gp -i 1.mp4 \ 
-filter_complex "[2]adelay=2790|2790[s2];\
[3]adelay=10300|10300[s3];\
[4]adelay=14930|14930[s4];\
[5]adelay=21090[s5];\
[0][1][s2][s3][s4][s5]amix=6[mixout]" \
-map 6:v -map [mixout] -c:v copy result.mp4

      



The difficult part: [2]adelay=2790|2790[s2]

. it means "select the third input, give a delay of 2.79 seconds and output as s2", "s2" is used in the next amix command to create "6 [mixout]" which is then used in "-map".

+3


source







All Articles