I'm using FFMPEG to transcode videos which the function is triggered automatically. I'm trying to scale the video down into multiple resolutions while keeping the aspect ratio (Shrink to fit). If the original video resolution is smaller than the resolution specified in the command, skip transcoding and stop creating the output file for that particular resolution.

For example:

I have a video with resolution 1920x1080


  • 3840x2160 (Skip/Stop)
  • 2560x1440 (Skip/Stop)
  • 1920x1080 (Proceed to output-1080p.mp4)
  • 1280x720 (Proceed to output-720p.mp4)

I've tried many commands, but none of them really works. May I know is there any command that are able to achieve this?

Below is the latest working command I have for FFMPEG. Sorry, I’m very new to FFMPEG, I understand the current command is still far from what I’m looking to approach.

ffmpeg -i sample.mp4 -c:a copy -vf scale='min(2160\,iw):-2' -movflags +faststart out2160.mp4 -vf scale='min(1440\,iw):-2' -movflags +faststart out1440.mp4 -vf scale='min(1080\,iw):-2' -movflags +faststart out1080.mp4 -vf scale='min(720\,iw):-2' -movflags +faststart out720.mp4 -vf thumbnail -vf scale='min(500\,iw):-2' -vframes 1 thumb500.png -vf scale='min(270\,iw):-2' -vframes 1 thumb270.png

If the sample.mp4 is 1920x1080p or even smaller resolution, this command will output these files:

  • out2160.mp4
  • out1440.mp4
  • out1080.mp4
  • out720.mp4
  • thumb500.png
  • thumb270.png

As I’m triggering FFMPEG automatically, I wish the command can compare the resolution that has been set. If original video resolution is smaller, then just skip it, no point creating or upscaling a file that are larger than the original resolution. Only output same or smaller resolution, while keeping the aspect ratio (Shrink to fit). It would be great if you could guide me on this, thanks once again.

  • What's your current transcoding command?
    – Gyan
    May 1, 2017 at 13:47
  • Hi @Mulvya , thanks for your reply. As I'm unable to post long comment here, please refer to the Update 2 on above, thank you.
    – Jessica
    May 2, 2017 at 10:52

1 Answer 1


This can be done by making use of the crop filter, which will fail if if the cropped output dimensions are larger than the input. If the command fails, the output file will be created but its size will be 0.

Each variant will need to be converted using a separate command. A single command can't be used as if one of the pipeline fails, the entire command is aborted.

The crop filter should be used like this:

ffmpeg -i sample.mp4 -c:a copy -vf crop=iw:'max(ih,2160)',scale=-2:2160 -movflags +faststart out2160.mp4 

The crop width is the same as the input width. The crop height is set to the maximum of the input height and the target height. If the input height is less than the target, the crop filter initialization fails and the command is aborted. If the input height is equal or greater, then the full width & height is passed through to the scale filter.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.