Esempio n. 1
0
    def main(self: Filtering) -> vs.VideoNode:  # noqa
        """Vapoursynth filtering"""
        src = WEB.clip_cut
        src = src.std.AssumeFPS(src)


        src = depth(src, 16)
        out = src


        denoise = hvf.SMDegrain(out, tr=1, thSAD=100, thSADC=100)
        out = denoise


        dering = hvf.EdgeCleaner(out, 15, smode=1, hot=True)
        dering = gf.MaskedDHA(dering, darkstr=0.05, brightstr=0.75)
        out = dering


        aaa = vdf.scale.nnedi3_upscale(get_y(out), pscrn=1, correct_shift=False)
        aaa = aaa.resize.Bicubic(1920, 1080, src_left=0.5, src_top=0.5, filter_param_a=-0.5, filter_param_b=0.25)
        out = vdf.misc.merge_chroma(aaa, out)


        cwarp = xvs.WarpFixChromaBlend(out, 64, depth=4)
        out = cwarp


        detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1200)
        deband = vdf.deband.dumb3kdb(out, 16, threshold=33, grain=[24, 0])
        deband = core.std.MaskedMerge(deband, out, detail_mask)
        out = deband


        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])[:100]
Esempio n. 2
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src



    ref = hvf.SMDegrain(out, thSAD=300)
    denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref)
    out = denoise

    crop = core.std.Crop(out, left=12)
    crop = awf.bbmod(crop, left=2, thresh=20 << 8)
    resize = core.resize.Bicubic(crop, 1920)
    out = lvf.rfs(out, resize, [(78, 89)])


    y = get_y(out)
    lineart = gf.EdgeDetect(y, 'scharr').morpho.Dilate(2, 2).std.Inflate()

    fkrescale = fake_rescale(
        y, 882, 0, 1,
        deringer=lambda x: gf.MaskedDHA(x, rx=1.85, ry=1.85, darkstr=0.25, brightstr=1.0, maskpull=100, maskpush=200),
        antialiser=lambda c: lvf.sraa(c, 2, 13, downscaler=core.resize.Bicubic)
    )
    merged = core.std.MaskedMerge(y, fkrescale, lineart)
    out = vdf.merge_chroma(merged, out)


    dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True)
    out = dering


    out = lvf.rfs(
        out, denoise,
        [(0, 11), (38, 77), (115, 133), (316, 395), (441, 460), (606, 779), (825, 844), (990, 1127)]
    )




    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000)
    deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband




    grain = adptvgrnMod(out, 0.3, static=True, grain_chroma=False, hi=[128, 240], seed=333)
    out = grain


    decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8)
    out = decz



    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
Esempio n. 3
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from ccd import ccd
    from vsutil import depth

    src = JP_BD.clip_cut
    cloc = core.resize.Bicubic(src, chromaloc_in=2, chromaloc=0)
    src = depth(cloc, 16)

    halo_mask = lvf.mask.halo_mask(src, rad=1, brz=0.85, thmi=0.35, thma=0.95)
    halo_mask = halo_mask.std.Maximum().std.Inflate()

    bidehalo = lvf.dehalo.bidehalo(src,
                                   sigmaR=8 / 255,
                                   sigmaS=2.0,
                                   sigmaS_final=1.5)
    dehalo_den = core.dfttest.DFTTest(bidehalo, sigma=8.0)
    dehalo_clean = haf.EdgeCleaner(dehalo_den, strength=8, smode=1, hot=True)

    dehalo = core.std.MaskedMerge(src, dehalo_clean, halo_mask)

    # Certain cuts have a strong camera effect that amplifies haloing, and is likely intentional
    dehalo = lvf.rfs(dehalo, src, [(773, 786), (867, 886)])

    denoise = core.dfttest.DFTTest(dehalo, sigma=1.75)
    cdenoise = ccd(denoise, threshold=4, matrix='709')
    decs = vdf.noise.decsiz(cdenoise,
                            sigmaS=8.0,
                            min_in=208 << 8,
                            max_in=232 << 8)

    baa = lvf.aa.based_aa(decs, str(shader_file))
    sraa = lvf.sraa(decs, rfactor=1.45)
    clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.45)

    darken = haf.FastLineDarkenMOD(clmp, strength=12)

    # Debanding and graining
    deband = flt.masked_f3kdb(darken, rad=18, thr=[24, 20])

    grain = vdf.noise.Graigasm(thrs=[x << 8 for x in (32, 80, 128, 176)],
                               strengths=[(0.20, 0.0), (0.15, 0.0),
                                          (0.10, 0.0), (0.0, 0.0)],
                               sizes=(1.20, 1.15, 1.10, 1),
                               sharps=(70, 60, 50, 50),
                               grainers=[
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True),
                                   vdf.noise.AddGrain(seed=69420,
                                                      constant=True)
                               ]).graining(deband)

    return grain
