Skip to content

/errors/ffmpeg/width-height-not-divisible-by-2

libx264: width not divisible by 2 / height not divisible by 2

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · ffmpeg version 9.0.2-full_build-www.gyan.devupdated 2026-10-20
tool
FFmpeg
exit code
1
versions
FFmpeg 6 – 9
os
linux, macos, windows

libx264 refuses to encode yuv420p video whose width or height is an odd number and prints width not divisible by 2 (101x101) (or height not divisible by 2). 4:2:0 chroma subsampling stores one colour sample per 2×2 block of pixels, so both dimensions must be even. Scale or pad the video to even dimensions.

Reproduce the error

bash
ffmpeg -hide_banner -loglevel error -f lavfi -i testsrc=size=101x101:duration=1 \
  -c:v libx264 -pix_fmt yuv420p -y out.mp4 2>&1 | head -2 | sed 's/@ 0x\?[0-9a-f]*/@ …/g'

Output

[libx264 @ …] width not divisible by 2 (101x101)
[vost#0:0/libx264 @ …] [enc:libx264 @ …] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.

The memory addresses after @ change on every run and are shortened here. Without -pix_fmt yuv420p, ffmpeg 9 picks yuv444p for an RGB source and the odd size is accepted, but many players and every browser need yuv420p.

Fix: make the dimensions even

bash
ffmpeg -hide_banner -loglevel error -f lavfi -i testsrc=size=101x101:duration=1 \
  -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -pix_fmt yuv420p -y out.mp4
ffprobe -v error -select_streams v -show_entries stream=width,height,pix_fmt -of csv=p=0 out.mp4

Output

100,100,yuv420p

Fix: let scale keep the computed side even

bash
ffmpeg -hide_banner -loglevel error -f lavfi -i testsrc=size=1080x1919:duration=1 \
  -vf "scale=-2:720" -c:v libx264 -pix_fmt yuv420p -y out.mp4
ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0 out.mp4

Output

406,720

-1 keeps the aspect ratio exactly and can produce an odd number; -2 keeps it as close as possible while rounding to a multiple of 2.

Sources