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.
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:
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.