The Computer Oracle

ffmpeg/avconv force scaled output to be divisible by 2

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Darkness Approaches Looping

--

Chapters
00:00 Ffmpeg/Avconv Force Scaled Output To Be Divisible By 2
01:10 Answer 1 Score 11
01:25 Answer 2 Score 9
01:43 Accepted Answer Score 7
02:01 Thank you

--

Full question
https://superuser.com/questions/571141/f...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#bash #ffmpeg

#avk47



ANSWER 1

Score 11


Actually the filter can handle it directly. You need only to pass -2 instead of -1 to the filter: e.g.

-vf scale="-2:720"

I was surprised to find this out in a bug report from 3 years ago.




ANSWER 2

Score 9


Since division by 2 incurs in odd numbers sometimes, it should be:

-vf scale="trunc(oh*a/2)*2:720"

This performs what one would want with -1:720 syntax (keep original aspect ratio)




ACCEPTED ANSWER

Score 7


After a lot of experimenting it looks like the following filter applied after other scale filters will round the width and height to 2.

scale=trunc(in_w/2)*2:trunc(in_h/2)*2

It's basically a divide, round, multiply thing, I just didn't have the syntax right.