Esempio n. 4
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_clip
    src = depth(src, 16)

    cleanedge = hvf.EdgeCleaner(src, 15, rmode=1, smode=1, hot=True)
    out = cleanedge

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2250,
                                          brz_b=1500).std.Median()
    deband = dbs.f3kpf(out, 17, 30, 30)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband

    freeze = core.std.FreezeFrames(out, 120, src.num_frames - 1, 120)
    out = freeze

    return depth(out, 10)
Esempio n. 5
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src



    ref = hvf.SMDegrain(out, thSAD=300)
    denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref)
    out = denoise



    dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True)
    out = dering


    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000)
    deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband




    grain = adptvgrnMod(out, 0.3, static=True, grain_chroma=False, hi=[128, 240], seed=333)
    out = grain


    decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8)
    out = decz



    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
Esempio n. 6
0
File: XC.py Progetto: po5/encoderino
from vapoursynth import core, YUV444P8, YUV420P8
from rekt import rektlvls
import havsfunc as haf
import awsmfunc as awf
import lvsfunc as lvf
import G41Fun

guilstein = core.d2v.Source("Guilstein/VTS_01_1.d2v")[:163645]
guilstein = guilstein.decross.DeCross().dedot.Dedot().resize.Bicubic(format=YUV444P8, matrix_s="170m")
topline = guilstein.vinverse.Vinverse().std.Crop(top=63, bottom=70, left=6, right=6).std.CropAbs(top=1, width=guilstein.width-12, height=2)
guilstein = core.std.MaskedMerge(guilstein.vinverse.Vinverse().std.Crop(top=66, left=6, right=6), guilstein.std.Crop(top=66, left=6, right=6).nnedi3.nnedi3(1), guilstein.std.Crop(top=66, left=6, right=6).comb.CombMask().morpho.Dilate())
guilstein = guilstein.std.Crop(bottom=70)
guilstein = core.std.StackVertical([topline, guilstein])

guilstein = rektlvls(guilstein, rownum=[0, 1], rowval=[50, 10], colnum=[0, 1, 2, 3, 4], colval=[14, 10, 9, -3, -2], prot_val=[16, 235])
guilstein = awf.bbmod(guilstein, right=4, thresh=7, blur=16)
guilstein = core.std.Expr([guilstein, awf.bbmod(guilstein, bottom=3, thresh=2, blur=16)], "x y > x y ?")
guilstein = core.std.Expr([guilstein, awf.bbmod(guilstein, left=8, thresh=1, blur=8)], "x y > x y ?")
guilstein = lvf.aa.upscaled_sraa(guilstein, rfactor=2.0)
guilstein = guilstein.dfttest.DFTTest(sigma=2.0)
guilstein = guilstein.f3kdb.Deband(range=30, grainy=2, grainc=2)
guilstein = G41Fun.MaskedDHA(guilstein, rx=1.6, ry=1.6, darkstr=0.0, brightstr=0.6, lowsens=120, highsens=10)
guilstein = haf.EdgeCleaner(guilstein, strength=10)

guilstein = guilstein.resize.Bicubic(format=YUV420P8, matrix_s="170m")
guilstein = guilstein.std.FreezeFrames(first=[110471], last=[110483], replacement=[110470])

