#10279 closed defect (invalid)

"width not divisible by 2" error with force_original_aspect_ratio=reduce

Reported by: php4fan Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
How to reproduce:

I have a file with a resolution of 480x848.

I try to convert it with:

ffmpeg -i "input.mp4" -vcodec libx264 -acodec aac -strict -2 -vf "scale='min(800,iw)':'min(800,ih)':force_original_aspect_ratio=decrease" "output.mp4"

I get the stupid error:

width not divisible by 2 (453x800)

This is stupid, because I'm not giving you an exact width. I'm asking you to force the aspect ratio, and 453 is the result of computing a width to force the aspect ratio.
Given that you are computing the width, it's up to you to round it to the nearest multiple of 2 if needed. Just like you don't complain about the computed width not being an integer, but you silently round to the nearest integer, in pretty much the same way you should round it to the nearest multiple of 2 (or 4 or whatever the requirement is) if the codec so requires.

According to https://trac.ffmpeg.org/wiki/Scaling:

Some codecs require the size of width and height to be
a multiple of n. You can achieve this by setting
the width or height to -n:

ffmpeg -i input.jpg -vf scale=320:-2 output_320.png

but I don't see how that would be applicable here.

Change History (1)

comment:1 by James, 14 months ago

Resolution: invalid
Status: newclosed

I get the stupid error:

width not divisible by 2 (453x800)

That "stupid error" is libx264 not accepting the input stream it's being fed. The scale filter can't know what the encoder down the line in the process can handle, and is doing exactly what you told it to do.
You want it to force the dimensions to be divisible by 2? Then check the documentation for the scale filter in https://ffmpeg.org/ffmpeg-filters.html#scale and you will find this option coincidentally called "force_divisible_by". You can also find it if you look at the available options in the CLI by running

ffmpeg -h filter=scale

With a description that states:

enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used (from 1 to 256) (default 1)

Note: See TracTickets for help on using tickets.