Skip to content

Instantly share code, notes, and snippets.

@arbal
Forked from joshschmelzle/ffmpeg-merge-two-videos.md
Created December 25, 2022 09:06
Show Gist options
  • Save arbal/9bcaa7fef462fac072eb01dbc3e4ee3f to your computer and use it in GitHub Desktop.
Save arbal/9bcaa7fef462fac072eb01dbc3e4ee3f to your computer and use it in GitHub Desktop.
Merging two video clips into one and placing them next to each other with ffmpeg

Taking two video clips, placing them side by side, combining 4 channels of audio into 2, and output.

ffmpeg -i video1.MP4 -i video2.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

This was done with two filters and the audio from both inputs.

  • hstack places each video side-by-side.
  • amerge combines the audio from both inputs into a single, multi-channel 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.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment