#------------------------------------------------------------------#
# #
# QuickTGMC 1.0, by Vitreous, 2010 #
# #
# Deinterlacer using motion-compensated temporal gaussian blurring #
# Substitute for TGMC designed for speed. #
# #
#------------------------------------------------------------------#
#
# Version History:
# v1.0: Released
# Requires (first three are needed for TGMC already):
# MVTools
# RemoveGrain
# MaskTools V2
# Choice of: NNEDI2 or TDeInt+Yadif
# Sharpness (0.0 ...) : How much to resharpen the temporally gaussian blurred clip
# EdiMode (0,1) : Mode used for interpolation, 0 = NNEDI2, 1 = combined TDeInt/Yadif
# Blocksize (4,8,16,32) : Block size for motion compensation
# Overlap (< Blocksize) : How much to overlap blocks for motion compensation
# SubPel (1,2,4) : Sub-pixel accuracy (1 = 1 pixel, 2 = 1/2 pixel, 4 = 1/4 pixel)
# To use EdiMode=1 (TDeInt/Yadif) you must update LoadCPlugin line below to point to your plugin path
function QuickTGMC( clip Input, float "Sharpness", int "EdiMode", int "BlockSize", int "Overlap", int "SubPel" )
{
Sharpness = default( Sharpness, 0.5 )
EdiMode = default( EdiMode, 0 )
BlockSize = default( BlockSize, 32 )
Overlap = default( Overlap, Blocksize / 4 )
SubPel = default( SubPel, 2 )
_lambda = (100*BlockSize*BlockSize)/(8*8)
_lSAD = 400
_pNew = 25
#**** UPDATE THIS PATH TO SUIT YOUR MACHINE IF USING EdiMode=1****#
LoadCPlugin( "C:\Program Files\AviSynth 2.5\plugins\yadif.dll" )
dbob = Input.bob( 0, 0.5 )
edi = (EdiMode == 0) ? Input.nnedi2(-2) : merge( Input.Yadif(1), Input.TDeInt(1) )
srchClip = dbob.temporalsoften( 1, 255, 255, 28, 2 ).merge( dbob, 0.25 )
srchSuper = srchClip.MSuper( pel=SubPel, sharp=2 )
bVec = srchSuper.MAnalyse( isb=true, blksize=BlockSize, overlap=Overlap, truemotion=false, global=true, lambda=_lambda, lsad=_lSAD, pnew=_pNew )
fVec = srchSuper.MAnalyse( isb=false, blksize=BlockSize, overlap=Overlap, truemotion=false, global=true, lambda=_lambda, lsad=_lSAD, pnew=_pNew )
ediSuper = edi.MSuper( pel=SubPel, sharp=2, levels=1 )
mdegrain = edi.MDegrain1( ediSuper, bvec, fvec, thSAD=5*8*8, thSCD1=180, thSCD2=98 )
tgmc = mdegrain.merge( edi, 0.25 )
return tgmc.mt_lutxy( tgmc.removegrain(11),"x x y - "+ string(sharpness) + " * +", U=3,V=3 )
}