ffmpeg - resize and crop from input file with unknown resolution I use this filter to do some cropping:

-filter_complex '[0:v]crop=w=320:h=240[v0c]


which works alright. The problem is that sometimes, I do not know what is the input that I am going to get. It might be a 1000x500 or a 500x1000, for instance. So when that happens it just gets a small area of the center of the video. The ideal would be to resize the input to match the smaller of its dimensions to my desired output, and crop the rest. The problem is that I do not know which dimension is going to be.

How could I build a filter to solve this problem?
Use

[0:v]scale='if(gt(a,4/3),-1,320)':'if(gt(a,4/3),240,-1)',setsar=1,crop=320:240[v0c]


The scale filter expressions for x and y check the aspect ratio of the input and if greater than 4:3, set the value to the 2nd argument, and if not, to the third argument. The -1 means that the original aspect ratio should be preserved e.g. scale=-1:400 applied to a 600x800 canvas will result in 300x400.