[FFmpeg-user] ffmpeg keep aspect ratio when scaling, keep dimensions divisable by n

Michael Koch astroelectronic at t-online.de
Thu Apr 9 12:42:40 EEST 2020

Am 09.04.2020 um 11:36 schrieb atticus via ffmpeg-user:
> Hi there,
> I'm scaling a video by with this filter:
> -vf "scale=720:320:force_original_aspect_ratio=decrease"
> which works perfectly fine, since I can input the my desired resolution and
> ffmpeg decides on its own which dimension should be scaled by how much to
> keep the aspect ratio. The problem now is that in some cases ffmpeg will
> calculate a uneven number for one of the dimensions (with the h264 codec)
> thus I get this error:
> [libx264 @ 0x5633df10bcc0] width not divisible by 2 (569x320)
> Error initializing output stream 0:0 -- Error while opening encoder for
> output stream #0:0 - maybe incorrect parameters such as bit_rate, rate,
> width or height
> Is there some way to prevent this to give ffmpeg a width and a height as an
> input and it says on its own which should be scaled by how much AND keep (at
> least the calculated) dimensions divisable by n (I know something similar is
> possible with negative numbers, but then I can only give one dimension)?

The scale filter has an option 'force_divisible_by'


More information about the ffmpeg-user mailing list