Log in

View Full Version : script to return video file name


mtamimi
25th June 2007, 11:45
I made a code like this:
v=DirectShowSource("myclip.wmv")
source=v.FilteredClip()
...
...
return source

function FilteredClip(clip v) {
...
...
...
}

What i am looking for is a script to return the clip name (file's name) not the avs file name! So return source will become:

return source.subtitle(v.wmvfilename())

thnx in advance;

P.S. When I finish my code I will post it here so i can hear your opinions. I just started scripting using avisynth, I know C, so it was not that difficult.

gzarkadas
25th June 2007, 12:12
...What i am looking for is a script to return the clip name (file's name) not the avs file name! So return source will become:

return source.subtitle(v.wmvfilename())
...


This is not so trivial as it seems at first; have a look at this thread (http://forum.doom9.org/showthread.php?t=125986).

smok3
25th June 2007, 12:14
was just trying to link to the same thread :)

mtamimi
25th June 2007, 12:52
Thanx to both fo you...:D :D

I was thinking the same, how in hell they inluded every clip property but not the filename??!! Memory should not be an issue now...right?!

P.S. gzarkadas: I just noticed that you are the one who made that file....thnx.

IanB
25th June 2007, 15:38
Try this styleglobal fname = "filename.wmv"

DirectShowSource(fname, ....)

SubTitle("This is file " + fname)

mtamimi
25th June 2007, 16:15
Thnx

The problem is this:

v1=DirectShowSource("clip1.wmv")
v2=DirectShowSource("clip2.wmv")
v3=DirectShowSource("clip3.wmv")
...
...
vn=DirectShowSource("clipn.wmv")

source=v1.FilteredClip()+v2.v1.FilteredClip()+...+vn.FilteredClip()

return source

function FilteredClip(clip v) {

// this one calls 5 other function.
...
...
...


What you are suggesting will make me do this

fname1="clip1"
v1=DirectShowSource(fname1)

return(FilteredClip(v1,fname))

function FilteredClip(clip v, string fname) {
...
...
...
dummy=final_result

return(dummy.subtitle(fname))
}

I will work on this and post my code later

mtamimi
25th June 2007, 21:35
My code now looks like this, it does show the filename of each clip, but if you look closely you will notice that it could be improved, if we just have loops or if we can use something like vectors -similar to MATLAB for instance-

The story:
I have 29 wmv clips; the frame rate, the aspect ratio, and the audio sample rate are different. I wanted to combine them all into 1 big xvid file, and at the same time show the names of the clips...this code does that...I use this avs file with VirtualDub, and i do all the editing there!

Maybe there is something already made to do this, I really do not know!!

I wish if there is a way in which the script will automatically read the files in a specific folder and do all the process w/o me entering all the information...!!!

currently I am busy with me thesis...maybe when I am done, I will see if I can make dll to so something like that....I just started working on avisynth, so I am not sure if this is even possible!!!

P.S.

I chose to use small functions so I can expand them later to do more work! This is a n0000bish way to do it...but it helped me.

I also know that I can fix all the functions with one command, but I preferred to check each clip properties and see if it is compatible with my preferred settings or not!!

global SRate=44100
global Width=640
global Height=480
global FRate=29.970
global number=0

c1="clip1.wmv"
c2="clip2.wmv"
...
...
...
c_n="clip_n.wmv"

v1=DirectShowSource(c1)
v2=DirectShowSource(c2)
...
...
...
v_n=DirectShowSource(c_n)

source=NewClip(v1,c1)+NewClip(v2,c2)+...+NewClip(v_n,c_n)

return source

function NewClip(clip v, string name) {

fr=(v.Framerate==FRate) ? 1 : 0
ar=(v.Width==Width && v.Height==Height) ? 1 : 0
sr=(v.Audiorate==SRate) ? 1 : 0

dummy = (fr==1 && sr==1 && ar==1) ? v.dontfix() :\
(fr<>1 && sr<>1 && ar<>1) ? v.fixsaf() :\
(fr==1 && sr==1 && ar<>1) ? v.fixs() :\
(fr==1 && sr<>1 && ar==1) ? v.fixa() :\
(fr<>1 && sr==1 && ar==1) ? v.fixf() :\
(fr<>1 && sr<>1 && ar==1) ? v.fixaf() :\
(fr<>1 && sr==1 && ar<>1) ? v.fixsf() : v.fixas()

return(dummy.subtitle(name))
}

function dontfix(clip v) {
return(v)
}

function fixsaf(clip v) {
return(Lanczos4Resize(SSRC(ConvertFPS(v,FRate),SRate),Width,Height))
}

function fixs(clip v){
return(Lanczos4Resize(v,Width,Height))
}

function fixa(clip v) {
return(SSRC(v,SRate))
}

function fixf(clip v) {
return(ConvertFPS(v,FRate))
}

function fixaf(clip v) {
return(SSRC(ConvertFPS(v,FRate),SRate))
}

function fixsf(clip v) {
return(Lanczos4Resize(ConvertFPS(v,FRate),Width,Height))
}

function fixas(clip v) {
return(Lanczos4Resize(SSRC(v,SRate),Width,Height))
}

mtamimi
25th June 2007, 21:52
to remove the extensions
return(dummy.subtitle(LeftStr(name, StrLen(name)-4)))
instead of this
return(dummy.subtitle(name))

gzarkadas
26th June 2007, 00:49
...if we just have loops or if we can use something like vectors -similar to MATLAB for instance...

There are vectors, as an extension (see my sig for link). Have a look at this thread (http://forum.doom9.org/showthread.php?p=1013430#post1013430) for an example of a more compact way to make such operations.


...I wish if there is a way in which the script will automatically read the files in a specific folder and do all the process w/o me entering all the information...!!!

1. In a command prompt, after changing directory to the folder in question (if you make this a batch file make %f ->%%f), type the following three commands, one line after the other:

@echo ^"^"^" > myfiles.avs
for %f in (*.vmw) do @echo %f >> myfiles.avs
@echo ^"^"^" >> myfiles.avs


2. In your script - after installing AVSLib 1.1.0 (beta) of course - use (I assume script and myfiles.avs are in the same folder as above; else use absolute paths):

LoadLibrary("avslib", CONFIG_AVSLIB_FULL)

{{put your globals and the definition of function NewClip here}}

files = Import("myfiles.avs")
ArrayDelimiterSet(CRLF)

# cleanup invalid files
okflag = files.ArrayOpFunc("Exist").ArrayOpFunc("CInt")
files = files.ArrayReduce(okflag)

# import the clips
clips = files.ArrayOpFunc("DirectShowSource")
# apply NewClip
clips = ArrayOpArrayFunc(clips, files, "NewClip")
# join to source
source = clips.ArraySum()
return source


See the 5th (http://avslib.sourceforge.net/examples/example-005.html), 8th (http://avslib.sourceforge.net/examples/example-008.html) and 12th (http://avslib.sourceforge.net/examples/example-012.html) examples in AVSLib documentation for variations on this theme.

To process other files, such as .avi, just change the extension in the for %f... command and use AviSource instead of DirectShowSource.

mtamimi
26th June 2007, 01:08
Thanx for all the help...you explained all i wanted... :) :thanks::thanks: