View Full Version : retrieve name of variable as String
gwendolien
13th May 2013, 16:36
Is it possible somehow to retrieve the name of a variable as a String?
clip1=AviSource(....)
s=String(clip1)
resulting in s being equal to: "clip1"
???
StainlessS
13th May 2013, 17:01
Just curious, what do you want to use that for?
Gavino
13th May 2013, 17:02
An obvious solution is
s = "clip1"
If that isn't what you mean, you will have to explain the context of your requirement in more detail.
gwendolien
13th May 2013, 17:39
StainlessS and Gavino: THANKS for the response.
I guess I'm just lazy: while writing my own version of a kind of Clip_Info Function,
I realized I was typing:
Return Clip_Info(clip1, "clip1")
and I just wondered is there a way to NOT need the separate String version of the clip name as the second argument....
Gavino
13th May 2013, 17:49
There is nothing in a clip which associates it with a variable name, as with all variables the relation is strictly one-way, name -> value.
In any case, a clip might not be associated with a variable.
What would you expect this to do?
return Clip_info(ColorBars())
???
HOWEVER, ...
you could make the function take a string (rather than a clip) as its only parameter. Then the string could indicate the name and by Eval'ing the name you could recover the clip too. However, the variable would have to be global.
StainlessS
13th May 2013, 17:54
Not really the sort of thing that could be reliably implemented in a plugin, even if it could, the internal storage
lists/structures could change and break the plug, would need to be built into Avisynth itself.
Maybe eval could be persuaded to assist, but is likely to be more awkward than the extra typing that you currently are accursed with.
Arh, beaten again :(
gwendolien
13th May 2013, 20:17
Thanks a lot both of you Gavino and StainlessS!
Not familiar with eval as such, but will give it a try.
StainlessS
13th May 2013, 20:44
Here implemented as per Gavino post,
Global MyClip=Avisource("D:\avs\test.avi")
s=Test("MyClip")
Myclip.SubTitle(S,lsp=0)
return Last
Function Test(String s) {
c=Eval(s)
s = "Name ="+S+"\n"+ \
"Width ="+String(c.Width)+"\n"+ \
"Height="+String(c.Height)+"\n"+ \
"Length="+String(c.FrameCount)+"\n"
return s
}
lsp in subtitle turns on multi-line mode, and we use '\n' to represent newline characters for Subtitle, you might want to use
Chr(10) instead of '\n', dependant upon purpose.
EDIT: This also works but the clip name is purely a nicety for return string.
Avisource("D:\avs\test.avi")
s=Test("MyClip")
SubTitle(S,lsp=0)
return Last
Function Test(clip c,String s) {
s = "Name ="+S+"\n"+ \
"Width ="+String(c.Width)+"\n"+ \
"Height="+String(c.Height)+"\n"+ \
"Length="+String(c.FrameCount)+"\n"
return s
}
EDIT: Or maybe
FN="test.avi" DIR="D:\avs\"
Avisource(DIR+FN)
s=Test(FN)
SubTitle(S,lsp=0)
return Last
Function Test(clip c,String s) {
s = "Name ="+S+"\n"+ \
"Width ="+String(c.Width)+"\n"+ \
"Height="+String(c.Height)+"\n"+ \
"Length="+String(c.FrameCount)+"\n"
return s
}
gwendolien
14th May 2013, 13:02
Got the example as per Gavino working!
I am not used to code like c=Eval(s) where I think variable c's type at that point is undetermined.
simply writing c.Width further on, the thing is clearly interpreted as being a clip...
Nevertheless, it'working!!!
StainlessS
14th May 2013, 13:22
or you could just enter
Function Test(String s) {
Eval(s)
s = "Name ="+S+"\n"+ \
"Width ="+String(Width)+"\n"+ \
"Height="+String(Height)+"\n"+ \
"Length="+String(FrameCount)+"\n"
return s
}
to assign clip to Last, where "Eval(s)" is just the same as directly entering "MyClip" to assign to Last, ie
Function Test(String s) {
MyClip # assign Global to Last
s = "Name ="+S+"\n"+ \
"Width ="+String(Width)+"\n"+ \
"Height="+String(Height)+"\n"+ \
"Length="+String(FrameCount)+"\n"
return s
}
For Eval(s), if you like string s, holds a mini script which is executed within the context of the Test() function.
Gavino
14th May 2013, 14:28
I am not used to code like c=Eval(s) where I think variable c's type at that point is undetermined.
simply writing c.Width further on, the thing is clearly interpreted as being a clip...
The type of 'c' will be the type returned by Eval() which, unlike most functions, is not fixed in advance and depends on the string supplied. In this case, you gave it the name of a variable which referred to a clip, so it produced that clip as its result and assigned it to 'c'.
If instead you wrote
global myclop = 42
s = Test("myclop")
c.width would produce an error inside the function as it would be trying to take the width of an integer.
gwendolien
15th May 2013, 12:16
But.....
when I try to recover information from RunTime only functions,
I get an error "only available in runtime environment".
OK, so I invoke ScriptClip as follows:
Global MyClip=....
return ClipStats("MyClip", 5.0)
Function ClipStats(String s, float thr)
{
c=Eval(s)
return c.ScriptClip("""String(RT_AverageLuma(c))+" | stdev= "+String(RT_YPlaneStDev(c))\
+"\nlumamed= "+String(RT_YPlaneMedian(c))+" | lumamax= "+String(RT_YPlaneMax(c, threshold=thr))\
+"\nlumamin= "+String(RT_YPlaneMin(c, threshold=thr)), size=15, x=0,y=0, lsp=0)""")
}
but then I get an error:
"I don't know what c is"...
Gavino
15th May 2013, 12:35
Since c is the input parameter to ScriptClip(), it becomes 'last' inside the run-time script, so instead of RT_AverageLuma(c), you can just write RT_AverageLuma().
I think you are also missing the call to Subtitle(), so your code should look like
return c.ScriptClip("""Subtitle(String(RT_AverageLuma())+ ...
EDIT: Ah, but then it will now say that it doesn't know what thr is.
You can get round that by using GRunT and adding args="thr" to the ScriptClip call.
gwendolien
15th May 2013, 12:48
T H A N K S !!
Your reply is "right on the nail", as the dutch saying goes!
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.