Log in

View Full Version : Trying to figure out why a script works one way, but not another.


Oswald Bastable
6th July 2006, 02:20
I'm something of a newbie at this, but an inveterate researcher before I usually ask questions. I can't figure out why a script works correctly in one case, but not in another. Either I've done something wrong in my additions (and I believe I may know where, though I'm not positive), or there's something I'm missing.

The setup:

I've been developing a script to clean up some old B&W film, specifically some Three Stooges shorts, using filters like removedirt, removegrain, despot and others as you will see. The problem came up when I tried to apply the script to 3 different trimmed parts of a short, as each part needed to be cropped differently before being resized and rejoined.

The original script is as follows:

LoadPlugin("D:\DVD\AviSynth\plugins\DGDecode.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\Decomb.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\despot.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\removedirt.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\removegrain.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\msharpen.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\descratch.dll")
MPEG2Source("Uncivil Warriors.d2v")
AssumeTFF()
Telecide(guide=1)
Decimate()
#Crop(0,0,-16,-8)
removedirt(grey=true,pthreshold=10,mthreshold=150)
removegrain()
i=last
d=depanestimate(trust=3)
depaninterleave(i,data=d)
despot(p1=30,p2=15,pwidth=702,pheight=276,mthres=20,motpn=true,dilate=1,seg=1)
selectevery(3,1)
descratch()
msharpen(threshold=100,strength=150)
#LancZosResize(640,480)
greyscale()

The crop and resize are commented out here because I ended up running the script on the short and saving as an uncompressed .avi, then doing the trim, crop and resize in a second script when compressing to xvid. I should also mention that I believe my problem may be with the despot portion and the way I had to adapt it for my attempt to do all in one script. I found the despot example in another thread and tried it, and it seemed to do what I wanted.

The adapted script including trim, etc. that I put together is as follows:

LoadPlugin("D:\DVD\AviSynth\plugins\DGDecode.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\Decomb.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\despot.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\removedirt.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\removegrain.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\msharpen.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\descratch.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\depan.dll")
video=MPEG2Source("Uncivil Warriors.d2v").AssumeTFF().Telecide(guide=1).Decimate()
Open=video.Crop(38,24,-58,-24).Trim(0,924).removedirt(grey=true,pthreshold=50,mthreshold=150,athreshold=100).removegrain().descratch().msharpen(threshold=100,strength=150).LancZosResize(640,480).greyscale()
function mydespot {
i=last
d=depanestimate(trust=3)
depaninterleave(i,data=d)
despot(p1=30,p2=15,pwidth=702,pheight=276,mthres=20,motpn=true,dilate=1,seg=1)
selectevery(3,1)
}
Main=video.Crop(0,0,-16,-8).Trim(925,27992).removedirt(grey=true,pthreshold=10,mthreshold=150).removegrain().descratch().msharpen(threshold=100,strength=150).LancZosResize(640,480).greyscale()
function mydespot {
i=last
d=depanestimate(trust=3)
depaninterleave(i,data=d)
despot(p1=30,p2=15,pwidth=702,pheight=276,mthres=20,motpn=true,dilate=1,seg=1)
selectevery(3,1)
}
Close=video.Crop(32,24,-40,-24).Trim(27993,0).removedirt(grey=true,pthreshold=10,mthreshold=150).removegrain().descratch().msharpen(threshold=100,strength=150).LancZosResize(640,480).greyscale()
function mydespot {
i=last
d=depanestimate(trust=3)
depaninterleave(i,data=d)
despot(p1=30,p2=15,pwidth=702,pheight=276,mthres=20,motpn=true,dilate=1,seg=1)
selectevery(3,1)
}
return Open+Main+Close

The open, main and close refer to the opening credits, main short and closing credits. When I run the first script on the whole short, everything comes out looking quite good. When I run the second one, some of the single frame spots that I believe removedirt should be removing, remain. I think those spots may have actually been removed by despot, and that's where my problem is, but I'm not sure because other defects that removedirt alone wouldn't deal with (stuff that's two or three frames long) is still cleaned up.

In putting the second script together, I kept getting function argument errors on the despot section, until I turned it into a function, but I'm not sure I've done it correctly...except that it does seem to work for many of the problems I have it in there for.

I just can't figure out why single frame defects that are removed with the first script, aren't with the second and I'm hoping someone can point out my error. As an example, in the opening credits on frame 421, a single white spot appears in a specific place on that frame (it's definitely not there on frames 420 or frame 422), and it's removed by the first script, but not by the second. There are other examples I found as well.

I'm sure there are other ways I could tighten this script up, but as I mentioned at the outset, I'm a bit of a newbie here and more interested in what works at this point, rather than elegance or speed.

Many thanks and sorry for the long windedness. :)

stickboy
6th July 2006, 03:12
In putting the second script together, I kept getting function argument errors on the despot section, until I turned it into a function, but I'm not sure I've done it correctly...except that it does seem to work for many of the problems I have it in there for.You don't actually call your mydespot function anywhere. (And why do you define it twice?)

Oswald Bastable
6th July 2006, 03:28
You don't actually call your mydespot function anywhere. (And why do you define it twice?)

Thanks for the response stickboy...I thought I might have a problem there, but wasn't sure. As I mentioned, I'm pretty wet behind the ears here and sometimes stabbing in the dark. Turning the despot code into a function was the only way I could get the script to load without an avisynth error about missing function arguments.

