Log in

View Full Version : script problem, bug or order of invokation?


esby
21st January 2004, 11:37
function dec(src) {
src = src.telecide()
src = src.decimate(cycle=5)
return src
}

function correctFPS1( clip src , int fl) {
src = src.changeFPS(src.Framecount()/fl*29.76)
src = src.assumeFPS(29.76)
src = dec(src)
src = src.assumeFPS(23.976)
return src
}

function correctFPS2( clip src , int fl) {
src = dec(src.trim(0,fl)).assumeFPS(23.976)
return src
}

function correctFPS( clip src , int fl ) {
src = (src.frameCount()<=fl) ? correctFPS1(src,fl) : correctFPS2(src,fl)
return src
}

clip = correctFPS(clip,165)



if clip>165 frames correctFPS call correctFPS2()
and it works correctly...

But when it comes to clip<=165 frames...
correctFPS1() returns a clip with 0 frame...

So is there an evaluation problem, or is it a bug?
or is it normal?
if i'm not wrong,
the line causing the problem is :
src = src.changeFPS(src.Framecount()/fl*29.76)
but src.framecount should be != 0
since it is evaluated correctly with clip>165 frames

so if anyone can help...

esby

Wilbert
21st January 2004, 11:46
But when it comes to clip<=165 frames...
correctFPS1() returns a clip with 0 frame...
What AviSynth version are you using? If you are using an old one, try this:

function correctFPS1( clip src , int fl) {
src = src.changeFPS(src.Framecount()*29.76/fl)
src = src.assumeFPS(29.76)
src = dec(src)
src = src.assumeFPS(23.976)
return src
}

esby
21st January 2004, 11:54
[more infos] ( could not edit my post )

function correctFPS1( clip src , int fl) {
fr = src.Framecount()/fl*29.76
return src.subtitle(String(fr))
}

fr is equal to 0 here...
but in
return src.subtitle(String(src.frameCount()))
frameCount != 0 ...

so that would means the variable are evaluated
before even the clips are? right?


@wilbert that seems fixing the problem indeed

correctFPS1() return the proper value if I inverse the order...

but i'm using avs 2.53 (11 nov 2003 build)

stickboy
22nd January 2004, 00:14
Originally posted by esby:
so that would means the variable are evaluated
before even the clips are? right?Not at all.

The problem with src.Framecount()/fl*29.76 is that:
src.FrameCount() returns an integer
fl is an integer
evaluation order for division and multiplication is left-to-right, so the division occurs before the multiplication (as of 2.53)
dividing an integer by another integer yields an integer quotient truncated toward zero. (e.g. 9/4 = 2, 1/3 = 0, -1/3 = 0)
Therefore, in the case when src.FrameCount() <= fl, the quotient is 0.

Wilbert's version avoids this problem. In src.Framecount()*29.76/fl, the multiplication occurs first. Since the multiplication involves an integer and a floating-point value, the product is also a floating-point value.

Float(src.Framecount())/fl*29.76 also should work.