Concatenation videos with different resolution. Part 1. Pad

We can concatenate video with different codec, resolution or framerate in different way. Because, video have different resolution, we can:

  • resize all videos by bigest side ( by width or height ) and add pad to videos on the smaller side
  • resize all videos by smaller side ( by width or height ) and crop
  • use original size, but add background to videos

Today we will use ffmpeg filter ‘pad
For example, we have 3 videos with resolution 640×480, 1920×1080 and vertical video 720×1280.

ffmpeg -y -loglevel warning
-i 5sec_640x480.mp4
-i 5sec_1920x1080.mp4
-i 5sec_720x1280.mp4
-filter_complex " 
[0:v] scale=w=min(iw*480/ih\,640):h=min(480\,ih*640/iw), pad=w=640:h=480:x=(640-iw)/2:y=(480-ih)/2  [video0]; 
[1:v] scale=w=min(iw*480/ih\,640):h=min(480\,ih*640/iw), pad=w=640:h=480:x=(640-iw)/2:y=(480-ih)/2  [video1];
[2:v] scale=w=min(iw*480/ih\,640):h=min(480\,ih*640/iw), pad=w=640:h=480:x=(640-iw)/2:y=(480-ih)/2  [video2];
[video0][video1][video2] concat=n=3:v=1 [v]
" -map "[v]" -an -c:v h264 -crf 18 -preset veryfast -f mp4 output.mp4

The same but with concatenation audio streams too.

ffmpeg -y -loglevel warning
-i 5sec_640x480.mp4
-i 5sec_1920x1080.mp4
-i 5sec_720x1280.mp4
-filter_complex " 
[0:v] scale=w=min(iw*480/ih\,640):h=min(480\,ih*640/iw), pad=w=640:h=480:x=(640-iw)/2:y=(480-ih)/2  [video0]; 
[1:v] scale=w=min(iw*480/ih\,640):h=min(480\,ih*640/iw), pad=w=640:h=480:x=(640-iw)/2:y=(480-ih)/2  [video1];
[2:v] scale=w=min(iw*480/ih\,640):h=min(480\,ih*640/iw), pad=w=640:h=480:x=(640-iw)/2:y=(480-ih)/2  [video2];
[0:a] anull [audio0];
[1:a] anull [audio1];
[2:a] anull [audio2];
[video0][audio0][video1][audio1][video2][audio2] concat=n=3:v=1:a=1 [v][a]
" -map "[v]" -map "[a]" -c:a aac -c:v h264 -crf 18 -preset veryfast -f mp4 output.mp4

Notes:
All videos in this sample will be scaled to 640×480, but you can set any other resolution for output video.
Result:

One Reply to “Concatenation videos with different resolution. Part 1. Pad”

Leave a Reply to Simon Cancel reply

Your email address will not be published. Required fields are marked *