View Full Version : Function: Automatic Cropping & Resizing


crOOk
7th December 2003, 12:46
Does anyone know of a function that can crop and resize automatically, given one out of 4 aspect ratios? Do you think it would even be possible to write such a function within AviSynth? It would surely save a lot of work.

r6d2
7th December 2003, 13:50
There is something called GripFit. For DVD2SVCD there is also something called FACAR.
Also, don't forget to :search:

Mango Madness
8th December 2003, 13:40
look up autocrop

elmaxxo
9th December 2003, 23:09
Hi, this may help you;it's what I use and it works fine for me:

LoadPlugin("C:\Program Files\AviSynth 2.5\Plugins\AutoCrop.dll")

you can get the Autocrop filter from the Avisynth site, the in your main routine use this line:

video=AutoCrop(video, 0, 4, 2, 2, 2, 2, 2, 40, 10)

I do the cropping before resizing, which I do with this function:

function AutoResize(clip video, int RRF, float AR, int Bilinear, int Lanczos)
{
Resolution=width(video) * height(video) * RRF * 0.01
TempH=round(sqrt(Resolution / AR))
TempW=round(TempH * AR)
NH=TempH - TempH%16
NW=TempW - TempW%16
DefaultResize=BicubicResize(video, NW, NH)
CustomResize=(Bilinear==1)?BilinearResize(video, NW, NH):LanczosResize(video, NW, NH)
video=(Bilinear==0 && Lanczos==0)?DefaultResize:CustomResize
video
}

RRF (Resolution Reduction Factor I call it)is a percentage, for example if you want to reduce the original resolution to say 80% your RRF will be 80. The function will keep the aspect ratio as close to the original as possible but sometimes you have to try a few times and compare your results. To solve this problem I use a display function that tells me what the new aspect ratio is and the deviation between original and new aspect ratios, a little math and some subtitles. Lanczos and Bilinear are switches, they are either 1 (use) or 0 (default), the default resizer is Bicubic. I have seen other functions similar to this one but they work based on BPPF, I don't care for BPPF because I do compressibility tests and I found that many times BPPF is irrelevant.
Finally in your main routine you call the function like this:

video=AutoResize(video, RRF, AR, 0, 0)

I hope this will be of help.