guilstein.set_output()
Esempio n. 7
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut

        # Dehardsubbing using .ass file
        masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR)
        dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
        src_web = dehardsub

        # AoD is poorly rescaled
        src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web])

        thr = 10
        src_web_y = core.std.Expr([src_web_y, src_cru_y],
                                  f'x y - abs {thr} < x y * sqrt y ?')
        src_web_y = depth(src_web_y, 16)

        ringrid = core.rgvs.Repair(src_web_y,
                                   src_web_y.std.Convolution([1] * 9), 11)
        ringrid = core.std.Expr([ringrid, src_web_y], 'x y min')

        # Remove ringing with AoD+CR
        ring_mask = Mask.ringing_mask(src_y)
        bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask)
        bdweb = lvf.rfs(bdweb, src_web_y, [(64, 1413), (32034, 33195),
                                           (33465, 33881), (34174, 34524)])
        out = vdf.misc.merge_chroma(bdweb, src)

        # ranges_frames = [
        #     (64, 131), (215, 292), (339, 410), (444, 515), (566, 657),
        #     (695, 786), (903, 971), (977, 1045), (1058, 1153), (1278, 1335),
        #     (1355, 1413)
        # ]
        # cm = partial(vdf.mask.region_mask, clip=out.std.BlankClip(format=vs.GRAY16, color=65535))

        # credit_mask = [
        #     cm()
        # ]

        # Restore BD changes
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)

        diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0)
        bdchanges = out
        bdchanges = lvf.rfs(bdchanges, dering_src, [(882, 902), (5596, 5701),
                                                    (9909, 10064),
                                                    (11804, 11864)])
        bdchanges = lvf.rfs(bdchanges,
                            core.std.MaskedMerge(out, dering_src, diff_mask),
                            [(2534, 2682), (2840, 2887), (3188, 3271),
                             (3818, 3859), (3986, 4087), (4499, 4618),
                             (5009, 5088), (14736, 14801), (15744, 15872),
                             (17106, 17135), (17913, 18143), (24247, 24438),
                             (33196, 33329), (34021, 34173)])
        # return bdchanges, diff_mask
        out = bdchanges

        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(depth(out, 32),
                                         knlm_h=0.15,
                                         sigma=1,
                                         knlm_args=dict(d=1, a=3, s=3),
                                         bm3d_args=dict(ref=depth(ref, 32)))
        denoise = depth(denoise, 16)
        out = denoise

        pre = get_y(out)

        # Remove haloing
        dehalo = gf.MaskedDHA(pre,
                              rx=1.4,
                              ry=1.4,
                              darkstr=0.1,
                              brightstr=1.0,
                              maskpull=40,
                              maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp,
                                      ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo

        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000,
                                                7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa

        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp

        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked

        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma

        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out,
                                       17,
                                       30,
                                       sample_mode=4,
                                       use_neo=True)
        deband_d = vdf.deband.dumb3kdb(out, 17, 65)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1] * 9), deband_1, deband_2], [
                f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' +
                strength + f' - * + x {th_lo} <= z y ? ?',
                'x y * sqrt x z * sqrt * y * z * 0.25 pow'
            ])

        deband = lvf.rfs(deband, deband_d, [(3920, 3985)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband

        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

        stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True)
        stgrain_a = core.std.MaskedMerge(out, stgrain_a,
                                         adgmask_b.std.Invert())

        stgrain_b = sizedgrn(out,
                             0.2,
                             0.1,
                             1.15,
                             sharp=80,
                             static=True,
                             fade_edges=False,
                             protect_neutral=False,
                             seed=333)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b,
                                         adgmask_a.std.Invert())
        stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

        dygrain = sizedgrn(out,
                           0.3,
                           0.1,
                           1.25,
                           sharp=80,
                           static=False,
                           fade_edges=False,
                           protect_neutral=False,
                           seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain

        if int(NUM) != 12:
            while out.num_frames < 34646:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2],
                                          [0, 1, 2])
Esempio n. 8
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)

        ring_mask = Mask.ringing_mask(get_y(src))
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)
        out = dering_src

        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(depth(out, 32),
                                         knlm_h=0.15,
                                         sigma=1,
                                         knlm_args=dict(d=1, a=3, s=3),
                                         bm3d_args=dict(ref=depth(ref, 32)))
        denoise = depth(denoise, 16)
        out = denoise

        pre = get_y(out)

        # Remove haloing
        dehalo = gf.MaskedDHA(pre,
                              rx=1.4,
                              ry=1.4,
                              darkstr=0.1,
                              brightstr=1.0,
                              maskpull=40,
                              maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp,
                                      ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo

        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000,
                                                7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa

        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp

        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked

        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma

        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out,
                                       17,
                                       30,
                                       sample_mode=4,
                                       use_neo=True)
        deband_a = vdf.placebo.deband(out,
                                      22,
                                      threshold=8,
                                      iterations=3,
                                      grain=0)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1] * 9), deband_1, deband_2], [
                f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' +
                strength + f' - * + x {th_lo} <= z y ? ?',
                'x y * sqrt x z * sqrt * y * z * 0.25 pow'
            ])

        deband = lvf.rfs(deband, deband_a, [(OPSTART + 1382, OPSTART + 1433)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband

        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

        stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True)
        stgrain_a = core.std.MaskedMerge(out, stgrain_a,
                                         adgmask_b.std.Invert())

        stgrain_b = sizedgrn(out,
                             0.2,
                             0.1,
                             1.15,
                             sharp=80,
                             static=True,
                             fade_edges=False,
                             protect_neutral=False,
                             seed=333)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b,
                                         adgmask_a.std.Invert())
        stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

        dygrain = sizedgrn(out,
                           0.3,
                           0.1,
                           1.25,
                           sharp=80,
                           static=False,
                           fade_edges=False,
                           protect_neutral=False,
                           seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain

        if int(NUM) != 12:
            while out.num_frames < 2160:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2],
                                          [0, 1, 2])
