3

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.

Diok
  • 83
  • 2
  • 10
  • Use ffprobe to determine the video dimensions: https://stackoverflow.com/questions/7362130/getting-video-dimension-from-ffmpeg-i – WLGfx May 02 '19 at 10:36
  • I'm running ffmpeg code in windows cmd alone, im not using any other programming language (i updated my question) – Diok May 02 '19 at 10:40

1 Answers1

6

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.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • thanks do you test it by your self? because it causes error in my side : [Parsed_scale_0 @ 000001deab116e80] Invalid size 'if(gte(ih' [AVFilterGraph @ 000001deab4eac00] Error initializing filter 'scale' with args 'if(gte(ih:flags=bicubic' Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0 Conversion failed! – Diok May 02 '19 at 10:46
  • 2
    Your shell needs escaping. Modified. – Gyan May 02 '19 at 11:27