FFMPEG Autoscale on height or width

If you would like to scale your video using FFMPEG you can do this by Just using -2

From the FFMPEG scale filter documentation:

If one of the values is -n with n > 1, the scale filter will also use a value that maintains the aspect ratio of the input image, calculated from the other specified dimension. After that it will, however, make sure that the calculated dimension is divisible by n and adjust the value if necessary.


Set width to 1280, and height will automatically be calculated to preserve the aspect ratio, and the height will be divisible by 2:
-vf scale=1280:-2
Same as above, but with a declared height instead; leaving width to be dealt with by the filter:
-vf scale=-2:720

“divisible by 2”

As required by x264, the “divisible by 2 for width and height” is needed for YUV 4:2:0 chroma subsampled outputs. 4:2:2 would need “divisible by 2 for width”, and 4:4:4 does not have these restrictions. However, most non-FFmpeg based players can only properly decode 4:2:0, so that is why you often see ffmpeg commands with the -pix_fmt yuv420p option when outputting H.264 video.


Unfortunately you can’t use -2 for both width and height, but if you already specified one dimension then using -2 is a simple solution.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.