Log in

View Full Version : New function to compare filters


qwerpoi
17th September 2003, 21:59
Here's a function I wrote to get a quick way to view the effect of filters in Avisynth 2.5:

function ViewEffect(clip a,clip "b",int "mode")
{
mode = default(mode,0) #0 is default, 1 is 1st half only, 2 is "flipped"
assert((mode==0)||(mode==1)||(mode==2), "Valid modes are 0, 1, or 2")
ap = a.ConvertToYUY2()
bp = (mode == 0) ? b.crop((b.width)/2,0,(b.width)/2,(b.height)).ConvertToYUY2() :
\ ((mode == 1) ? b.crop(0,0,(b.width)/2,(b.height)).ConvertToYUY2() :
\ b.crop(0,0,(b.width)/2,(b.height)).FlipHorizontal().ConvertToYUY2())

c = Layer(ap,bp,"add",255,(b.width)/2,0)
line = BlankClip(length=1,width=2,height=a.height,color=$000000,pixel_type="YUY2")
return Layer(c,line,"add",255,(b.width)/2,0)
}


The function works similar to the Subtract() (http://www.avisynth.org/index.php?page=Subtract) command in Avisynth, where it takes in two clips from the same source a and b, where a is filtered one way and b is filtered another. The output is the video with the left half filtered like clip a and the right half filtered like clip b. For example,

source = AviSource("C:\something.avi")
clipa = source
clipb = source.Blur(1.0)
ViewEffect(clipa,clipb)

This script returns the source with the left half of the image unfiltered and the right half of the image blurred. It's a good way to see the visual impact of any filters or chain of filters you want to use. I personally suggest using VirtualDub or VirtualDubMod to preview your scipts, since you can use the arrow keys to examine the video frame by frame. I do not suggest playing the script back in a media player, since the function is quite slow, it's just for comparing filters, not for encoding. There's an optional mode parameter you can try out which does different comparisons (mode 1 compares left halves only, mode 2 is like mode 1 but a flipped right half, mode 0 is default - I can't describe it very well, try it out to understand :)).

As a quick aside, for those of you who don't know how to use functions in Avisynth, all you need to do is copy the function code and put it at the top of the script, you can then use the command ViewEffect() as shown in the example. If you don't like putting the function at the top of every script you make, you could instead copy the function into a seperate text file and name it "functions.avsi", then put it in your plugins directory, which makes it autoload.