/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
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
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.mp4Output
100,100,yuv420p
Fix: let scale keep the computed side even
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.mp4Output
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
Related pages
flags · ffmpegffmpeg -crf: constant rate factor for x264, x265 and AV1-crf sets constant quality: lower means better and bigger. libx264 defaults to 23 on a 0 to 51 scale, libx265 to 28. Use it with -preset; sizes measured.cheat sheets · ffmpegFFmpeg cheat sheet: convert, cut, scale, extract and inspectFFmpeg cheat sheet: inspect files with ffprobe, change containers, encode H.264, cut without re-encoding, scale, extract audio, make GIFs and thumbnails.errors · ffmpegffmpeg: Unknown encoder 'libx264' (Encoder not found)ffmpeg prints Unknown encoder when the codec name is misspelled or the build lacks that library, such as libx264 or libfdk_aac. List them with -encoders.