Search code examples
ffmpegscale

ffmpeg how to upscale video 2x but only if resulting size is smaller than 720 height?


I want to upscale videos in ffmpeg to twice their size, but only if the resulting size is smaller than 720 height... so, for example:

A video of 256x144 will be upscaled 2x, resulting in 512x288

A video of 640x360 will be upscaled 2x, resulting in 1280x720

A video of 854x480 (or bigger sizes) won't be upscaled, because the resulting sizes would exceed the limit of 720 height.

So, is it possible to do something like that in ffmpeg with the "scale" filter?


Solution

  • Yes. Use scale filter with expression:

    scale=-1:'if(lte(ih,360),2*ih,ih)'
    

    The width will be automatically set proportional to the height.

    [edit] Thanks @anonymous for spotting the inaccuracy in the original solution. The original solution:

    scale='if(lt(iw,720)*lt(ih,720),2*iw,iw)':-1
    

    This one doubles the frame size if either dimension is less than 720px, which is not accurate to the OP's need.