View Full Version : Accessing variables from ScriptClip


pvann
28th September 2005, 23:29
Is there a way to access variables generated within ScriptClip in avisynth code outside ScriptClip?

To illustrate my question, in the sample script below, I use ScriptClip’s internal functions to put a value in the variable diffY and display that on the clip (using SubTitle() within ScriptClip), but I when I try to access diffY outside ScriptClip (the call to SubTitle() in line 6), it doesn’t show the same value.

A sample frame will have 0.123 in the centre of the frame (ie diffY defined in Line 1) and say 15.32 at the top of the frame (ie diffY from ScriptClip) – as I move from frame to frame, the 15.32 will change and the 0.123 will be constant.

global diffY = 0.123
clip = AVISource("C:C deshaker.avi")
clip = converttoYV12(clip)
clipProc = ScriptClip(clip,"global diffY = YDifferenceToNext()+YDifferenceFromPrevious()"
chr(13)+ "SubTitle(Clip, String(DiffY), align=8)") #put diffY from ScriptClip at top of clip
clipProc = SubTitle(ClipProc, string(diffY), align=5) #put diffY from AVISynth script at centre of clip
return clipProc


The reason I want to do this is to clean some old VHS home video using the overlay() function to blend the results of different smoothing/cleaning filters depending on the value of the variable diffY. I can code all of this in ScriptClip, but it is “neater” to do this outside ScriptClip! My initial results show smoother results than say that produced by QMF where they switch between two or three filters depending on the motion differences. If only I could pass “ScriptClip variables” outside ScriptClip. :confused:

Peter

gzarkadas
29th September 2005, 01:12
The reason your script does not work is that you broke the line to the 1st ScriptClip call incorrectly; you should do it like this (note the \ at the end of line):

global diffY = 0.123
clip = AVISource(...your file...)
clip = converttoYV12(clip)
clipProc = ScriptClip(clip,"global diffY = YDifferenceToNext()+YDifferenceFromPrevious()" \
+ Chr(13) + Chr(10) + "SubTitle(Clip, String(DiffY), align=8)") # put diffY from ScriptClip at top of clip
return SubTitle(ClipProc, string(diffY), y=Round(clip.Height/2), align=5) # put diffY from AVISynth script at centre of clip

Note also that I added a y=... argument at the last SubTitle so that the subtitle does come to the center of the clip.

Better, thow would be to simply break your string directly, whithout coding the CRLF characters:

global diffY = 0.123
clip = AVISource(...your file...)
clip = converttoYV12(clip)
clipProc = ScriptClip(clip,"global diffY = YDifferenceToNext()+YDifferenceFromPrevious()" \
+ Chr(13) + Chr(10) + "SubTitle(Clip, String(DiffY), align=8)") # put diffY from ScriptClip at top of clip
return SubTitle(ClipProc, string(diffY), y=Round(clip.Height/2), align=5) # put diffY from AVISynth script at centre of clip

I noted also a missing \ in "C:C deshaker.avi"; shouldn't be "C:\C deshaker.avi" ?

pvann
29th September 2005, 01:52
gzarkadas - thanks for the reply

It looks like when I copied my code into my post, that numerous backslashes vanished - not sure how that happened but clear evidence of my 1st post on this forum.

Anyway my code does run but I just can't find a way to access, outside the ScriptClip function, the variables changed in the ScriptClip script?

Any ideas?

Peter

Didée
29th September 2005, 08:11
I just can't find a way to access, outside the ScriptClip function, the variables changed in the ScriptClip script?
You simply can't.

Variables used inside the conditional functions are updated for every single frame, at the time when the script is actually "running".

Outside of the conditional environment, all variables are evaluated only one single time: during the initialisation when the script is opened. Thus, there's no way to get access to the conditionally updated values outside.

So you either have to put the cruitial action into ScriptClip, too, or use FileWrite to create a log file with the needed values, which you can read in & evaluate in an upfollowing 2nd pass.

pvann
29th September 2005, 22:45
Didee - unfortunately you confirmed what I suspected after searching the avisynth site and internet.

Ah well I'll write "all the action" within ScriptClip.

Thanks for the replies.