Merge two video clips into one, placing them next to each other

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

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 \
  output.mp4

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


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.