Code: Select all
 
 ####################################################################################################################
#                                                                                                                                                                                                       
#  ~HQDegrain v0.9 by Alek93j~   19/06/2011                                                                                                                                           
#                                                                                                                                                                                                        
# Required MVtools2.dll    http://avisynth.org.ru/mvtools/mvtools2.html                                                                                                                           
#       ttempsmooth.dll    http://avisynth.org.ru/docs/english/externalfilters/ttempSmooth.htm                           
#   mt_masktools-25.dll    http://manao4.free.fr/masktools-v2.0a48.zip
#   blockbuster.dll   http://kvcd.net/sansgrip/avisynth/                                   
#                                                                                                          ~Syntax~ 
#                                                                                                                  
 #################################################################################################################### 
#                                                                                                                   
# # It doesn't work perfectely with sudden luma changes such as flashes and fades, so it                            
# # is best not to filter those parts.                                                                              
#                                                                                                                  
# -Example of a Backup of a NTSC DvD-                                                                             
#                                                                                                                   
# MPEG2Source("C:\blabla.d2v")                                                                                    
# ivtc() (your prefer ivtc ectr)                                                                                 
# A=hqdegrain() (Clip normally processed)                                                                            
# B=ttempsmoothf(maxr=7,strength=5,lthresh=3,cthresh=4) (or your prefer denoise for clean fade)                 
# B.Trim(0,215)+A.Trim(216,31464)                                                                                
#                                                                                                                  
 ####################################################################################################################
Function HQDegrain(clip clp,int"Degrain",int"limit",bool"HQ",\
                   int"maxr",int"strength",int"lthresh",int"cthresh",\
                   clip"PreNoise",int"BkSize",bool"noise",\
                   int"Blk",int"PEL",int"DCT",int"Overlap",\
                   int "thSAD", int "thSADC",int "thSCD1", int "thSCD2")
{
#MDegrain Strength
Degrain = Default( Degrain , 2     ) # Means how many frame should be analyzed for a better result, 3 doesn't help much.
limit   = Default( limit   , 255   ) # limit of mvdegrain. (255 mean no limits)
#ttempsmoothf Strength
HQ      = Default( HQ      , true  ) # Repair artefact.
maxr    = Default( maxr    , 5     )
strength= Default( strength, 4     )
lthresh = Default( lthresh , 3     )
cthresh = Default( cthresh , 4     )
#Noise Filter
Noise   = Default( Noise   , true  )
BkSize  = Default( BkSize  , 8     )
#Motion Vector Analyse
Blk     = Default( Blk     , 8     ) # Use 16/for 1080p - 8/for 720p - 4/for 480p to avoid unnecessary slowdowns.
PEL     = Default( PEL     , 2     )
DCT     = Default( DCT     , 0     )
OPS     = Blk/2
Overlap = Default( Overlap , OPS   ) 
#Threshold Setting
thSAD   = Default( thSAD   , 180   ) # Lower values will reduce artefacts for bad motion vectors, but they will also have a lighter denoising effect. For animated sources, 120 seems to be a good setting to start with.
thSADC  = Default( thSADC  , thSAD )
thSCD1  = Default( thSCD1  , 400   )
thSCD2  = Default( thSCD2  , 102   )
#Processing
input = clp
clp = defined(PreNoise) ? PreNoise 
       \: (Noise==true) ? clp.blockbuster(method="noise",Block_size=BkSize) : clp
sup = clp.Msuper(hpad=Blk,vpad=Blk,PEL=PEL,levels=0)
sup2= clp.Msuper(hpad=Blk,vpad=Blk,PEL=PEL,levels=1)
BV1 = MAnalyse(sup,isb = true , truemotion=true,delta=1,blksize=Blk,blksizeV=Blk,DCT=DCT,overlap=Overlap)
FV1 = MAnalyse(sup,isb = false, truemotion=true,delta=1,blksize=Blk,blksizeV=Blk,DCT=DCT,overlap=Overlap)
BV2 = (Degrain>=2) ? MAnalyse(sup,isb = true , truemotion=true,delta=2,blksize=Blk,blksizeV=Blk,DCT=DCT,overlap=Overlap) : Blackness () 
FV2 = (Degrain>=2) ? MAnalyse(sup,isb = false, truemotion=true,delta=2,blksize=Blk,blksizeV=Blk,DCT=DCT,overlap=Overlap) : Blackness () 
BV3 = (Degrain==3) ? MAnalyse(sup,isb = true , truemotion=true,delta=3,blksize=Blk,blksizeV=Blk,DCT=DCT,overlap=Overlap) : Blackness () 
FV3 = (Degrain==3) ? MAnalyse(sup,isb = false, truemotion=true,delta=3,blksize=Blk,blksizeV=Blk,DCT=DCT,overlap=Overlap) : Blackness () 
clp = (degrain==1) ? clp.MDegrain1(sup2, BV1, FV1,                     thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit): 
 \    (degrain==2) ? clp.MDegrain2(sup2, BV1, FV1, BV2, FV2,           thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit):
 \                   clp.MDegrain3(sup2, BV1, FV1, BV2, FV2, BV3, FV3, thSAD=thSAD, thSADC=thSADC, thSCD1=thSCD1, thSCD2=thSCD2, limit=limit)
Diff1 = mt_makediff(input,clp)
clp2  = clp.ttempsmoothf(maxr=maxr,strength=strength,lthresh=lthresh,cthresh=cthresh)
Diff2 = mt_makediff(input,clp2)
lutxy = mt_lutxy(Diff1,Diff2,"x 128 - abs y 128 - abs < x y ?")
output = (HQ==true) ? Input.mt_makediff(lutxy,U=2,V=2) : clp2
output }




hqdegrain()




good work and crf 14 for overkill quality \ò/