Esempio n. 9
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut


        # Dehardsubbing using .ass file
        masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR)
        dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
        src_web = dehardsub


        # AoD is poorly rescaled
        src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web])

        thr = 10
        src_web_y = core.std.Expr([src_web_y, src_cru_y], f'x y - abs {thr} < x y * sqrt y ?')
        src_web_y = depth(src_web_y, 16)

        ringrid = core.rgvs.Repair(src_web_y, src_web_y.std.Convolution([1]*9), 11)
        ringrid = core.std.Expr([ringrid, src_web_y], 'x y min')

        # Remove ringing with AoD+CR
        ring_mask = Mask.ringing_mask(src_y)
        bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask)
        bdweb = lvf.rfs(bdweb, src_web_y, [(793, 1503), (1696, 2301), (32121, 34164), (34472, 34523)])
        out = vdf.misc.merge_chroma(bdweb, src)



        # Restore BD changes
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)

        diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0)
        bdchanges = core.std.MaskedMerge(out, dering_src, diff_mask)
        bdchanges = lvf.rfs(out, bdchanges, [(9419, 9512), (17731, 17865)])
        bdchanges = lvf.rfs(bdchanges, dering_src, [(14977, 15078), (15382, 15540), (23311, 23346)])
        # return bdchanges, diff_mask
        out = bdchanges




        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(
            depth(out, 32), knlm_h=0.15, sigma=1,
            knlm_args=dict(d=1, a=3, s=3), bm3d_args=dict(ref=depth(ref, 32))
        )
        denoise = depth(denoise, 16)
        out = denoise



        pre = get_y(out)


        # Remove haloing
        dehalo = gf.MaskedDHA(pre, rx=1.4, ry=1.4, darkstr=0.1, brightstr=1.0, maskpull=40, maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp, ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo




        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000, 7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa




        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp


        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked




        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma


        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out, 17, 30, sample_mode=4, use_neo=True)
        deband_x = vdf.placebo.deband(out, 28, 4, iterations=3, grain=0)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1]*9), deband_1, deband_2],
            [f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength + f' - * + x {th_lo} <= z y ? ?',
             'x y * sqrt x z * sqrt * y * z * 0.25 pow'])

        deband = lvf.rfs(deband, deband_x, [(6688, 6714)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband



        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

        stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True)
        stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert())

        stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, static=True, fade_edges=False, protect_neutral=False, seed=333)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert())
        stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

        dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, fade_edges=False, protect_neutral=False, seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain


        if int(NUM) != 12:
            while out.num_frames < 34646:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
