3

It blew my mind when I recently came across something new about FFmpeg despite having used it for years - the fact that it comes out of the box with advanced conditionals like if statements and lt/gt for filters. To me this has to be its most underrated feature, or at least it would be if the documentation mentioned anything about them and how they worked.

I want to take advantage of them in my FFmpeg scripts to upscale videos intelligently based on their height: if a video's height is less than 720 pixels, to upscale it to -1:720 (that is, a height of 720 and a proportional width that maintains its aspect ratio), and to leave it unchanged if it's 720 pixels or greater. What would a scale filter to do this with if and lt/gt look like?

Hashim Aziz
  • 13,835

1 Answers1

4

You can use max:

max(x, y)
Return the maximum between x and y.

Example:

ffmpeg -i input -vf "scale=-1:'max(720,ih)'" output

If I wanted to replace the -1 with a $width variable in my script, would there be a way to ensure that $width is only acted on when the right side (i.e. height) is also upscaled?

Example using if and lt:

ffmpeg -i input -vf "scale='if(lt(ih,720),$width,iw)':'max(720,ih)'" output
llogan
  • 63,280