coco
coco

Reputation: 3136

What is the variable "a" in ffmpeg?

In using the scale filter with ffmpeg, I see many examples similar to this:

ffmpeg -i input.mov -vf scale="'if(gt(a,4/3),320,-2)':'if(gt(a,4/3),-2,240)'" output.mov

What does the variable a signify?

Upvotes: 2

Views: 2463

Answers (3)

coco
coco

Reputation: 3136

In the ffmpeg wiki "Scaling (resizing) with ffmpeg", they use this example:

ffmpeg -i input.jpg -vf scale="'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)'" output.png

The purpose of the gt(a,4/3) is, as far as I can tell, to determine the orientation (portrait or landscape) of the video (or image, in this case).

This wouldn't work for some strange aspect ratios (7:6, for an example, where gt(a,4/3) would incorrectly turn false.

It seems to me better to use the height and width of the video, so the above line would instead be:

ffmpeg -i input.jpg -vf scale="'if(gt(iw,ih),320,-1)':'if(gt(iw,ih),-1,240)'" output.png

Upvotes: 1

Maxito
Maxito

Reputation: 629

From the ffmpeg scale options docs.

a The same as iw / ih

where

iw Input Width ih Input Height

Upvotes: 4

Zyberzero
Zyberzero

Reputation: 1604

My guess after reading https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg is that a is the aspect ratio of the input file.

The example given on the webpage gives you an idea how to use it:

Sometimes there is a need to scale the input image in such way it fits into a specified rectangle, i.e. if you have a placeholder (empty rectangle) in which you want to scale any given image. This is a little bit tricky, since you need to check the original aspect ratio, in order to decide which component to specify and to set the other component to -1 (to keep the aspect ratio). For example, if we would like to scale our input image into a rectangle with dimensions of 320x240, we could use something like this:

ffmpeg -i input.jpg -vf scale="'if(gt(a,4/3),320,-1)':'if(gt(a,4/3),-1,240)'"
output_320x240_boxed.png

Upvotes: 1

Related Questions