ffmpeg-错误-提取视频预览时 报错-h.264 – FFMPEG (libx264) height not divisible by 2

I sometimes get the following error:

[libx264 @ 0xa3b85a0] height not divisible by 2 (520×369)

归结原因就是 height 不是偶数

After playing around with this a bit, I think I’ve answered my own question. Here is the solution in case anyone else runs into a similar issue… I had to add the below argument to the command:

-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"

Command

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

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

Divide the original height and width by 2
Round it down to the nearest pixel
Multiply it by 2 again, thus making it an even number

https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2

http://www.itkeyword.com/doc/3596353026169028160/ffmpeg-libx264-height-not-divisible-by-2