2

Merging two video clips into one and placing them next to each other with ffmpeg

 1 year ago
source link: https://gist.github.com/joshschmelzle/fc96024dbb14f3f919893fdd14e7dffc
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Merging two video clips into one and placing them next to each other with ffmpeg · GitHub

Instantly share code, notes, and snippets.

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.)

@joshschmelzle thanks for this, but how to combine videos with different sizes?
I get the error

[Parsed_amerge_2 @ 0x55dd77800820] No channel layout for input 1
[Parsed_amerge_2 @ 0x55dd77800820] Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[Parsed_hstack_0 @ 0x55dd77801860] Input 1 height 1080 does not match input 0 height 270.
[Parsed_hstack_0 @ 0x55dd77801860] Failed to configure output pad on Parsed_hstack_0
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:1
Conversion failed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK