6

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?

Zombo
  • 1

3 Answers3

5

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))'
Zombo
  • 1
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.

MarianD
  • 2,726
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

wuxmedia
  • 241