Esempio n. 10
0
def do_filter():
    """Vapoursynth filtering"""
    src = WEB.src_cut
    src = src.std.AssumeFPS(src)

    src = depth(src, 16)
    out = src

    denoise = hvf.SMDegrain(out, tr=3, thSAD=150, thSADC=150)
    out = denoise

    dering = hvf.EdgeCleaner(out, 20, smode=1, hot=True)
    out = dering

    y = get_y(out)
    taps = 5
    w, h = 1600, 900
    descale = core.descale.Delanczos(depth(y, 32), w, h, taps)

    upscale = vdf.nnedi3_upscale(descale, pscrn=1, correct_shift=False)
    rescale = core.resize.Bicubic(upscale,
                                  1920,
                                  1080,
                                  src_left=.5,
                                  src_top=.5,
                                  filter_param_a=-.5,
                                  filter_param_b=.25)
    out = depth(rescale, 16)

    sharp = hvf.LSFmod(out,
                       strength=90,
                       Smode=3,
                       edgemode=0,
                       source=get_y(denoise))
    out = sharp

    merge = vdf.merge_chroma(out, denoise)
    out = merge

    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1200)
    pref = out.std.Convolution([1, 2, 1, 2, 4, 2, 1, 2,
                                1]).std.Convolution([1] * 9)
    deband1 = vdf.dumb3kdb(pref, 17, 45, grain=16, seed=333)
    deband2 = vdf.dumb3kdb(pref,
                           15,
                           49,
                           grain=16,
                           sample_mode=4,
                           use_neo=True,
                           blur_first=False,
                           seed=333)

    th_lo, th_hi = 20 << 8, 26 << 8
    strength = '{1} x - {1} {0} - /'.format(th_lo, th_hi)
    deband = core.std.Expr([pref, deband1, deband2], [
        f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength +
        f' - * + x {th_lo} <= z y ? ?', 'y'
    ])

    deband = core.std.MergeDiff(deband, out.std.MakeDiff(pref))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    grain = adptvgrnMod(out,
                        0.3,
                        0.15,
                        size=1.2,
                        luma_scaling=16,
                        hi=[128, 240],
                        protect_neutral=False,
                        seed=333)
    out = grain

    ref = denoise
    rescale_mask = vdf.drm(src, h, 'spline36', mthr=80).std.Maximum()
    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask),
                     [(2374, 4530), (4544, 4648), (4701, 4762), (30070, 30210),
                      (31266, 33422)])
    credit = lvf.rfs(credit, ref, [(33423, src.num_frames - 1)])
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
Esempio n. 11
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut

        # Dehardsubbing using .ass file
        masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR)
        dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
        src_web = dehardsub

        # AoD is poorly rescaled
        src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web])

        thr = 10
        src_web_y = core.std.Expr([src_web_y, src_cru_y],
                                  f'x y - abs {thr} < x y * sqrt y ?')
        src_web_y = depth(src_web_y, 16)

        ringrid = core.rgvs.Repair(src_web_y,
                                   src_web_y.std.Convolution([1] * 9), 11)
        ringrid = core.std.Expr([ringrid, src_web_y], 'x y min')

        # Remove ringing with AoD+CR
        ring_mask = Mask.ringing_mask(src_y)
        bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask)
        out = vdf.misc.merge_chroma(bdweb, src)

        # Restore BD changes
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)

        diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0)
        bdchanges = core.std.MaskedMerge(out, dering_src, diff_mask)
        bdchanges = lvf.rfs(out, bdchanges, [(4455, 4607), (4876, 5078),
                                             (5199, 5246), (5958, 6035),
                                             (6894, 7076), (7275, 7406),
                                             (7653, 7784), (7863, 7970),
                                             (8142, 8348), (8784, 9065),
                                             (9276, 9800), (10613, 10720),
                                             (10739, 10780), (10949, 10969),
                                             (11105, 11230), (11924, 12289),
                                             (12865, 12891), (13139, 13213),
                                             (15520, 15733), (19160, 19243),
                                             (20351, 20422), (24824, 24979),
                                             (26357, 26527), (27920, 28000),
                                             (29576, 29659), (29780, 29881),
                                             (30128, 30271), (30644, 30763),
                                             (31776, 31811), (32522, 32641)])
        # return bdchanges, diff_mask
        out = bdchanges

        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(depth(out, 32),
                                         knlm_h=0.15,
                                         sigma=1,
                                         knlm_args=dict(d=1, a=3, s=3),
                                         bm3d_args=dict(ref=depth(ref, 32)))
        denoise = depth(denoise, 16)
        out = denoise

        pre = get_y(out)

        # Remove haloing
        dehalo = gf.MaskedDHA(pre,
                              rx=1.4,
                              ry=1.4,
                              darkstr=0.1,
                              brightstr=1.0,
                              maskpull=40,
                              maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp,
                                      ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo

        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000,
                                                7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa

        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp

        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked

        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma

        ref = depth(src_cru, 16)
        cred_mask = Mask.credits_mask(src, JPBD_NCOP.clip_cut,
                                      JPBD_NCED.clip_cut, OPSTART, OPEND,
                                      EDSTART, EDEND)
        cred = out
        cred = lvf.rfs(cred, core.std.MaskedMerge(cred, ref, cred_mask, 0),
                       [(OPSTART, OPEND), (EDSTART, EDEND)])
        out = cred

        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out,
                                       17,
                                       30,
                                       sample_mode=4,
                                       use_neo=True)
        deband_a = vdf.placebo.deband(out,
                                      22,
                                      threshold=8,
                                      iterations=3,
                                      grain=0)
        import rekt
        deband_c = rekt.rekt_fast(out,
                                  lambda x: vdf.placebo.deband(x, 18, 6, 2, 0),
                                  bottom=600)
        deband_d = vdf.deband.dumb3kdb(out, 17, 65)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1] * 9), deband_1, deband_2], [
                f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' +
                strength + f' - * + x {th_lo} <= z y ? ?',
                'x y * sqrt x z * sqrt * y * z * 0.25 pow'
            ])

        deband = lvf.rfs(deband, deband_a, [(OPSTART + 1382, OPSTART + 1433)])
        deband = lvf.rfs(deband, deband_c, [(12362, 12391)])
        deband = lvf.rfs(deband, deband_d, [(14789, 15025)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband

        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

        stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True)
        stgrain_a = core.std.MaskedMerge(out, stgrain_a,
                                         adgmask_b.std.Invert())

        stgrain_b = sizedgrn(out,
                             0.2,
                             0.1,
                             1.15,
                             sharp=80,
                             static=True,
                             fade_edges=False,
                             protect_neutral=False,
                             seed=333)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b,
                                         adgmask_a.std.Invert())
        stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

        dygrain = sizedgrn(out,
                           0.3,
                           0.1,
                           1.25,
                           sharp=80,
                           static=False,
                           fade_edges=False,
                           protect_neutral=False,
                           seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain

        if int(NUM) != 12:
            while out.num_frames < 34646:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2],
                                          [0, 1, 2])
