FFmpeg Concatenate Videos with Different Aspect Ratios

This article provides a step-by-step guide and the exact FFmpeg command needed to concatenate two videos with different aspect ratios. You will learn how to use FFmpeg’s complex filter graph to scale, pad, and merge your videos into a single output file without stretching or distorting the original footage.

The Challenge with Different Aspect Ratios

When concatenating videos with different aspect ratios or resolutions using the basic FFmpeg demuxer, the resulting file will often suffer from severe distortion, green bars, or playback errors. To merge them successfully, both videos must be normalized to the same resolution and aspect ratio before they are joined.

The most effective way to achieve this is by using FFmpeg’s -filter_complex flag to scale and pad the videos to a uniform resolution (such as 1920x1080) and then concatenate them.

The FFmpeg Command

Run the following command in your terminal to concatenate two videos with different aspect ratios:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1[v0]; \
 [1:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1[v1]; \
 [v0][0:a][v1][1:a]concat=n=2:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mp4

How the Command Works

Here is a breakdown of the specific filters used in the command: