How to Stack Two Videos Vertically with FFmpeg

This guide explains how to combine two separate video files into a single, vertically stacked video using the FFmpeg vstack filter. You will learn the basic command for stacking videos of equal width, how to handle videos with different widths by resizing them, and how to merge their audio tracks.

Basic Vertical Stacking

To stack two videos vertically, they must have the exact same width. If your videos already share the same width, use the following basic command:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex vstack=inputs=2 output.mp4

Stacking Videos with Different Widths

If your input videos have different widths, the basic vstack command will fail with an error. You must scale the videos to a matching width before stacking them.

The command below scales both videos to a width of 1280 pixels while automatically adjusting the height to maintain the original aspect ratio:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v]scale=1280:-1[v0];[1:v]scale=1280:-1[v1];[v0][v1]vstack=inputs=2[v]" -map "[v]" output.mp4

Combining Audio Tracks

By default, FFmpeg will only copy the audio from the first input video. To merge the audio from both videos so they play simultaneously, use the amix filter alongside vstack:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "[0:v][1:v]vstack=inputs=2[v];[0:a][1:a]amix=inputs=2[a]" -map "[v]" -map "[a]" output.mp4