Log in

View Full Version : hows this for a deinterlacer?


actionman133
18th March 2004, 12:53
i've been curious about deinterlacing and inherent issues with it, and i decided to put my own one together in an avisynth script. it is designed to convert between the tv signals, but it can Bob the fields as well if you want it on the computer.

so heres the code:

Function PALtoNTSC (clip Last, bool Progressive, bool Weaving) {

IsPAL = ((Width == 720) && (Height == 576) && (Framerate == 25)) ? True : False
(IsPAL == False) ? Subtitle (Last, "Not PAL video!") : Last
((Progressive == True) && (IsPAL == True)) ? pPALtoNTSC (Weaving) : Last
((Progressive == False) && (IsPAL == True)) ? iPALtoNTSC (Weaving) : Last
}

Function pPALtoNTSC (clip Last, bool Weaving) {

LanczosResize (720, 480)
SeparateFields
SelectEvery (8, 0, 1, 2, 3, 2, 5, 4, 7, 6, 7)
AssumeFPS (59.94, True)
(Weaving == True) ? Weave : Bob

}

Function iPALtoNTSC (clip Last, bool Weaving) {

SeparateFields
LanczosResize (720, 240)
Bob
ConvertFPS (ConvertToYUY2, 60)
SeparateFields
SelectEvery (4, 1, 2)
AssumeFPS (59.94, True)
AssumeFieldBased
ComplementParity
(Weaving == True) ? Weave : Bob

}

Function NTSCtoPAL (clip Last, bool Progressive, int Offset, bool Weaving) {

IsNTSC = ((Width == 720) && (Height == 480) && (Ceil (Framerate) == 30)) ? True : False
(IsNTSC == False) ? Subtitle (Last, "Not NTSC video!") : Last
((Progressive == True) && (IsNTSC == True)) ? pNTSCtoPAL (Offset) : Last
((Progressive == False) && (IsNTSC == True)) ? iNTSCtoPAL (Weaving) : Last
}

Function pNTSCtoPAL (clip Last, int Offset) {

DoubleWeave
Pulldown (Offset, Offset + 3)
LanczosResize (720, 576)
AssumeFPS (25, True)

}

Function iNTSCtoPAL (clip Last, bool Weaving) {

SeparateFields
LanczosResize (720, 288)
Bob
AssumeFPS (60, True)
ConvertFPS (ConvertToYUY2, 50)
SeparateFields
SelectEvery (4, 1, 2)
AssumeFieldBased
ComplementParity
(Weaving == True) ? Weave : Bob

}


pPALtoNTSC (and pNTSCtoPAL) are meant to convert content from sources that were originally progressive, such as film. pPALtoNTSC is the fastest of all of these.

iPALtoNTSC (and iNTSCtoPAL) are meant to convert TV content. i know its slow but i am a quality freak. its motion remains quite fluid and it retains the field order, so i dont complain.

id like to see if anyone can optimize the code to make it a little faster, and if the central code can be improved, or made more efficient. im referring to:

IsPAL = ((Width == 720) && (Height == 576) && (Framerate == 25)) ? True : False
(IsPAL == False) ? Subtitle (Last, "Not PAL video!") : Last
((Progressive == True) && (IsPAL == True)) ? pPALtoNTSC (Weaving) : Last
((Progressive == False) && (IsPAL == True)) ? iPALtoNTSC (Weaving) : Last

thanks for any help guys.

Guest
19th March 2004, 03:20
Which function do I use for deinterlacing? :)

Suppose I have interlaced NTSC 30fps and I want progressive NTSC 30fps.

actionman133
19th March 2004, 13:23
perhaps i labelled it wrong. its more accurate to call it an ntsc<=>pal converter...

but to deinterlace video material (30i to 30p) is simple enough (with a decent source), so there's no reason to make a function out of it.

Guest
19th March 2004, 14:14
Gotcha. Thanks for the explanation.