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. |
16th October 2008, 19:37 | #1 | Link |
Registered User
Join Date: Jun 2007
Location: Washington, DC
Posts: 130
|
Trim and Empty Clip
I'm looking at the Replace() function that someone wrote, and I think there's a problem if you're trying to replace the very first part of a clip. Here's the function (from somewhere in this forum, or maybe in the wiki):
Code:
function Replace (clip old, clip inclip, int frame, int numframes) { numframes = ((numframes == 0) || (numframes > inclip.framecount)) ? inclip.framecount : numframes return old.Trim(0, frame - 1) + inclip.Trim(0, numframes) + old.Trim(frame + numframes, 0) } c.Replace(b, 0, 10) However, that would call old.Trim(0, -1), which returns the first frame (according to the documentation on the Trim() page. Part of the problem is that Trim() is overloaded -- if the second parameter is negative, then it means "framecount", so get 1 frame starting a frame zero. But what I want is zero frames. Because Avisynth doesn't have if statements, something like this can be confusing for all but expert script writers. But hopefully someone will point me in the right direction! Tac PS Yes, I realize that Replace starting with zero could be rewritten as an align without ever calling replace, but I still would like to know how to do it, so that if it's called programmatically the function works as expected. |
16th October 2008, 19:54 | #2 | Link |
Guest
Join Date: Jan 2002
Posts: 21,901
|
Code:
function Replace (clip old, clip inclip, int frame, int numframes) { numframes = ((numframes == 0) || (numframes > inclip.framecount)) ? inclip.framecount : numframes return (frame > 0) ? old.Trim(0, frame - 1) + inclip.Trim(0, numframes) + old.Trim(frame + numframes, 0) : \ inclip.Trim(0, numframes) + old.Trim(frame + numframes, 0) } |
16th October 2008, 19:57 | #3 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
tac, I don't know where you got that Replace function from, but it's rubbish. Not only does it fail to handle frame=0 correctly, it adds one frame more than it should.
For any question about function writing, your first port of call should be stickboy's functions. There you will find JDL_ReplaceRange and lots of other good stuff as well. If you want to see how to write functions well, spend a little while studying the code of all these functions. |
16th October 2008, 20:20 | #4 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Code:
function Replace (clip old, clip inclip, int frame, int numframes) { numframes = ((numframes == 0) || (numframes > inclip.framecount)) ? inclip.framecount : numframes return (frame > 0) ? old.Trim(0, -frame) + inclip.Trim(0, -numframes) + old.Trim(frame + numframes, 0) : \ inclip.Trim(0, -numframes) + old.Trim(frame + numframes, 0) } Last edited by Gavino; 16th October 2008 at 20:54. Reason: highlight changes |
|
16th October 2008, 22:50 | #5 | Link | |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
Quote:
It's much, much simpler to avoid trying to use Trim in functions like this. Use my Trim2/Trim3 functions instead. (See Caveats of using Trim in functions.) Last edited by stickboy; 16th October 2008 at 22:55. |
|
16th October 2008, 22:52 | #6 | Link |
Registered User
Join Date: Jun 2007
Location: Washington, DC
Posts: 130
|
More on Replacement
You're absolutely right, the first place to go is JDL's routines. The solution isn't simple, but he's provided it in JDL_ReplaceRange (which calls Trim2, which calls NullClip, both things I couldn't figure out how to handle in my original post).
I'd love to see more references to routines like this in the wiki, rather than just in the forums. Unfortunately, the capcha routine in the wiki is broken more often than not. My browser has been spinning for about 4 minutes trying to bring up an image, which is so cleverly convoluted that in the few times it's come up, I often don't type it correctly because I can't read it. I can't be the only one having this problem, and so I'm frustrated, not only because I can't add to the wiki, but because the wiki generally gets better with more contributions, and I'm sure I'm not the only one that's had something worthwhile to add but given up because the technology was in the way. Anyway, I'm both using the JDL routines now and learning a lot from them! Thx, Tac |
16th October 2008, 23:44 | #8 | Link | ||
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Quote:
|
||
17th October 2008, 01:01 | #9 | Link | |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
Quote:
I'm planning on pushing all the deprecated functions into a separate jdl-glue.avsi file, but I haven't gotten around to it yet. AviSynth development has slowed down, so there's a lot less need for keeping those backward-compatibility functions around. |
|
Tags |
trim |
|
|