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.


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.
  • Thnx a lot and srry for late acceptance. :)
    – BlueSword
    Mar 20 '14 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.