Scale video using black bars

By default FFMPEG scales video to a given resolution but keeps the original aspect ratio, so you can end up with a 1920×1080 video that plays in 4:3. This may not be what you want.

There are a few solutions. First, you could not set the width or height with -1, and this way, FFMPEG will scale it keeping the same aspect ratio (eg: -vf scale=1920:-1) and match the missing width/height for what it needs to be for that aspect ratio. This is the recommended way.

On the other hand, you can force it to be the specified resolution, and stretch/compress the video.

You could also crop in the video to match the specified resolution and aspect ratio.

Finally, you can resize it like the first solution and add black bars to fill your desired resolution. This is useful if you are going to concatenate videos for example to edit something together, and want the size/aspect ratio consistent. This way, if you have a few 4:3 clips is a majority 16:9 video, all will be well.

The following does this, where RW is the width, and RH is the height you want. This will resize the video to fit in it's original version and then pad it. You can change the colour of the padding.

ffmpeg -i input -c:v libvpx-vp9 -crf 30 -vf "scale=${RW}:${RH}:force_original_aspect_ratio=decrease,pad=${RW}:${RH}:-1:-1:color=black" output.webm
  • scripts/ffmpeg/scale_video_with_bars.txt
  • Last modified: 2022-04-06 21:42
  • by Tony