Resize to a specific width and height using ffmpeg
ffmpeg
Solution
This is an example using a picture, same filter can be applied to video:
ow=220
oh=120
ffmpeg -i foo.png \
-vf "scale=max($ow\,a*$oh):max($oh\,$ow/a),crop=$ow:$oh" bar.png
Regardless of aspect ratio, this will:
- scale down until width or height fits "the box"
- crop down the other until it fits as well
The commas inside needs to be escaped so they aren't interpreted as filter separators.
§ Crop
§ Scale
Problem
I need to generate thumbnails for videos, automatically. I cannot predict the format of the video, but I need the thumbnail to be 220x120 pixels, always. Using `-s 220x120` produces a weird stretch, just like `-vf "scale=220:120"`. I'd like the stretching to be uniform, either cutting away top and bottom if the video is too high or adding black borders.