Combine 6 Videos into a 3x2 Grid with FFmpeg

This guide explains how to combine six separate video files into a single 3x2 grid layout using the powerful xstack filter in FFmpeg. You will learn the exact command-line syntax required, how the grid coordinate system works, and how to handle videos of different sizes by scaling them prior to merging.

The Basic Command (For Same-Sized Videos)

If all six of your input videos already share the exact same resolution (for example, 1920x1080 or 1280x720), you can merge them directly using the following command:

ffmpeg -i input1.mp4 -i input2.mp4 -i input3.mp4 -i input4.mp4 -i input5.mp4 -i input6.mp4 \
-filter_complex "xstack=inputs=6:layout=0_0|w0_0|w0+w1_0|0_h0|w0_h0|w0+w1_h0" \
-c:v libx264 output.mp4

Understanding the Layout Grid

The layout option in the xstack filter defines the starting X and Y coordinates (separated by an underscore _) for each input video. Each video position is separated by a pipe | character.

Here is how the 3x2 grid coordinates are calculated:


The Advanced Command (For Different-Sized Videos)

If your input videos have different dimensions, they must be scaled to matching sizes before being passed to xstack. The command below scales all six inputs to a uniform resolution of 640x360 pixels before arranging them into the 3x2 grid:

ffmpeg -i input1.mp4 -i input2.mp4 -i input3.mp4 -i input4.mp4 -i input5.mp4 -i input6.mp4 \
-filter_complex \
"[0:v]scale=640:360[v0]; \
 [1:v]scale=640:360[v1]; \
 [2:v]scale=640:360[v2]; \
 [3:v]scale=640:360[v3]; \
 [4:v]scale=640:360[v4]; \
 [5:v]scale=640:360[v5]; \
 [v0][v1][v2][v3][v4][v5]xstack=inputs=6:layout=0_0|w0_0|w0+w1_0|0_h0|w0_h0|w0+w1_h0" \
-c:v libx264 output.mp4

Key Elements of This Command:


Handling Audio

By default, the commands above will only map the audio from the first input file. If you want to combine the audio tracks from all six videos so they play simultaneously, add the amix filter to your command:

ffmpeg -i input1.mp4 -i input2.mp4 -i input3.mp4 -i input4.mp4 -i input5.mp4 -i input6.mp4 \
-filter_complex \
"[0:v]scale=640:360[v0];[1:v]scale=640:360[v1];[2:v]scale=640:360[v2];[3:v]scale=640:360[v3];[4:v]scale=640:360[v4];[5:v]scale=640:360[v5]; \
 [v0][v1][v2][v3][v4][v5]xstack=inputs=6:layout=0_0|w0_0|w0+w1_0|0_h0|w0_h0|w0+w1_h0[outv]; \
 [0:a][1:a][2:a][3:a][4:a][5:a]amix=inputs=6[outa]" \
-map "[outv]" -map "[outa]" -c:v libx264 output.mp4