2

Using this command:

ffmpeg -loop 1 -r 1 -i q.jpg -t 5 -pix_fmt yuv420p -vf 'scale=-2:min(1080\,ih)' z.mp4

I get this message:

[libx264 @ 00000000004d0ec0] height not divisible by 2 (954x953)

I can avoid the error like this:

ffmpeg -loop 1 -r 1 -i q.jpg -t 5 -pix_fmt yuv420p -vf scale=-2:1080 z.mp4

However this is not ideal because it is upscaling the image. How can I scale the image only if the height is greater than 1080, while keeping the pixel format as I have it?

2

Here is what I came up with:

-vf 'scale=-2:min(1080\,trunc(ih/2)*2)'

http://trac.ffmpeg.org/ticket/309

Or:

-vf 'scale=-2:min(1080\,bitand(ih\,-2))'

Or:

-vf 'scale=-2:min(1080\,ih-mod(ih\,2))'
  • This didn't work for me. For example: ffmpeg -r 30 -f image2 -i fft_%05d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p fft_.mp4 -vf 'scale=-2:min(1080\,trunc(ih/2)*2)' still gives "width not divisible by 2 (2265x2209)". – Galen Nov 28 '18 at 21:51
0

Instead of

'scale=-2:min(1080\,ih)'

use

'scale=-2:min(1080\,if(mod(ih\,2)\,ih-1\,ih))'

It will check if ih is divisible by 2, and if not, it will decrease it by 1.

0

Not sure if this is the exact answer, but my google search led here. I simply looked at the frame size (in my case I am downsampling) took the size: 1796x1080 and divided 1796 in 2 (898) and used that in the size line:

-vf scale=898:-1

Which did end up with this size: 898x540

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.