Esempio n. 12
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import EoEfunc as eoe
    import havsfunc as haf
    import kagefunc as kgf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from vsdpir import DPIR
    from vsutil import depth

    src = pre_filter()
    src = depth(src, 16)

    # Fix slight green tint present throughout parts of the OP
    src_g = core.std.Expr(src, ["", "", "x 32768 = x x 96 + ?"])
    src_g = lvf.rfs(src, src_g, [(None, 873)])

    scaled, descale_mask = flt.rescaler(src_g,
                                        height=854,
                                        shader_file=shader_file)

    # Denoising this is rough. Lots of fine detail that's easy to destroy.
    detail_mask = flt.detail_mask(scaled,
                                  pf_sigma=1.5,
                                  rxsigma=[50, 150, 200, 300],
                                  rad=2,
                                  brz=[2250, 3500])
    denoise_y = eoe.dn.BM3D(scaled, sigma=[0.3, 0])
    denoise_y_str = flt.to_yuvps(
        DPIR(flt.to_rgbs(scaled),
             strength=40,
             task='deblock',
             device_type='cpu'))
    denoise_y = lvf.rfs(denoise_y, denoise_y_str, [(1384, 1398)])

    denoise_uv = ccd(denoise_y, threshold=7, matrix='709')
    denoise_uv_rep = core.std.MaskedMerge(denoise_uv, denoise_y, detail_mask)
    stab = haf.GSMC(denoise_uv_rep, radius=1, thSAD=200, planes=[0])
    stab = lvf.rfs(
        stab, scaled,
        [(1399, 1400),
         (1408, 1416)])  # Undo denoising because it eats lines on these scenes
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=200 << 8, max_in=232 << 8)

    # F**k ufo lines
    eed = lvf.aa.nneedi3_clamp(decs, strength=1.6)
    sraa = lvf.sraa(decs, rfactor=1.5, aafun=flt.eedi3_singlerate_custom)
    clamp_aa = lvf.aa.clamp_aa(decs, eed, sraa, strength=1.6)

    # Certain frames have truly godawful aliasing. We attempt to fix those here
    tsraa = flt.transpose_sraa(decs,
                               rfactor=1.5,
                               aafun=flt.eedi3_singlerate_custom)
    tsraa_rep = core.rgvs.Repair(tsraa, clamp_aa, 13)
    aa_rfs = lvf.rfs(clamp_aa, tsraa_rep, strong_aa)

    # F**k ufo lines
    ec = haf.EdgeCleaner(aa_rfs, strength=4)

    # This fixes up all the super red scenes fairly well
    crecon = lvf.recon.chroma_reconstruct(ec)

    deband_a = flt.masked_f3kdb(crecon,
                                rad=18,
                                thr=24,
                                grain=[24, 16],
                                mask_args={'brz': (1250, 2250)})
    deband_b = flt.masked_f3kdb(crecon,
                                rad=24,
                                thr=40,
                                grain=[32, 24],
                                mask_args={'brz': (1000, 1750)})
    deband_c = flt.placebo_debander(crecon,
                                    grain=2,
                                    iterations=2,
                                    threshold=8,
                                    radius=16)
    deband = lvf.rfs(deband_a, deband_b, [])
    deband = kgf.crossfade(deband[:2246 + 48], deband_c[2246:], 47)
    deband = lvf.rfs(deband, crecon, [(1399, 1400)])

    sqmask = lvf.mask.BoundingBox((699, 50), (526, 870)).get_mask(deband)
    sqmask = core.bilateral.Gaussian(sqmask, sigma=4)
    blur = core.bilateral.Gaussian(deband,
                                   sigma=25).bilateral.Gaussian(sigma=25)
    blur_mask = core.std.MaskedMerge(blur, deband, sqmask)
    blurred = kgf.crossfade(deband[:2412 + 48], blur_mask[2411:], 48)

    blurred_del = core.std.DeleteFrames(blurred, [2293])

    grain_a = adptvgrnMod(blurred_del,
                          seed=42069,
                          strength=0.15,
                          static=True,
                          size=1.15,
                          sharp=80,
                          grain_chroma=False)
    grain_b = adptvgrnMod(blurred_del,
                          seed=42069,
                          strength=0.25,
                          static=True,
                          size=1.15,
                          sharp=100,
                          grain_chroma=False)
    grain_c = adptvgrnMod(blurred_del,
                          seed=42069,
                          strength=0.2,
                          static=False,
                          size=1.15,
                          sharp=100,
                          grain_chroma=False)
    grain = lvf.rfs(grain_a, grain_b, [(2390, None)])
    grain = lvf.rfs(grain, grain_c, [(885, 1149), (1324, 1345), (1489, 1506),
                                     (1603, 1810), (1981, 1996)])

    # Accidentally a frame during one of the previous processes. Easy to fix, though.
    oopsie = core.std.DeleteFrames(grain, [grain.num_frames - 1])
    out = enc.dither_down(oopsie)

    return out
