View Full Version : is trim adding a frame?
Naked Misty
17th April 2005, 17:41
Can someone please explain why this happens, is it a bug or just the way it is? Take this simple script as an example.
avisource=("c:\movie.avi")
trim(200,2200)
showframenumber
Simple right, 2200 - 200 = 2000 total frames. Why does this script show a total of 2001 frames when viewed in virtualdub. With the "showframenuber" showing 0 thru 2000 which is 2001 frames, when is should be showing 0 thru 1999 being the 2000 frames I wanted. Whats going on?
Wilbert
17th April 2005, 17:50
First your script should be
avisource("c:\movie.avi")
trim(200,2200)
showframenumber
second
Simple right, 2200 - 200 = 2000 total frames. Why does this script show a total of 2001 frames when viewed in virtualdub.
Because that script has 2001 frames, namely: 200, 201, ..., 2200 (see docs).
stickboy
17th April 2005, 19:49
Originally posted by Naked Misty
Simple right, 2200 - 200 = 2000 total frames.Nope. It's 2200 - 200 + 1 because Trim's endpoints are inclusive.
If you'd prefer to get the range [start, end) instead of [start, end], try my Trim2 function (especially if you're using Trim in your own user-defined functions (http://forum.doom9.org/showthread.php?s=&threadid=58358)).
Naked Misty
21st April 2005, 00:49
Thanks for the replies guys and to Wilbert for pointing out my typo in my script. It's still confusing and the reason I'm bringing this up is because as stickyboy mentioned I have been using it in a function.
function combofade( int "duration1", int "duration2" )
{
duration1 = default( duration1, 0 )
duration2 = default( duration2, 0 )
total = (trim2 - trim1) + 1
end = (total / 2)
round(end)
lenght = (total * 2)
start = (end + 1) + total
fadein1(duration1)+fadeout1(duration2)
equal = trim(0,end)+trim(start,lenght)
trim(0,end)+trim(start,lenght)
framecount == total ? equal : blackness.subtitle("error in combofade")
}
Note: line total, I have to add one frame so the frame numbers match the original clip and audio sync will be kept. I could be doing it the hard way but that's how I learned.
stickboy
21st April 2005, 06:41
You really should use Trim2 instead, for all the various reasons I explained in that thread.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.