[FFmpeg-user] let ffmpeg auto-calc height value when specifying (new) width while keeping aspect ratio?
barsnick at gmx.net
Thu Nov 1 09:36:49 EET 2018
On Thu, Nov 01, 2018 at 07:56:52 +0100, Ben wrote:
> The new video should have the same aspect ratio as the original.
> I want to change the resolution of the new video to 1680 but don't want to calculate manually the corresponding height (dividable by 2).
> Can I tell ffmpeg to automatically calculate the appropriate height by using the specified width and the given aspect ratio?
Sure. Using the "scale" filter, there's the magic negative dimension:
"If one and only one of the values is -n with n >= 1, the scale
filter will 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."
In other words:
$ ffmpeg -i input -vf scale=1680:-2 output
More information about the ffmpeg-user