I have two video clips. Both are 640x480 and last 10 minutes. One contains background audio, the other one a singing actor. I would like to create a single 10 minute video clip measuring 1280x480 (in other words, I want to place the videos next to each other and play them simultaneously, mixing audio from both clips). I've tried trying to figure out how to do this with ffmpeg/avidemux, but so far I came up empty. They all refer to concatenating when I search for merging.

Any recommendations?

ffmpeg \
  -i input1.mp4 \
  -i input2.mp4 \
  -filter_complex '[0:v]pad=iw*2:ih[int];[int][1:v]overlay=W/2:0[vid]' \
  -map '[vid]' \
  -c:v libx264 \
  -crf 23 \
  -preset veryfast \

This essentially doubles the size of input1.mp4 by padding the right side with black the same size as the original video, and then places input2.mp4 over the top of that black area with the overlay filter.

Source: https://superuser.com/questions/153160/join-videos-split-screen

  • 1
    What does -map [vid] do? – 0xcaff Dec 23 '16 at 4:12
  • @caffinatedmonkey [vid] is a so-called linklabel, which is a defined output link label in the filter graph (the line above with the filter_complex). It maps the output from the complex filter graph to the output file. – Jan Dec 26 '16 at 12:34
  • I'm getting Unrecognized option 'crf'. Error splitting the argument list: Option not found. If I remove cr then unrecognized option 'preset' – R S Mar 10 '18 at 17:03
  • 2
    [vid] not in quotes doesn't work. --> -map "[vid]" \ – The Nomadic Coder Dec 12 '19 at 12:02
  • 1
    This works like a charm but a bit more explanation would be helpful. – Patryk Mar 2 '20 at 13:33

To be honest, using the accepted answer resulted in a lot of dropped frames for me.

However, using the hstack filter_complex produced perfectly fluid output:

ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack output.mp4
  • 7
    In case anyone is wondering how to stack more than 2 videos, you can simply specify hstack=inputs=3 – Simbi Jun 17 '20 at 18:34

This can be done with just two filters and the audio from both inputs will also be included.

ffmpeg -i left.mp4 -i right.mp4 -filter_complex \
"[0:v][1:v]hstack=inputs=2[v]; \
 [0:a][1:a]amerge[a]" \
-map "[v]" -map "[a]" -ac 2 output.mp4
  • hstack will place each video side-by-side.
  • amerge will combine the audio from both inputs into a single, multichannel audio stream, and -ac 2 will make it stereo; without this option the audio stream may end up as 4 channels if both inputs are stereo.
  • Hello, Can I overlay one video on to another video? – Nisarg Sep 21 '16 at 11:38
  • @Nisarg Use the overlay filter. – llogan Sep 21 '16 at 22:25
  • I want upper video little transparent so one can see whats happening in background, Can you help me out with that? – Nisarg Sep 22 '16 at 5:01
  • Hello Sir, Can you care to look this out. – Nisarg Sep 22 '16 at 6:34
  • 2
    I lost audio with the accepted answer. This one works perfectly. – Matt Hough Feb 22 '19 at 8:48
ffmpeg -y -ss 0 -t 5 -i inputVideo1.mp4 -ss 0 -t 5 -i inputVideo2.mp4 -i BgPaddingImage.jpg -filter_complex nullsrc=size=720*720[base];[base][2:v]overlay=1,format=yuv420p[base1];[0:v]setpts=PTS-STARTPTS,scale=345*700[upperleft];[1:v]setpts=PTS-STARTPTS,scale=345*700[upperright];[base1][upperleft]overlay=shortest=1:x=10:y=10[tmp1];[tmp1][upperright]overlay=shortest=1:x=366:y=10 -c:a copy -strict experimental -ss 0 -t 5 -preset ultrafast -an output.mp4

Add Two Video Side by side And Also Add OverLay Image That Show On Videos Padding With You can change Background Image [BgPaddingImage.jpg] here set your bg image path.

Show This below Video its create from Above command

enter image description here

  • 1
    What language is this? How do you run it? – muru May 30 '19 at 4:41
  • @muru Check it out now its FFMPEG Command ?? :) – Sanjay Hadiya May 30 '19 at 5:04
  • @Sanjay Usually characters like [ and * would have to be escaped before the command could be understood by a shell. I think that is part of the confusion. What shell are you using? – Metamorphic Apr 22 '20 at 6:41
  • bro i was run on android ffmpeg – Sanjay Hadiya Apr 23 '20 at 16: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.