FFMPEG (libx264) “height not divisible by 2”

The answer to the original question should not scale the video but instead fix the height not divisible by 2 error. This can be achieve using this filter:

-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"

Full command:

ffmpeg -i frame_%05d.jpg -vcodec libx264 \
 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -r 24 \
 -y -an video.mp4 

Basically, .h264 needs even dimensions so this filter will:

  1. Divide the original height and width by 2
  2. Round it up to the nearest pixel
  3. Multiply it by 2 again, thus making it an even number
  4. Add black padding pixels up to this number

You can change the color of the padding by adding filter parameter :color=white. See the documentation of pad.

Leave a Comment

tech