View Single Post
Old 24th June 2010, 12:02   #476  |  Link
Terka
Registered User
 
Join Date: Jan 2005
Location: cz
Posts: 704
when someone is dealing with small 'unstable areas' (which you could see after using TGMC) you can try following:
put the green code between the bold original TGMC`s code.
functions GlobalMOCO and LUTDeCrawl are needed. I changed the LUTDeCrawl a litte by adding a global motion compensation line to it.
http://www.aquilinestudios.org/scrip...-20081003.avsi
the masking part is stolen from idontknow whos script.
Quote:
# apply sharpness limiting (SLmode 3|4), or has "draft" been requested?
stage3 = (draft==2) ? t .subtitle("Draft 2")
\ : (draft==1) ? t1 .subtitle("Draft 1")
\ : (SLmode==3) ? ( (SLrad<2) ? stage2.repair(edi,1) : stage2.repair(stage2.repair(edi,12),1) )
\ : (SLmode==4) ? stage2.mt_clamp(pmax,pmin,Sovs,Sovs,U=3,V=3)
\ : stage2

#LUtdecrawl
ythresh=25
cthresh=50
maxdiff=206
GrassDontDance=stage3.LUTDeCrawlGlobalMOCO(ythresh=ythresh,cthresh=cthresh,maxdiff=maxdiff)

#mask the static, use LUtdecrawl on static only
maskp1 = stage3.MMask(fvec1, kind=1, ysc=255).UtoY()
maskp2 = stage3.MMask(fvec2, kind=1).UtoY()
maskp3 = stage3.MMask(bvec1, kind=1, ysc=255).UtoY()
maskp4 = stage3.MMask(bvec2, kind=1).UtoY()
maskf = average(maskp1, 0.25, maskp2, 0.25, maskp3, 0.25, maskp4, 0.25).spline36resize(stage3.width, stage3.height)
stage3=Overlay (GrassDontDance,stage3, mask=maskf)





# "Lossless" stage
#==================
Quote:
function GlobalMOCO (clip clp, int "prev", int "next", int "subpixel", bool "matchfields", float "pixaspect", bool "info")
{
#input has to be ConvertToYV12()
#
prev = default( prev , 0 )
next = default( next , 1 )
subpixel = default( subpixel , 2 ) #quality of matching 0-2
matchfields = default( matchfields, True ) # xxx todo
pixaspect = default( pixaspect , 1.094 ) #PAL
info = default( info , false ) #PAL

# procedure ##############
mdata = DePanEstimate (clp) #motion data
depa = DePanInterleave(clp, data=mdata, matchfields =matchfields,prev=prev, next=next,pixaspect=pixaspect,subpixel=subpixel,info=info)
return (depa)
}
function LUTDeCrawlGlobalMOCO(clip input, int "ythresh", int "cthresh", int "maxdiff",
\ int "scnchg", bool "usemaxdiff", bool "mask") {

Assert(input.IsYV12(),"LUTDeCrawl: YV12 input only")

cthresh=default(cthresh,15)
ythresh=default(ythresh,10)
cthr=string(cthresh)
ythr=string(ythresh)
scnchg=default(scnchg,25)
sc=string(scnchg)
maxdiff=default(maxdiff,50)
md=string(maxdiff)
usemaxdiff=default(usemaxdiff,true)
org=input

tri=org.GlobalMOCO(1,1)
org_minus=org.Trim(0,-1)+org.Trim(0,org.framecount-1)
org_plus=org.Trim(1,0)+org.Trim(org.framecount,0)

org_minus=tri.selectevery(3,0)
org_plus=tri.selectevery(3,2)


org_y=org.Greyscale()
org_minus_y=org_minus.Greyscale()
org_minus_u=UToY(org_minus)
org_minus_v=VToY(org_minus)
org_plus_y=org_plus.Greyscale()
org_plus_u=UToY(org_plus)
org_plus_v=VToY(org_plus)

average_u=mt_lutxy(org_minus_u,org_plus_u,"x y - abs "+cthr+" < 255 0 ?")
average_v=mt_lutxy(org_minus_v,org_plus_v,"x y - abs "+cthr+" < 255 0 ?")
average_y=mt_lutxy(org_minus_y,org_plus_y,"x y - abs "+ythr+" < x y + 2 / 0 ?")

diffplus_y = mt_lutxy(org_plus_y, org, "x y - abs "+md+" < 255 0 ?")
diffminus_y = mt_lutxy(org_minus_y, org, "x y - abs "+md+" < 255 0 ?")
diffs_y = mt_logic(diffplus_y, diffminus_y, "and").Greyscale()

ymask=average_y.mt_Binarize(threshold=0,upper=false)
ymask=usemaxdiff ? mt_logic(ymask, diffs_y, "and") : ymask
cmask=mt_logic(average_u.mt_Binarize(upper=false),average_v.mt_Binarize(upper=false),"and")
cmask=cmask.PointResize(cmask.Width()*2, cmask.Height()*2)

themask=mt_logic(ymask,cmask,"and")

fixed_y=mt_lutxy(average_y,org_y,"x y + 2 /",y=3,u=2,v=2)

output=MergeChroma(mt_Merge(org_y,fixed_y,themask),org)
output=ConditionalFilter(org, org, output, "YDifferenceFromPrevious()", ">", sc)
output=ConditionalFilter(org, org, output, "YDifferenceToNext()", ">", sc)

return (default(mask,false)?themask: output)

}
you got more stable result, a little blurring in some affected areads, and about 4% better compressibilty on clips i have tested (for --crf 22)
speeddown or speedloss not tested.

Last edited by Terka; 24th June 2010 at 12:10. Reason: updated the code
Terka is offline   Reply With Quote