[FFmpeg-user] Scale down if resolution is greater than given?

Moritz Barsnick barsnick at gmx.net
Wed Jul 29 14:29:15 CEST 2015


Hi Vedran,

On Wed, Jul 29, 2015 at 03:42:05 +0200, vedran wrote:
> I'm looking for simple bash script which scales down video only if it has
> greater resolution than given.

You won't need a bash script necessarily. ffmpeg can handle
expressions.

> The problem is also with "vertical videos". So i need to check width and
> height.

Do you need the math to express what to do, or do you need the ffmpeg
command line?

For instance, if you want ffmpeg to scale down anything wider than
1280, use a filter somewhat like this:

$ ffmpeg [...] -vf "scale=w=min(iw\,1280):h=-2" [...]

("h=-2" maintains the aspect ratio, using only even numbers.)

You can make that expression more complex, e.g. if you want to restrict
both width and height, or you want their product not be larger than a
certain number, by construction "if-the-else" (actually "and/or") type
expressions.

What logic were you thinking of? ("If the video is so-and-so, do this,
else if ... do that, else do something else, else don't change
resolution.") Can you express it in words?

Cheers,
Moritz


More information about the ffmpeg-user mailing list