[FFmpeg-user] Can I do scaling better?

csparker247 csparker247 at gmail.com
Fri Feb 14 18:05:05 CET 2014


James Darnley wrote
> On 2014-02-14 16:55, csparker247 wrote:
>>> I cannot provide you with a quick solution but 
>>> "-vf scale,scale" seems a very bad idea to me. 
>> 
>> I've had concerns with that, too, but I can't think of another way to
>> guarantee square pixels AND scale downs for arbitrary inputs.
> 
> You can access the aspect ratio in the "scripting" so you can scale
> width and height using it.
> 
> I will post what I used fairly recently.  It is not exactly what you
> want but shows the principle.  It will scale everything larger than
> 1024x768 to something that fits within that bound.  Otherwise it just
> scales to square pixels.
> 
>> "scale=
>>     w=if(lt(dar\,1.34)\, -1\, if(gt(iw\,1024)\, 1024\, iw)):
>>     h=if(gte(dar\,1.34)\, -1\, if(gt(ih\,768)\, 768\, ih)),
>> setsar=1"
> 
> It still didn't solve the odd sizes it that -1 can give.

That check for dar was exactly what I needed, but it needed a couple of
tweaks. For one, setsar=1 doesn't actually change par, it just changes the
flag. Anamorphic content would end up being squished still. I'd accounted
for that already with my first scale filter, though, so whatever.

In terms of the odd sizes, I had a solution for that already, too. This is
what I've ended up with:
>"scale=iw*sar:ih, 
> scale=		
>     'w=if(lt(dar, 16/9), trunc(oh*a/2)*2, min(1920,ceil(iw/2)*2)): 
>      h=if(gte(dar, 16/9), ceil(ih/2)*2, min(1080,ceil(ih/2)*2))', 
>      setsar=1"

It's obviously still questionable if I should use two scale filters, but I'm
not entirely sure what to do about that.



--
View this message in context: http://ffmpeg-users.933282.n4.nabble.com/Can-I-do-scaling-better-tp4663866p4663895.html
Sent from the FFmpeg-users mailing list archive at Nabble.com.


More information about the ffmpeg-user mailing list