Ffmpeg add new audio in video (mixing 2 audio)

3

2

I want to add an audio to video at specific duration. Now before/after that intended duration, original audio of the video should be playing; and at the intended duration only inserted audio should play.

I saw Overlay Audio but it overlays over original audio. I have already tried -itsoffset but it mutes remaining audio.

Here is graphical description of what I want to do exactly What I want to do

Any help is appreciated.

BlueSword

Posted 2014-02-07T11:52:16.277

Reputation: 283

Answers

5

Use the atrim, asetpts, and concat filters:

ffmpeg -i video.mkv -i audio.mp3 -filter_complex \
"[0:a]atrim=end=12,asetpts=PTS-STARTPTS[aud1]; \
 [1:a]atrim=30:42,asetpts=PTS-STARTPTS[aud2]; \
 [0:a]atrim=start=24,asetpts=PTS-STARTPTS[aud3]; \
 [aud1][aud2][aud3]concat=n=3:v=0:a=1[aout]" \
-map 0:v -map "[aout]" -c:v copy -c:a libfdk_aac output.mp4
  • The first atrim gets the the first 12 seconds of audio from the first input (video.mkv).
  • The second atrim gets seconds 30-42 from the second input (audio.mp3).
  • The third atrim gets seconds 24-end of audio from the first input (video.mkv).
  • concat then combines these segments into one audio stream.
  • The video is stream copied instead of being re-encoded in this example.
  • Without asetpts I was getting buffer queue overflows resulting in a "jerky" output. See the atrim documentation for more info.

llogan

Posted 2014-02-07T11:52:16.277

Reputation: 31 929

Thnx a lot and srry for late acceptance. :) – BlueSword – 2014-03-20T09:54:30.817