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. |
27th July 2003, 09:04 | #1 | Link |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
Caveats of using Trim in functions
I was looking through some of the shared functions, and I saw a few cases where Trim isn't used very carefully. IMO, Trim's syntax--intended for editing convenience--is tricky to use robustly for general-purpose, user-defined functions.
For example, let's say we wanted to write our own version of ApplyRange. Here's the naive approach: Code:
# ApplyRange2 # # A version of ApplyRange that works with Avisynth 2.0x and that allows # named arguments and filters that take no arguments. # # USAGE: # c.ApplyRange2(123, 456, "Tweak(sat=1.1)") # function ApplyRange2(clip c, int start, int end, string thunk) { # NOTE: this version isn't very safe! seg1 = c.Trim(0, start - 1) seg2 = c.Trim(start, end) # filter will be applied to frames in the # range [start, end] seg3 = c.Trim(end + 1, 0) seg2 = Eval("seg2." + thunk) return seg1 + seg2 + seg3 }
(I'm not sure why, but c.Trim(c.FrameCount() + N, 0) returns the last frame of c instead of an error or instead of a 0-frame clip.) Okay, so what can we do? We can simplify Trim a lot by:
[Edit: code moved to <http://www.avisynth.org/stickboy/>] Now we safely can define ApplyRange2 as: Code:
function ApplyRange2(clip c, int start, int end, string thunk) { seg1 = c.Trim2(0, start) seg2 = c.Trim2(start, end + 1) # filter will be applied to frames in the # range [start, end] seg3 = c.Trim2(end + 1) seg2 = Eval("seg2." + thunk) return seg1 + seg2 + seg3 } Greatly relaxed the bounds-checking for Trim2; now allows start/end values that go past the end of the clip. Edit: (2003-08-20): Oops, I broke Trim2's support for negative values of end. Should be fixed now, hopefully without breaking anything else. Last edited by stickboy; 27th November 2003 at 01:47. |
10th January 2007, 22:21 | #2 | Link |
Registered User
Join Date: Mar 2005
Posts: 468
|
I'm having some trouble with your JDL_ApplyRange function. First, I'd like to thank you for making it in the first place, because it is needed due to the named parameters taken by hdragc().
The problem is my script has two lines, like this: JDL_ApplyRange(0,710,"hdragc(coef_gain=1.5,freezer=1)") JDL_ApplyRange(1410,180975,"hdragc(coef_gain=1.5,freezer=1)") The area between frames 710-1410 is where I don't want the hdragc() filter to be active. However, when I open this script, the first section (0-710) works as expected, and of course the hdragc() filter doesn't work in 710-1409, but it doesn't show up in 1410+ either. When I comment # the first line, the hdragc() function then activates for frames 1410+ Can you help me figure out what's going on here? Thanks. |
10th January 2007, 22:34 | #3 | Link |
Registered User
Join Date: Mar 2005
Posts: 468
|
After some experimentation, I've found a way to make it work... all JDL_ApplyRange() lines must be in reverse frame order:
JDL_ApplyRange(1410,180975,"hdragc(coef_gain=1.5,freezer=1)") JDL_ApplyRange(0,710,"hdragc(coef_gain=1.5,freezer=1)") This arrangement works fine... I wonder why the former doesn't? |
14th January 2007, 11:23 | #4 | Link |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
Hm, that doesn't make any sense.
I'm not familiar with hdragc, but maybe there's a bug in that filter that affects its behavior when called multiple times. Does it happen with other filters? Does the following work? Code:
a = hdragc(coef_gain=1.5, freezer=1) b = hdragc(coef_gain=1.5, freezer=1) c1 = a.Trim(0, 710) c2 = Trim(711, 1409) c3 = b.Trim(1410, 180975) c4 = Trim(180976, 0) c1 + c2 + c3 + c4 Code:
c1 = Trim(0, 710).hdragc(coef_gain=1.5, freezer=1) c2 = Trim(711, 1409) c3 = Trim(1410, 180975).hdragc(coef_gain=1.5, freezer=1) c4 = Trim(180976, 0) c1 + c2 + c3 + c4 Last edited by stickboy; 14th January 2007 at 11:25. |
Thread Tools | Search this Thread |
Display Modes | |
|
|