5

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?

3 Answers 3

4

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))'
1
  • 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)".
    – user968099
    Commented Nov 28, 2018 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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .