Log in

View Full Version : Applyrange calling function with global


cwolf
25th December 2004, 22:21
My intention is to get rid of flashes in a show ("David Gilmour in concert"). After some experiments that didn't satisfy me, I'm trying Depan to fix the affected fields before deinterlacing with Alignfields. This show has a lot of flashes that I noted down, and will be fixed by calling a function. Usually 3 fields are affected.
function flash (clip f, int "first", int "qty") {
global first = first # first affected field of the range
global qty = qty # number of affected fields to fix
# It copies the last and next good fields to the previous and
# current ones so that Depan can do its job.
scriptclip(f,""" x= freezeframe(current_frame -1,current_frame -1,first -1)
y= x.freezeframe(current_frame,current_frame,first + qty)
d= y.DePanEstimate(improve=true,zoommax=1.4)
offs= 1. / ( qty + 1.) * (current_frame - first + 1.)
DePan(x, data=d, offset=offs,info=true)
subtitle (" current_frame="+string(current_frame)+
\ " first="+string(first)+
\ " offset="+string(offs),
\ " qty="+string(qty),y=200)
""")
}
avisource("f:\david gilmour\show.avi",audio=false)
assumetff()
###alignfields(fps2=true,mode=0)
ibob()
showframenumber(scroll=true)
applyrange (157177,157179,"flash",157177,3)
applyrange (37115,37117,"flash",37115,3)
applyrange (6713,6715,"flash",6713,4)

Now the goddamn problem :( :
the variables first and qty keep the value from the last "applyrange" of the script! For instance, in the sequence above the value for "first" will be 6713 for all instances of applyrange. The only way I know for passing the parameters to the scriptclip is this one. I appreciate if someone could think of a workaround. There are about 100 flashes to clean.:angry:
PS: I suggest comment Depan in order to run this script, because the value for "offset" will be absurd (30093 for the range 157177).

stickboy
25th December 2004, 23:34
Yeah, that's pretty much what you can expect when you can expect when using global variables. It's not a problem with ApplyRange.

You can think of script evaluation as being in two stages:
1. Script load.
2. Exuection/frame requests.

When the script is loaded, AviSynth parses the script, evaluates expressions, and creates the filter chains. This means that it calls the "flash" function three times when the script is loaded, before it ever requests a frame. By the time you request frames, your global variables have been set to their final values already.

(I really do not like this global variable business with ScriptClip/FrameEvalute/et al., but oh well.)

And none of that really helps you. Heh.

I suppose a possible workaround to try:
function flash(clip f, int "first", int "qty")
{
return ScriptClip(f, "first = " + String(first)
\ + "qty = " + String(qty)
\ + """x = FreezeFrame(...)
y = x.FreezeFrame(...)
...""")
}

tsp
26th December 2004, 00:47
you could try this scriptclip instead:

scriptclip(f,""" x= freezeframe(current_frame -1,current_frame -1,first -1)
y= x.freezeframe(current_frame,current_frame,first + qty)
d= y.DePanEstimate(improve=true,zoommax=1.4)
offs= 1. / ( qty + 1.) * (current_frame - first + 1.)
DePan(x, data=d, offset=offs,info=true)
subtitle (" current_frame="+string(current_frame)+
\ " first="+string(first)+
\ " offset="+string(offs),
\ " qty="+string(qty),y=200)
""",after_frame=true)

cwolf
19th January 2005, 00:10
I hope it's never too late to thank :o
The script that worked is this. I made an AVSI and put it in the plugin directory:

function applyflash(clip a, int fn, int qt) {a
eval ("""applyrange (fn,fn+qt-1,"flash",fn,qt)""")}

function flash (clip f, int "first", int "qty") {
scriptclip(f,"first = "+string(first) +chr(13)+
\ "qty = " +string(qty) +chr(13)+
\ """x= freezeframe(current_frame -1,current_frame -1,first -1)
Y= x.freezeframe(current_frame,current_frame,first + qty)
d= y.DePanEstimate(improve=true,zoommax=1.4)
offs= 1. / ( qty + 1.) * (current_frame - first + 1.)
DePan(y, data=d, offset=offs,info=false)
#subtitle (string(offs)+" "+string(first)+" "+string(qty),y=200)
#stackhorizontal(x.trim(current_frame - 1,-1).crop(0,0,360,0),y.crop(360,0,0,0))
""")}


avisource("f:\xxx.avi",audio=false)
assumetff()
alignfields(fps2=true,mode=0)
#showframenumber(scroll=true)
applyflash(271,3)
applyflash(288,2)
applyflash(703,2)
...
AssumeTFF().SeparateFields().SelectEvery(4,0,3).Weave()
alignfields(mode=3,scene=3)

I went further and did a wraper function to call it, using Stickboy's ideas. This solution pleased me more, although all that Depan gives is a freezed frame that moves toward a global movement.
Your help was unvaluable. Thank you guys! :cool:
Cecilia