Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using if statement in ffmpeg

Tags:

ffmpeg

is it possible using if/else statement in ffmpeg ?

I would want to tell ffmpeg if dimension of any video lower than 480p do not touch the height or width otherwise do encode and resize it to 480p, here's my command but it always scale up the video if the video lower than 480p

ffmpeg -i input.mp4 -c:v libx264 -crf 31 -me_method umh -bf 0 -vf scale=480:-2 out.mp4

Note that i dont want to use any programming language because it's on windows cmd.

like image 743
Diok Avatar asked Jun 28 '26 15:06

Diok


1 Answers

The notation 480p refers to the height, so I assume that's what you mean.

Use

ffmpeg -i input.mp4 -c:v libx264 -crf 31 -me_method umh -bf 0 -vf scale='if(gte(ih\,480)\,480\,iw)':-2 out.mp4

This will rescale videos whose height is 480 or more.

like image 50
Gyan Avatar answered Jul 02 '26 08:07

Gyan