View Full Version : Script functions with variable-length argument list?
mg262
2nd July 2005, 16:42
I find I'm writing this sort of thing:
Trim(0,6002) \
+Trim(6003 +294, 18499 +294) \
+Trim(18500 +512, 19480 +512) \
+Trim(19481 +669, 28567 +669) \
+Trim(28568 +763, 0)
a lot while dubbing, with half the parameters being redundant; it would be nice to be able to write
TrimSection(\
0, 0, \
6003, 294,\
18500, 512,\
19481, 669, \
28568, 763)
It would be preferable to do it in a script fn rather than a filter... does anyone know if there's a way of writing script functions taking a variable number of arguments? I've checked the docs + searched a bit + looked at @stickboy's list of script-creation aids but no luck...
I guess I could just add lots of parameters with default values, but that's messy and gets very errorprone very quickly.
Thanks,
M.
Richard Berg
2nd July 2005, 19:13
To me, even the 2nd form of script is a lot of manual labor, albeit less than the 1st. What editor are you using? VDubMod, for instance, will write the Trims for you.
mg262
2nd July 2005, 20:27
I'm generating the numbers using a filter (http://forum.doom9.org/showthread.php?t=95115). The pairs of values can be read off the visual output and text file (respectively) in that thread.What editor are you using?Notepad. ;)
I tend to stay away from the script editor in VirtualDubMod because I have a lot of VDM crashes. I know there AVSEdit and maybe other editors out there, but I've never found the time to look through them and see how they compare.VDubMod, for instance, will write the Trims for you.I didn't know that... thank you.
stax76
2nd July 2005, 21:16
Notepad. ;)
I tend to stay away from the script editor in VirtualDubMod because I have a lot of VDM crashes. I know there AVSEdit and maybe other editors out there, but I've never found the time to look through them and see how they compare.
how does a car compare to walking by foot ;)
obviously it takes time learning driving a car and when the car is broke it needs to be fixed
VDubMod, for instance, will write the Trims for you.
I didn't know that... thank you.
so does AVSEdit, like lot's of many other useful things
mg262
2nd July 2005, 21:46
how does a car compare to walking by foot ;)I meant how they compare to each other. Not to Notepad -- that would be offensive! Sorry if I gave that impression.
When I start using a particular kind of tool I tend to spend a while finding all the alternatives, reading about them, assimilating information, etc. before settling on one -- and that takes a fair bit of effort. (And if I were stupid enough to ask "what's the best AviSynth Editor", something like this would turn up on my doorstep... :devil: :angry: :devil:.) So it's a bit like having to wade through car magazines :p .
(I'm probably also a bit jaded because I wasted time fighting with several HTML editors before reverting to notepad...) Plus in this case I know v3.0 will add extra support, so it seemed the sensible time to do it. No offense intended -- and I hope none taken.
stax76
2nd July 2005, 22:20
I've tested probably thousands of applications, I've even started a thread here what applications people use to learn about new applications:
http://forum.doom9.org/showthread.php?t=88815&highlight=applications
I'm using AVSEdit and for normal text EmEditor, if I had to use a free editor maybe I would use notepad2 (http://www.flos-freeware.ch/notepad2.html). For HTML I use Dreamweaver and Namo WebEditor
stickboy
3rd July 2005, 00:25
It would be preferable to do it in a script fn rather than a filter... does anyone know if there's a way of writing script functions taking a variable number of arguments? I've checked the docs + searched a bit + looked at @stickboy's list of script-creation aids but no luck...There's no direct way. The best you can do is to put all your arguments into a string and then have your script function parse it. See my strings as a poor-man's array (http://forum.doom9.org/showthread.php?p=367841#post367841) post if you're really interested, but I doubt it's worthwhile in your case.
(BTW, shouldn't you be using ++ instead of +?)
Another alternative is to make a program that generates an AviSynth script for you with the appropriate Trim() calls, but I suppose it's not much less effort than making a plug-in that does it.
mg262
3rd July 2005, 01:18
(BTW, shouldn't you be using ++ instead of +?)I'm just about to dub it, so it doesn't make much difference. But thank you for pointing it out. Another alternative is to make a program that generates an AviSynth script for you with the appropriate Trim() calls, but I suppose it's not much less effort than making a plug-in that does it.The main point wasn't really the amount of work involved... it was wanting to be able to read/verify what was happening more easily -- I'm likely to have to put down these scripts and come back to them much later. Plus duplicating all the numbers increased the probability of a silly error. Similarly, the reason I wanted to use a script rather than a filter was that it would be easier to check that there were no silly bugs in it.
gzarkadas
27th September 2005, 17:45
Below is a solution to the problem mentioned (of course for the next time, since I respond well after this conversation has came to an end).
In order for this to work, the 1.0.0 version of the AVSLib distribution (http://sourceforge.net/projects/avslib/) must be installed in your machine, in order to be able to work with arrays (http://avslib.sourceforge.net/modules/array.html) and also use the referenced editing functions (http://avslib.sourceforge.net/modules/edit.html).
You will have to include in your script an Import statement to the AVSLib header file (details are provided in the documentation) and the following function (which I will incorporate in AVSLib in a following version):
Function __edit_dotrim(int fs, int fe, clip c) { return c.EditTrim (http://avslib.sourceforge.net/functions/e.html#EditTrim)(fs, fe) }
# trims a number of ranges of frames [fs..fe) and returns them as a single clip.
# joining is performed by EditJoin, supporting all of its features
Function EditTrimRange(clip c, string fs, val "fe", int "op", string "extra_info") {
# if fe is not supplied extract one frame from each range (ie the frames supplied in fs)
fe = Default(fe, 1)
op = Default(op, EDOP_ADD)
extra_info = Default(extra_info, "")
# if fe is a scalar value assume it is the number of frames to extract from each range, starting from fs
_fe = fe.IsString ? fe : fs.ArrayOpValue (http://avslib.sourceforge.net/functions/a.html#ArrayOpValue)(fe, "+")
# 1st global is needed for ArrayOpArrayFunc
# 2nd global is needed because ArraySum chokes when strings with keyword arguments
# that contain strings are passed in (Eval cannot handle them correctly)
global __edit_tr_tmp = c
global __edit_tr_xti = extra_info
parts = ArrayOpArrayFunc (http://avslib.sourceforge.net/functions/a.html#ArrayOpArrayFunc)(fs, _fe, "__edit_dotrim", "__edit_tr_tmp")
# free global copy of c to reclaim memory
global __edit_tr_tmp = Null(c)
return parts.ArraySum (http://avslib.sourceforge.net/functions/a.html#ArraySum)(sum_func="EditJoin (http://avslib.sourceforge.net/functions/e.html#EditJoin)", sum_args="op=" + String(op) + \
(extra_info == "" ? "" : ",extra_info=__edit_tr_xti") )
}
At the main body of the script you will import your video (in the example I created a test clip like this):
c = BlankClip(length=20000).ShowFrameNumber(scroll=true)
And then you will define an array of integers, either hard-coded as the example below
fse = "120,200, 490,520, 740,760, 1140,1200, 1500,1570, 3400,3450, 6980,7020"
or using ArrayCreate (http://avslib.sourceforge.net/functions/a.html#ArrayCreate) or any other of the array creation functions.
If you, like me, prefer to see start and end frame numbers together as pairs then put numbers as start[0],end[0], start[1],end[1], etc. in a single array and then use ArrayDeplex (http://avslib.sourceforge.net/functions/a.html#ArrayDeplex) as in the line below to break pairs in separate arrays.
Else create two separate arrays one with start and one with end frame numbers and pass them to the function.
This line does the actual job returning the trimmed ranges as a single clip. I have added some spice asking from the function to join parts using Dissolve with an overlap of 5 frames.
return c.EditTrimRange(fse.ArrayDeplex (http://avslib.sourceforge.net/functions/a.html#ArrayDeplex)(0,2), fse.ArrayDeplex(1,2), EDOP_DISS, "5")
If I wanted a plain join I would have simply specified the line below (plain join is the default behavior)
return c.EditTrimRange(fse.ArrayDeplex(0,2), fse.ArrayDeplex(1,2))
One thing that must be pointed out is that the frame that corresponds to the end frame number in each range is not included, ie the function trims ranges as [fs..fe).
Hope it was helpful.
------------
Note that the example code is provided under the terms of the GNU General Public Licence, version 2.0 or later.
mg262
27th September 2005, 17:53
@gzarkadas,
Thank you for the reply. I ended up throwing together a plug-in to do it (which I don't think I ever released because of the lack of interest (http://forum.doom9.org/showthread.php?t=97445&highlight=dubbing) in dubbing tools). But, the library looks very interesting! Hope to see more of it (and you) around here.
gzarkadas
27th September 2005, 21:57
@mg262,
Thanks for the good words.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.