Esempio n. 13
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    edstart1, edend1 = 37428, 37428 + 2160
    edstart2, edend2 = edend1 + 12, edend1 + 2160




    ref = hvf.SMDegrain(out, thSAD=300)
    denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref)
    out = denoise




    y = get_y(out)
    lineart = gf.EdgeDetect(y, 'scharr').morpho.Dilate(2, 2).std.Inflate()

    fkrescale = fake_rescale(
        y, 882, 0, 1,
        deringer=lambda x: gf.MaskedDHA(x, rx=1.85, ry=1.85, darkstr=0.25, brightstr=1.0, maskpull=100, maskpush=200),
        antialiser=lambda c: lvf.sraa(c, 2, 13, downscaler=core.resize.Bicubic)
    )
    merged = core.std.MaskedMerge(y, fkrescale, lineart)
    out = vdf.merge_chroma(merged, out)


    dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True)
    out = dering



    out = lvf.rfs(out, denoise, [(edstart1, src.num_frames - 1)])


    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000)
    deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband




    grain = adptvgrnMod(out, 0.3, static=True, grain_chroma=False, hi=[128, 240], seed=333)
    out = grain


    decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8)
    out = decz



    ref = depth(src, 16)
    src_c, src_nced1, src_nced2 = [
        depth(x, 16).std.Convolution(
            [1, 2, 1, 2, 4, 2, 1, 2, 1]
        ) for x in [src, JPBD_NCED1.src_cut, JPBD_NCED2.src_cut]
    ]

    ending_mask1 = vdf.dcm(out, src_c[edstart1:edend1 + 1], src_nced1[:edend1 - edstart1 + 1], edstart1, edend1, 2, 2)
    ending_mask2 = vdf.dcm(out, src_c[edstart2:edend2 + 1], src_nced2[:edend2 - edstart2 + 1], edstart2, edend2, 2, 2)
    ending_mask = core.std.Expr([ending_mask1, ending_mask2], 'x y +')
    ending_mask = iterate(ending_mask, core.std.Inflate, 4)

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, ending_mask), [(edstart1, edend2)])
    credit = lvf.rfs(credit, ref, [(21594, 21737), (39589, 39599), (41744, src.num_frames - 1)])
    out = credit


    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
Esempio n. 14
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    opstart, opend = 2712, 4869

    ref = hvf.SMDegrain(out, thSAD=300)
    denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref)
    out = denoise

    crop = core.std.Crop(out, left=12)
    crop = awf.bbmod(crop, left=2, thresh=20 << 8)
    resize = core.resize.Bicubic(crop, 1920)
    out = lvf.rfs(out, resize, [(86, 201)])

    y = get_y(out)
    lineart = gf.EdgeDetect(y, 'scharr').morpho.Dilate(2, 2).std.Inflate()

    fkrescale = fake_rescale(y,
                             882,
                             0,
                             1,
                             deringer=lambda x: gf.MaskedDHA(x,
                                                             rx=1.85,
                                                             ry=1.85,
                                                             darkstr=0.25,
                                                             brightstr=1.0,
                                                             maskpull=100,
                                                             maskpush=200),
                             antialiser=lambda c: lvf.sraa(
                                 c, 2, 13, downscaler=core.resize.Bicubic))
    merged = core.std.MaskedMerge(y, fkrescale, lineart)
    out = vdf.merge_chroma(merged, out)

    dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True)
    out = dering

    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000)
    deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    grain = adptvgrnMod(out,
                        0.3,
                        static=True,
                        grain_chroma=False,
                        hi=[128, 240],
                        seed=333)
    out = grain

    decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8)
    out = decz

    ref = depth(src, 16)
    src_c, src_ncop = [
        depth(x, 16).std.Convolution([1, 2, 1, 2, 4, 2, 1, 2, 1])
        for x in [src, JPBD_NCOP.src_cut]
    ]

    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           src_ncop[:opend - opstart + 1], opstart, opend, 2,
                           2)
    opening_mask = iterate(opening_mask, core.std.Inflate, 4)

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, opening_mask),
                     [(opstart, opend)])
    credit = lvf.rfs(credit, ref, [(17985, 18128)])
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
Esempio n. 15
0
def do_filter():
    """Vapoursynth filtering"""
    def _sraa(clip: vs.VideoNode, nnargs: dict, eeargs: dict) -> vs.VideoNode:
        def _nnedi3(clip):
            return clip.nnedi3.nnedi3(0, False, **nnargs)

        def _eedi3(clip, sclip):
            return clip.eedi3m.EEDI3(0, False, **eeargs, sclip=sclip)

        clip = _eedi3(clip, _nnedi3(clip)).std.Transpose()
        clip = _eedi3(clip, _nnedi3(clip)).std.Transpose()
        return clip

    def _nnedi3(clip: vs.VideoNode, factor: float, args: dict) -> vs.VideoNode:
        upscale = clip.std.Transpose().nnedi3.nnedi3(0, True, **args) \
            .std.Transpose().nnedi3.nnedi3(0, True, **args)
        return core.resize.Spline36(upscale,
                                    clip.width * factor,
                                    clip.height * factor,
                                    src_top=.5,
                                    src_left=.5)

    def area_resize(clip: vs.VideoNode, width: int,
                    height: int) -> vs.VideoNode:
        blank = core.std.BlankClip(clip, format=vs.GRAY16, color=128 << 8)
        clip = join([clip, blank, blank])
        clip = core.area.AreaResize(clip, width, height)
        return get_y(clip)

    src = JPBD.src_cut
    src = depth(src, 16)

    flashback = [(31665, 31987), (68524, 68569)]

    denoise = CoolDegrain(src, tr=1, thsad=48, blksize=8, overlap=4, plane=4)
    denoise = lvf.rfs(denoise, src, flashback)

    dering = hvf.EdgeCleaner(denoise, 10, rmode=3, smode=1, hot=True)

    luma = get_y(dering)
    line_mask = TAAmbk(luma, mtype=2, showmask=1).std.Inflate()
    upscale = _nnedi3(luma, 2, dict(nsize=4, nns=4, qual=2, pscrn=2))
    sraa = _sraa(upscale, dict(nsize=0, nns=3, qual=1, pscrn=1),
                 dict(alpha=0.2, beta=0.5, gamma=40, nrad=3, mdis=20))
    sraa = core.rgvs.Repair(sraa, upscale, 13)
    antialias = area_resize(sraa, src.width, src.height)
    antialias = lvf.rfs(core.std.MaskedMerge(luma, antialias, line_mask),
                        antialias, [(22503, 22789)])
    antialias_merged = vdf.merge_chroma(antialias, denoise)

    deband_mask_a = lvf.denoise.detail_mask(antialias_merged,
                                            brz_a=3000,
                                            brz_b=1200)
    deband_mask_b = kgf.retinex_edgemask(antialias_merged)
    deband_mask = core.std.Expr([deband_mask_a, deband_mask_b], 'x y +')
    deband = dbs.f3kpf(antialias_merged, 18, 30, 30)
    deband = core.std.MaskedMerge(deband, antialias_merged, deband_mask)
    deband = hvf.ContraSharpening(deband, antialias_merged)
    deband = lvf.rfs(deband, antialias_merged, flashback)

    grain = core.neo_f3kdb.Deband(deband, preset='depth', grainy=24)
    grain_a = kgf.adaptive_grain(grain)
    grain_b = core.grain.Add(grain, 1, 0, constant=True)
    grain = lvf.rfs(grain_a, grain_b, flashback)

    mask_borders = core.std.BlankClip(grain,
                                      format=vs.GRAY16,
                                      color=(256 << 8) - 1)
    mask_borders = vdf.region_mask(mask_borders, 0, 0, 132, 132).std.Invert()
    final = lvf.rfs(grain, core.std.MaskedMerge(grain, src, mask_borders),
                    flashback + [(65388, 65413), (113621, 113763)])

    smooth = xvs.mvfrc(src[146178:src.num_frames], preset='slow')
    vfr = muvf.VFRSplice([final[:146178], smooth], 'sora_timecode.txt')

    return depth(vfr, 10)
