Cdeint

From Avisynth wiki
Revision as of 23:03, 19 May 2013 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Bad telecined sources with blended fields seems to be normal in my country. The possible solutions for this problems are really rare. For example matchbob or tdeint(mode=1, tryweave=true) with unblend and a decimater or the the great but totally complex function restore24. So I tried to create a alternative for restore24 and this is the result.

Discussion can be found here.

Function

function Cdeint(clip clp, clip "bob", int "bmode", float "nlv", float "hv") 
{
###### PREPARATION ######
global noisel = default(nlv,0)
global x = default(hv,0.9)

ord = clp.getparity() ? 1 : 0
tmpp = isyv12(clp) ? clp.leakkernelbob(order=ord, sharp=false, twoway=false, threshold=5).duplicateframe(0) : 
\	clp.leakkernelbob(order=ord, sharp=false, twoway=false, threshold=5).duplicateframe(0).ConvertToYV12()
one = tmpp.crop(8,8,-8,-8)
two = tmpp.crop(8,8,-8,-8).BilinearResize(640,352)
three = tmpp.crop(8,8,-8,-8).BilinearResize(352,192)

global testclip = (bmode==1 ? one : (bmode==3 ? three : two))


###### FRAMES FOR BLENDPARAMETERS ######
global combing_n0 = testclip.selecteven()
global combing_n1 = testclip.selectodd()
global combing_n2 = combing_n0.trim(1,0)
global combing_n3 = combing_n1.trim(1,0)

###### POSSIBLE OUTPUTS ######
out = bob.selecteven()
out_1 = bob.selectodd()

###### Conditional Function Chain, evaluated from bottom to top (!) ######
c99=ConditionalFilter(clp, out_1, out, "btest/Min(combl_0, combl_1)", "lessthan", "btest_2/Min(combl_1, combl_2)") 

c9=FrameEvaluate(c99, "global btest_2 = LumaDifference(blendmade_test, blendpic_test) - (0.8 * noisel)")
c8=FrameEvaluate(c9, "Evaluate_test()")
c7=FrameEvaluate(c8, "global blendl_test = combl_1 < combl_2 ? 0.5 * Exp(x * Log(combl_1 / combl_2)) :
	\	1 - 0.5 * Exp(x * Log(combl_2 / combl_1))")
c6=FrameEvaluate(c7, "global btest = LumaDifference(blendmade, blendpic) - (0.8 * noisel)")
c5=FrameEvaluate(c6, "Evaluate()")
c4=FrameEvaluate(c5, "global blendl = combl_0 < combl_1 ? 0.5 * Exp(x * Log(combl_0 / combl_1)) :
	\	1 - 0.5 * Exp(x * Log(combl_1 / combl_0))")
c3=FrameEvaluate(c4, "global combl_2 = LumaDifference(combing_n2, combing_n3) - noisel")		
c2=FrameEvaluate(c3, "global combl_1 = LumaDifference(combing_n1, combing_n2) - noisel")      
c1=FrameEvaluate(c2, "global combl_0 = LumaDifference(combing_n0, combing_n1) - noisel")      
return(c1) 
}


# (running inside of the Conditional Environment)

function Evaluate() 
{
vid = testclip.selecteven()
vid_1 = vid.trim(1,0)

global blendmade = MergeLuma(vid,vid_1,blendl)
global blendpic = testclip.selectodd()
}

function Evaluate_test() 
{
vid_2 = testclip.selectodd()
vid_3 = vid_2.trim(1,0)

global blendmade_test = MergeLuma(vid_2,vid_3,blendl_test)
global blendpic_test = testclip.selecteven().trim(1,0)
}

function Min(float a, float b)
{
temp = a < b ? a :b
return(temp)
}

Usage

LoadPlugin("C:\program_me\dgmpgdec\DGDecode.dll")
LoadPlugin("C:\program_me\filters\TIVTC.dll")
LoadPlugin("C:\program_me\filters\FDecimate.dll")
#LoadPlugin("C:\program_me\filters\TDeint.dll")
LoadPlugin("C:\program_me\filters\leakkerneldeint.dll")

#AVISource("D:\video\inu\[Ingow] Pirates Of Japan (Trailer).avi")
#OpenDMLSource("C:\Dokumente und Einstellungen\Benutzername\Eigene Dateien\Eigene Videos\film.avi")
#DirectShowSource("D:\video\inu\[Ingow] Pirates Of Japan (Trailer).avi")

MPEG2Source("D:\dvd.d2v",cpu=4)

#trim(0,0)

crop(8,8,-8,-8)

ord = last.getparity() ? 1 : 0
a = leakkernelbob(order=ord, sharp=true, twoway=true, threshold=7)
			

deint = Cdeint(bob=a, bmode=2, nlv=0)

tfm(order=-1, mode=0, cthresh=6, MI=64, display=false, mChroma=true, slow=false, pp=2, clip2=deint)

fdecimate(rate=23.976,threshold=1.0,metrics=false) 	# or another decimater
Personal tools