I'm trying to make a video with an overlay video inside (PiP) but I can't get the sound source right, I need the sound from the underlay video but I keep getting the sound from the overlay video.

I don't have very much experience with or knowledge of ffmpeg, but after some searching around on the internet I found some ffmpeg commands and managed to put the following command together:

ffmpeg.exe -itsoffset 35 -i overlay-race-replay.mp4 -i underlay-race-live.mp4 
-filter_complex "[0]scale=700:-1 [overlay]; 
[1][overlay] overlay=main_w-overlay_w-30:30:enable='between(t,35,552)'" 
-profile:v high -level 4.1 -ar 44100 -ab 128k -s 1920x1080 -vcodec h264 
-acodec libmp3lame output.mp4

It works great to create a video with an overlay video in it which shows up and starts at 35 seconds and ends and disappears somewhere before the underlay video ends which is just what I want.

Only the problem is the sound! In the output file you only hear the sound from the overlay video, and I want to keep the sound from the underlay video.

Does anyone know how to do this right? What I need is, overlay-race-replay.mp4 resized to a width of 700 with kept ratio, inside underlay-race-live.mp4, showing up after 35 seconds, placed in the top right corner with about 30 pixels margin and only the sound of underlay-race-live.mp4

I would be very grateful for a solution, I think I've injured my brain in the documentations of ffmpeg I really can't make anything of it, it's like algebra to me.

1 Answer 1


Ah I found the answer to my question, I ventured into the ffmpeg documentations again and found that all I had to do was add -map 1:a in front of output.mp4 and I also added -c:a copy cause I thought that copies the same codec settings from the original videos or something, not really sure but it seemed better then putting all those specifications in like I did which I actually just left in there from the site that I found the main part of this ffmpeg command on.

My code is now working as I want it and I'll share it below:

ffmpeg.exe -itsoffset 35 -i overlay.mp4 -i underlay.mp4 -filter_complex 
"[0]scale=700:-1 [overlay]; [1][overlay] 
-map 1:a -c:a copy output.mp4

The itsoffset is the time before the overlay video starts playing, between(t,35,552) means the overlay video is visible between the 35th second and the 552nd second on the timeline of the output video.

  • Hi what if I want to keep sound of the overlay video?
    – yuan
    Commented Oct 15, 2020 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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