height not divisible by 2
h.264 - FFMPEG (libx264) "height not divisible by 2" - Stack Overflow https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2
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
尺寸调整为不大于的最小偶数
from PIL import Image f = 'my.jpg' mid_icon = Image.open(f) h, w = mid_icon.height, mid_icon.width h, w = int(h / 2) * 2, int(w / 2) * 2 mid_icon = mid_icon.resize((w, h), Image.ANTIALIAS) mid_icon.save(f)
from PIL import Image def img_to_floor_even(f): try: fo = Image.open(f) w, h = fo.width, fo.height w_, h_ = int(w / 2) * 2, int(h / 2) * 2 if (w, h) != (w_, h): fo = fo.resize((w_, h_), Image.ANTIALIAS) fo.save(f) except Exception as e: print(e) # log