About
In this how-to, we show you how to resize video with the ffmpeg command line utility and the scale filter 1)
How to
How to scale down preserving the aspect ratio
ffmpeg permits to set the dimension of a video to -1 in order to preserve aspect ratio
Once, you have installed ffmpeg, you can resize:
- a mp4 video
- while preserving the aspect ratio (most wanted)
- to a width of 960
ffmpeg -i output.mp4 -vf "scale=960:-1" output_960.mp4
- to a height of 300
ffmpeg -i output.mp4 -vf "scale=-1:300" output_300.mp4
Image
Note that you can also resize an image
ffmpeg -i input.jpg -vf scale=320:-2 output_320.png
height not divisible by 2
You may encounter this error height not divisible by 2.
If you encounter the above error, you may want to use the following expression 2)
scale=640:trunc(ow/a/2)*2
where ow is the width of the output. </note>
How to scale down a video by 50% preserving the aspect ratio
On the width:
ffmpeg -i input.mp4 -vf "scale=trunc(iw/4)*2:-1" output_down_2.mp4
On the height
ffmpeg -i input.mp4 -vf "scale=iw:ih/2:0:0" output_down_2.mp4
Where iw and ih means the width and height of the input video.
How to scale down or up to fill into a rectangle ?
You can achieve this with the force_original_aspect_ratio option. It has two possible values:
- decrease: The output video dimensions will automatically be decreased if needed.
- increase: The output video dimensions will automatically be increased if needed.
Example 3)
ffmpeg -i input.jpg -vf scale=w=320:h=240:force_original_aspect_ratio=decrease output_320.png