Esempio n. 16
0
def do_filter():
    """Vapoursynth filtering"""
    src = CLIP_SRC
    out = depth(src, 16)

    clip = out
    clip = core.std.FreezeFrames(clip, 1432, 1433, 1434)
    clip = core.std.FreezeFrames(clip, 1503, 1514, 1515)
    out = clip

    planes = split(out)
    planes[1], planes[2] = [
        core.resize.Spline16(plane, src_left=-0.25) for plane in planes[1:]
    ]
    out = join(planes)

    # qual=2 produces weird artefacts and a stronger alpha/beta/gamma smudges details.
    new_fields = core.eedi3m.EEDI3(out,
                                   1,
                                   alpha=0.4,
                                   beta=0.5,
                                   gamma=300,
                                   nrad=3,
                                   mdis=20,
                                   vcheck=3,
                                   sclip=core.nnedi3.nnedi3(out,
                                                            1,
                                                            nsize=3,
                                                            nns=3,
                                                            qual=1,
                                                            pscrn=4))
    out = new_fields

    denoise = gf.MCDegrainSharp(
        out,
        tr=3,
        bblur=0.65,
        csharp=lambda x: hvf.LSFmod(
            x, strength=85, Smode=3, Lmode=1, edgemode=0),
        thSAD=285,
        rec=True)
    out = denoise

    edge_cleaner = hvf.EdgeCleaner(out, 35, rmode=13, smode=1, hot=True)
    out = edge_cleaner

    antialias = lvf.sraa(out,
                         2,
                         13,
                         downscaler=core.resize.Bicubic,
                         alpha=0.25,
                         beta=0.35,
                         gamma=400)
    antialias_a = lvf.sraa(out, 1.4, 9, downscaler=core.resize.Bicubic)
    antialias = lvf.rfs(antialias, antialias_a, [(1223, 1229)])
    out = antialias

    chromableed = xvs.WarpFixChromaBlend(out, 72, depth=8)
    out = chromableed

    detail_mask = lvf.denoise.detail_mask(out, brz_a=2300, brz_b=1000)
    deband = placebo.deband(out, 17, 4.25, grain=6)
    deband_a = placebo.deband(out, 17, 8, 2, grain=6)
    deband_b = placebo.deband(out, 17, 6, grain=6)
    deband = lvf.rfs(deband, deband_a, [(1230, 1330)])
    deband = lvf.rfs(deband, deband_b, [(1678, 1889)])

    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    return depth(out, 10)