Skip to content

Instantly share code, notes, and snippets.

View vdivakar's full-sized avatar

Divakar Verma vdivakar

View GitHub Profile
@joshschmelzle
joshschmelzle / ffmpeg-merge-two-videos.md
Last active December 25, 2022 09:06
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.)