Log in

View Full Version : filename to string?


smok3
18th May 2007, 21:06
how do i get a filename to string? (i would like to use it as a title), like:

somestringvar = string(clip.filename) ? #well, it should allready be a string...

gzarkadas
19th May 2007, 11:41
I don't think it is possible; AFAIK a clip once loaded does not carry information about its source file. You will have to keep track of the filenames manually.

If you really need to create a clip "object" with extra properties that you access on demand (say just the filename as an example), you could use someting like the following:


function NamedSource(string file) { return ArrayCreate(AviSource(file), file) }

aclp = NameSource("c:\somedir\some.avi")
...
# apply a filter to clip, say Levels
aclp = aclp.ArraySet(0, aclp.ArrayGet(0).Levels(0,1,255,10,245))
...
# get the name when wanted
somestringvar = aclp.ArrayGet(1)


This of course implies using my library :) . There is also a small added complexity because every time you want to modify the clip you will have to use the ArrayGet/ArraySet combination, but this may be - depended on application - less than keeping track the extra properties yourself.

smok3
19th May 2007, 12:59
ic, kinda funny i can get clip.width or almost anything, bit i cant get clip name isn't it thought? :)

gzarkadas
19th May 2007, 13:43
Well, as it is the case with all engineering projects, some things are included in the specs and the rest are excluded. I must admit though that I am a bit curious: why do you need the filename as a clip property and not simply supply it by yourself (clips are usually loaded explicitly by name in a script)?

squid_80
19th May 2007, 16:36
ic, kinda funny i can get clip.width or almost anything, bit i cant get clip name isn't it thought? :)
Not really, clip might not originate from a file (think blankclip or colorbars) or might be the result of several files combined in the filterchain, in which case how would it determine which filename to return?

gzarkadas
19th May 2007, 20:38
Not really, clip might not originate from a file (think blankclip or colorbars) or might be the result of several files combined in the filterchain, in which case how would it determine which filename to return?

Correct and comprehensive :) . If however one would like to implement such a property he/she could follow the following set of rules:

for single clip in file system -> it's filename
for single clip not in file system -> the empty string
for combination of clips -> the filename of the first (this is what AviSynth does in most multi-clip filters)


The key question is whether it would be worth to have that property (the application domain question) since it means a possibly serious memory overhead (a unicode filename string can easily be even 1 - 2 KB in size and this would have to be replicated in each filter's instance across the filter chain) and a (less) speed one.

I can imagine some uses of this, but I would prefer to create an object (such as the one described in previous post) when I would need it instead of having to pay for it every time.

smok3
20th May 2007, 15:03
gzarkadas: iam trying to do a simple countdown clock, work in progress:
http://somestuff.org/avs/coolclock2.avs

tnx for your help so far, will try to play with your function.

mgh
20th May 2007, 15:37
have you looked at list of avisynth string functions in syntax.htm installed along with avisynth?

stickboy
20th May 2007, 18:47
Since you ultimately just pass the filename to Subtitle anyway, you instead could make your CoolClock function take a filename as an argument instead of a clip, and let it call AVISource directly.

Or instead of using AVISource, make a LabeledAVISource wrapper function (http://forum.doom9.org/showthread.php?t=108605) to call AVISource + Subtitle.

I don't think it makes sense for clips to have filenames. Since not all clips are generated directly from individual files, I don't think such a property should be imposed, and also it's information that already is specified by the script. You already know your own filename.

smok3
20th May 2007, 20:14
Since you ultimately just pass the filename to Subtitle anyway, you instead could make your CoolClock function take a filename as an argument instead of a clip, and let it call AVISource directly. and that would solve what?

I don't think it makes sense for clips to have filenames. Since not all clips are generated directly from individual files, I don't think such a property should be imposed...ok, i got that part allready.

stickboy
20th May 2007, 22:56
and that would solve what?It'd avoid your need to derive the filename from the clip and minimize any additional bookkeeping you'd need to do.

gzarkadas
23rd May 2007, 21:16
@smok3,

This thread motivated me (thank you for steering up the subject :)) to start preparing an article for implementation of objects with custom attibutes (actually "class" hierarchies) in Avisynth.

The article will take some time to finish, but I have ready an implementation of a custom clip "class" with a filename attribute included that you may find suitable for your needs - see the attached file. You just have to remove the "test" section from the script and is ready to be imported.

@all,

I would also appreciate any comments regarding how this scheme could be improved to provide an as close as the Avisynth script language permits generic "class" implementation mechanism.