How to Combine 3 Videos Vertically with FFmpeg vstack

This article explains how to use the FFmpeg vstack filter to merge three separate video files into a single, vertically stacked output video. You will learn the exact command-line syntax required, how to handle the audio streams from all three inputs, and how to resolve potential errors caused by mismatched video dimensions.

The Basic Command

To stack three videos vertically, all input videos must have the exact same width. Use the following basic command structure to combine them:

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

Command Breakdown:

Combining Audio Along with Video

The basic command above only processes the video tracks, leaving the output silent. If you want to merge the audio tracks from all three videos, use the amix filter:

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

In this command, [0:a][1:a][2:a]amix=inputs=3[a] mixes the audio tracks from the three inputs into a single audio stream labeled [a], which is then mapped to the output file using -map "[a]".

Handling Videos with Different Widths

The vstack filter will fail with an error if the input videos do not have identical widths. If your videos are of different sizes, you must scale them to a uniform width before stacking them.

The command below scales all three videos to a width of 1920 pixels while automatically maintaining their respective aspect ratios:

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

In this sequence, each video stream is scaled individually (scale=1920:-1) and given a temporary label ([v0], [v1], [v2]). These scaled streams are then passed directly into the vstack filter.