I was pretty sure I had something wrong, except that there were multiple white spots longer than a single frame which removedirt alone wouldn't deal with, yet did disappear in a frame by frame comparison using the second script, so I thought I had it working correctly...obviously not, but if so it raises a second question.

Why would large white blobs of 2-3 frames, not removed by removedirt alone...be removed by an uncalled despot function in the second script. Removedirt alone wouldn't touch them in the first script (why I added the despot routine, which did remove them), but they are also removed by the second script, while some single frame spots are left, which the working removedirt call should have caught.

Damn...was that convoluted enough? :)

I'm still struggling with this and at this point couldn't put a function together to save my life, so I'm relegated to finding examples in other posts and trying to adapt them to my needs and level of understanding as I progress in this learning process.

Oswald Bastable
10th July 2006, 06:22
Ah...it would appear that this forum is only useful to those who already know what they are doing, and those of us who are struggling with avisynth or scripting are on our own.

128 views and one less than useful reply...

I shall continue my quest on my own since it appears there is no help here.

Are you not entertained?

Guest
10th July 2006, 06:24
Yup, we're all idiots. Sorry to have disappointed you.

Didée
10th July 2006, 09:45
Ther're a dozen different ways to make that script correct. The follwing isn't the most elegant, but the one that required the least effort in respect to copy+paste+adapt. ;)

LoadPlugin("D:\DVD\AviSynth\plugins\DGDecode.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\Decomb.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\despot.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\removedirt.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\removegrain.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\msharpen.dll")
LoadPlugin("D:\DVD\AviSynth\plugins\descratch.dll")

MPEG2Source("Uncivil Warriors.d2v")
AssumeTFF()
Telecide(guide=1)
Decimate()

video = last

Open = video .trim( 0, 924) .AllAtOnce(38,24,-58,-24, 640,480)
Main = video .trim( 925,27992) .AllAtOnce( 0, 0,-16, -8, 640,480)
Close = video .trim(27993, 0) .AllAtOnce(32,24,-40,-24, 640,480)

Open ++ Main ++ Close

return( last )

#-----------------------------------

function AllAtOnce(clip clp, int cropleft, int croptop, int cropx, int cropy, destx, desty)
{
clp
Crop(cropleft,croptop,cropx,cropy)
removedirt(grey=true,pthreshold=10,mthreshold=150)
removegrain()
i=last
d=depanestimate(trust=3)
depaninterleave(i,data=d)
despot(p1=30,p2=15,pwidth=702,pheight=276,mthres=20,motpn=true,dilate=1,seg=1)
selectevery(3,1)
descratch()
msharpen(threshold=100,strength=150)
LanczosResize(destx,desty)
greyscale()
}

Note that

a) just dropping a function definition somewhere in the script does not do anything. You have to actually *call* the defined function, in order to let it do something.

b) when defining a function, you need to have at least one parameter: a clip variable to which the stuff within the function is referring to

Oswald Bastable
11th July 2006, 01:29
Yup, we're all idiots. Sorry to have disappointed you.

Actually I believe I'm the one that's the idiot as far as avisynth scripting is concerned...hence my questioning. :)

In looking over the many posts in this section of the forum I see many newbie type posts that seem to go unanswered or are glossed over, while those of you who genuinely know what you're doing seem more interested in discussing the finer points that I can only hope to understand one day. There really doesn't seem to be enough concentrated info on the net for those of us struggling to understand this subject.

For example, my gf is a fractal artist, mostly working as a novice, playing with the various programs and turning out some very good stuff, but she always wanted to learn much more about the finer points of what could be done, of which there is not really enough info to be found without much search and pieceing together of disparate info gleaned here and there, much like the info on avisynth usage/script building.

Recently, one of the members of one forum she frequents, someone with a much vaster knowledge of the subject and programs than she has, began offering classes for a fee (I believe $25 per person per class, with each class offering several lessons of increasing complexity), which she has gladly joined and paid for, much to her delight and now growing understanding.

Each lesson is downloaded with instructions, results are posted to the forum for critique and suggested improvement, advice and additional instruction is offered for those in the class who are struggling with a given lesson.

Now if someone hereabouts were to do something of the same with Avisynth, I'd be willing to bet they could make some decent money. I know that I for one would gladly pay for and join such a class as I probably spent a dozen or more hours search for the right tools and info just to put together the two scripts above, one of which did the job (albeit haphazardly) and one of which was flawed. :)

By the way, many thanks for the great work you've done neuron. I greatly appreciate it. I only wish I knew how to better make use of it.

Oswald Bastable
11th July 2006, 01:34
Ther're a dozen different ways to make that script correct. The follwing isn't the most elegant, but the one that required the least effort in respect to copy+paste+adapt. ;)


Note that

a) just dropping a function definition somewhere in the script does not do anything. You have to actually *call* the defined function, in order to let it do something.

b) when defining a function, you need to have at least one parameter: a clip variable to which the stuff within the function is referring to


Many, many thanks Didée, that's just the kind of example I was looking for, something that would show me how to do it right after having botched it. After struggling with this for some time, I'm pretty sure your example will set me quite a bit further along the path I'm looking for. :)

Also, my apologies for my earlier reply. I will contain my frustrations in future.

Wilbert
11th July 2006, 10:35
@Oswald, spend a few weeks browsing http://www.avisynth.org/mediawiki/wiki/Main_Page. It contains much of the info you are looking for.