Merge Videos with Different Resolutions in FFmpeg
This article explains how to use FFmpeg’s concat filter
to merge video files that have different resolutions, aspect ratios, or
frame rates. Because the standard FFmpeg concat demuxer requires
identical video properties, you must use the filter_complex
tool to dynamically rescale and pad your videos to a unified resolution
before concatenating them. Below, you will find the exact command and an
explanation of how it works.
The Challenge with Different Resolutions
When using FFmpeg to merge videos, the simple stream copy method
(-c copy) will fail or produce corrupted files if the input
videos do not share the exact same width, height, codec, and pixel
format. To solve this, you must decode the videos, resize them to a
common resolution (such as 1920x1080), and then merge them using the
concat filter.
The FFmpeg Command
To merge two videos (input1.mp4 and
input2.mp4) with different resolutions into a single 1080p
output, use the following command:
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.mp4How the Filter Graph Works
The -filter_complex option allows you to process
multiple inputs through a chain of filters. Here is a breakdown of what
each part of the filter graph does:
[0:v]and[1:v]: These refer to the video streams of the first and second input files, respectively.scale=1920:1080:force_original_aspect_ratio=decrease: This scales the video to fit within a 1920x1080 box without stretching or distorting the original aspect ratio.pad=1920:1080:(ow-iw)/2:(oh-ih)/2: If the scaled video does not perfectly match the 1920x1080 box, this filter adds black bars (pillarboxes or letterboxes) to fill the remaining space. The math(ow-iw)/2and(oh-ih)/2centers the video within the frame.setsar=1: This resets the Sample Aspect Ratio to 1:1, preventing rendering issues after concatenation.[v0]and[v1]: These are temporary labels assigned to the processed video streams.concat=n=2:v=1:a=1: This tells FFmpeg to concatenate the inputs.n=2specifies the number of input segments (videos).v=1specifies that there will be 1 output video stream.a=1specifies that there will be 1 output audio stream.
-map "[outv]" -map "[outa]": This maps the final concatenated video and audio streams to the output file,output.mp4.