[FFmpeg-user] FFMpeg encoding error: "height not divisible by 2" - Recommended dimesion 1680 x ??? with aspect 16:9

Moritz Barsnick barsnick at gmx.net
Mon Oct 22 12:11:49 EEST 2018


On Mon, Oct 22, 2018 at 09:32:57 +0200, Ben wrote:
> I wanted to encode (and resize) an existing MP4 file into a new MP4 video and a width of 1680 * ... and an aspect ratio of 16:9
> The used codec is H.264
> 
> Since the calculated height therefore is (1680/16)*9=945 I entered this for the ffmpeg command and got an error:
> 
> "height not divisible by 2"
> Hmm, can this really be?

Yes, certain operations and codecs have such requirements. For example
the very common H.264 with yuv420p colorspace.

> What is the recommended height otherwise?

Some codecs even encode more efficiently when the resolution is
divisible by 4, 8 or possibly even 16. In your case, just choose a
height divisible by two.

> Is there no auto-adjustment in ffmpeg?

No, but if you use the scale filter (or others using the same size
syntax), you can let ffmpeg do the math for you:

Resize while keeping input aspect ratio, but divisible by 2:

$ ffmpeg [...] -vf scale=1680:-2 [...]

If you want to be explicit about 16:9 (and let ffmpeg calculate 16/9):

$ ffmpeg [...] -vf "scale=trunc(1680/2)*2:trunc(1680*9/16/2)*2"

There are some other nice suggestions in this StackOverflow topic:
https://stackoverflow.com/q/20847674/3974309

Cheers,
Moritz


More information about the ffmpeg-user mailing list