Thread: Vapoursynth
View Single Post
Old 15th January 2023, 08:55   #4776  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,277
Trying to port CQTGMC to Vapoursynth, I started with:
Code:
def CQTGMC(clip: vs.VideoNode, Sharpness: float=0.25, thSAD1: int=192, thSAD2: int=320, thSAD3: int=128, thSAD4: int=320) -> vs.VideoNode:
  
  flip = core.std.FlipHorizontal(clip)
  flip = Padding(clip=clip,top=clip.width%64)
  flip = Padding(clip=clip,right=clip.height%64)
  padded = core.std.StackHorizontal([clip,flip])
  # todo: optional use nnedi3CL
  bobbed = core.znedi3.nnedi3(clip=padded, field=2)
  denoised = core.rgvs.RemoveGrain(clip=bobbed,mode=12)
  denoised = core.fmtc.resample(clip=denoised, kernel="gauss", w=denoised.width, h=denoised.height, scaleh=denoised.width+0.0001, interlaced=False, interlacedd=False)
  denoised = core.resize.Bicubic(clip=denoised, format=bobbed.format, dither_type="error_diffusion") # adjust format after fmtc
  denoised = core.std.Merge(clipa=denoised, clipb=bobbed,weight=0.25)
  
  srchClip = denoised
  csuper = core.mv.Super(clip=denoised);
  bvec = core.mv.Analyse(csuper,isb=True,blksize=64,overlap=32)
  fvec = core.mv.Analyse(csuper,isb=False,blksize=64,overlap=32)
  Comp1 = core.mv.Compensate(denoised,csuper,bvec,thsad=thSAD2)
  Comp2 = core.mv.Compensate(denoised,csuper,fvec,thsad=thSAD2)
  denoised = core.std.Interleave([Comp1,denoised,Comp2])
  csuper = core.vs.Super(clip=denoised)
  bvec = core.mv.Analyse(csuper,isb=True,blksize=64,overlap=32)
  fvec = core.Analyse(csuper,isb=False,blksize=64,overlap=32)
  Inter = core.mv.FlowInter(csuper,bvec,fvec,blend=False)
#   global CQTGMC_A = Inter.SelectEvery(3,0)
#   global CQTGMC_B = Inter.SelectEvery(3,1)
#   srchClip
#   ScriptClip("""
#   P = YDifferenceFromPrevious()
#   N = Trim(1,0).YDifferenceFromPrevious()
#   N < P ? CQTGMC_A : CQTGMC_B 
#   """)
#   super = MSuper()
#   bVec1 = MAnalyse(super,isb=true,overlap=4,delta=1)
#   fVec1 = MAnalyse(super,isb=false,overlap=4,delta=1)
#   bobbed 
#   super = MSuper(levels=1)
#   bComp1 = MCompensate(super,bVec1,thSAD=thSAD3)
#   fComp1 = MCompensate(super,fVec1,thSAD=thSAD3)
#   Interleave(\
#   SeparateFields(bobbed).SelectEvery(4,0),\
#   SeparateFields(fComp1).SelectEvery(4,1),\
#   SeparateFields(bComp1).SelectEvery(4,2),\
#   SeparateFields(bobbed).SelectEvery(4,3))
#   Weave()
#   #   super = MSuper(levels=1)
#   bComp1 = MCompensate(super, bVec1,thSAD=thSAD4)
#   fComp1 = MCompensate(super, fVec1,thSAD=thSAD4)
#   tMax = mt_logic(fComp1,"max",U=3,V=3).mt_logic(bComp1,"max",U=3,V=3)
#   tMin = mt_logic(fComp1,"min",U=3,V=3).mt_logic(bComp1,"min",U=3,V=3)
#   MDegrain1(super,bVec1,fVec1,thSAD=thSAD1)
#   sharpen = mt_adddiff(mt_makediff(Removegrain(20),u=3,v=3),u=3,v=3)
#   mt_clamp(sharpen,tMax,tMin,Sharpness,Sharpness,3,3,3)
#   super = MSuper(levels=1)
#   MDegrain1(super,bVec1,fVec1,thSAD=thSAD1)
#   Crop(0,0,-(input.width()%64),-(input.height()%64))
#   return last
  
# from havsfunc
def Padding(clip: vs.VideoNode, left: int = 0, right: int = 0, top: int = 0, bottom: int = 0) -> vs.VideoNode:
    if not isinstance(clip, vs.VideoNode):
        raise vs.Error('Padding: this is not a clip')

    if left < 0 or right < 0 or top < 0 or bottom < 0:
        raise vs.Error('Padding: border size to pad must not be negative')

    width = clip.width + left + right
    height = clip.height + top + bottom

    return clip.resize.Point(width, height, src_left=-left, src_top=-top, src_width=width, src_height=height)
but now I'm stuck.
Can someone tell me how to convert this part:
Code:
global CQTGMC_A = Inter.SelectEvery(3,0)
    global CQTGMC_B = Inter.SelectEvery(3,1)
    srchClip
    ScriptClip("""
    P = YDifferenceFromPrevious()
    N = Trim(1,0).YDifferenceFromPrevious()
    N < P ? CQTGMC_A : CQTGMC_B 
    """)
to Vapoursynth?

Thanks!

Cu
Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote