View Single Post
Old 12th August 2003, 12:12   #7  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
I believe your math is a little off... if you remove every 196th frame, you'll remove 5 frames of every 800. (If you neglect to remove the fifth frame, one of the segments will not be a multiple of 4.)

I think it should be:
Code:
keep     telecine
   0     [  1, 200]
 201     [202, 401]
 402     [403, 602]
 603     [604, 799]
Anyhow, here's a function I whipped up that I believe does what you want (24 -> 29.97). I'm really sleepy, so the code is rather crude, isn't well-tested, and doesn't perform any error-checking:
Code:
function min(int m, int n)
{
    return (m < n) ? m : n
}


function Telecine(clip c)
{
    assert(c.IsFrameBased(), "Telecine: clip must be frame-based")

    # we need to handle the case of a null-clip manually;
    # otherwise, SelectEvery(...) will generate unwanted blank frames
    return (c.FrameCount() == 0)
    \      ? c.AssumeFPS(c.FrameRate() * 5.0 / 4.0)
    \      : c.ComplementParity().DoubleWeave().SelectEvery(8, 0, 2, 3, 5, 6)
}


function NewTelecineHelper(clip c, int iterLeft)
{
    assert(iterLeft > 0, "NewTelecineHelper: invalid <iterLeft> value")
    iterLeft = iterLeft - 1

    start = iterLeft * 800
    end = min(c.FrameCount(), (iterLeft + 1) * 800)

    seg = c.Trim2(start, length=800)

    seg1 = seg.Trim2(  0, length=1) + seg.Trim2(  1, 201).Telecine()
    seg2 = seg.Trim2(201, length=1) + seg.Trim2(202, 402).Telecine()
    seg3 = seg.Trim2(402, length=1) + seg.Trim2(403, 603).Telecine()
    seg4 = seg.Trim2(603, length=1) + seg.Trim2(604     ).Telecine()

    c = c.Trim2(0, start) + seg1 + seg2 + seg3 + seg4 + c.Trim2(end)

    return (iterLeft == 0)
    \      ? c
    \      : NewTelecineHelper(c, iterLeft)
}


function NewTelecine(clip c)
{
    assert(c.FrameCount() > 0, "NewTelecine: input clip must have at least one frame")
    c.NewTelecineHelper(Ceil(c.FrameCount() / 800.0)).AssumeFPS(29.97)
    return AudioDub(last, c)
}
(See also: Trim2)

Edit:
The code should no longer add blank frames to the end when the framecount of the input clip is not a multiple of 800.

Last edited by stickboy; 13th August 2003 at 09:54.
stickboy is offline   Reply With Quote