Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

Domains: forum.doom9.org / forum.doom9.net / forum.doom9.se

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage
Register FAQ Today's Posts Search

Reply
 
Thread Tools Search this Thread
Old 13th May 2013, 16:36   #1  |  Link
gwendolien
Registered User
 
Join Date: Nov 2005
Posts: 70
retrieve name of variable as String

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"

???
gwendolien is offline   Reply With Quote
Old 13th May 2013, 17:01   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,479
Just curious, what do you want to use that for?
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 13th May 2013, 17:02   #3  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,444
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 13th May 2013, 17:39   #4  |  Link
gwendolien
Registered User
 
Join Date: Nov 2005
Posts: 70
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....
gwendolien is offline   Reply With Quote
Old 13th May 2013, 17:49   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,444
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 13th May 2013 at 17:55.
Gavino is offline   Reply With Quote
Old 13th May 2013, 17:54   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,479
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
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 13th May 2013, 20:17   #7  |  Link
gwendolien
Registered User
 
Join Date: Nov 2005
Posts: 70
Thanks a lot both of you Gavino and StainlessS!
Not familiar with eval as such, but will give it a try.
gwendolien is offline   Reply With Quote
Old 13th May 2013, 20:44   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,479
Here implemented as per Gavino post,

Code:
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.

Code:
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

Code:
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
}
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 13th May 2013 at 21:02.
StainlessS is offline   Reply With Quote
Old 14th May 2013, 13:02   #9  |  Link
gwendolien
Registered User
 
Join Date: Nov 2005
Posts: 70
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!!!
gwendolien is offline   Reply With Quote
Old 14th May 2013, 13:22   #10  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,479
or you could just enter

Code:
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

Code:
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.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 14th May 2013 at 13:32.
StainlessS is offline   Reply With Quote
Old 14th May 2013, 14:28   #11  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,444
Quote:
Originally Posted by gwendolien View Post
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 15th May 2013, 12:16   #12  |  Link
gwendolien
Registered User
 
Join Date: Nov 2005
Posts: 70
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:
Code:
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"...
gwendolien is offline   Reply With Quote
Old 15th May 2013, 12:35   #13  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,444
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
Code:
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 15th May 2013 at 12:40.
Gavino is offline   Reply With Quote
Old 15th May 2013, 12:48   #14  |  Link
gwendolien
Registered User
 
Join Date: Nov 2005
Posts: 70
T H A N K S !!

Your reply is "right on the nail", as the dutch saying goes!
gwendolien is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 21:42.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.