示例#1
0
def do_filter():
    """Vapoursynth filtering"""
    def _rescale(clip: vs.VideoNode, dx: int, dy: int):
        eeargs = dict(pscrn=2, alpha=0.3, beta=0.4, gamma=500, nrad=3, mdis=18)
        ux = clip.width * 2
        uy = clip.height * 2
        clip = iaa.eedi3_instance(clip.std.Transpose(),
                                  nnedi3Mode='opencl',
                                  **eeargs)
        clip = core.resize.Bicubic(clip,
                                   height=dx,
                                   src_top=-0.5,
                                   src_height=ux,
                                   filter_param_a=0,
                                   filter_param_b=0)
        clip = iaa.eedi3_instance(clip.std.Transpose(),
                                  nnedi3Mode='opencl',
                                  **eeargs)
        return core.resize.Bicubic(clip,
                                   height=dy,
                                   src_top=-0.5,
                                   src_height=uy,
                                   filter_param_a=0,
                                   filter_param_b=0)

    # Fun part / Cutting
    src_funi, src_wkn = [depth(c, 16) for c in CLIPS_SRC]
    src_funi, src_wkn = src_funi[744:], src_wkn[0] + src_wkn + src_wkn[-1]

    # Dehardsubbing
    # comp = lvf.comparison.stack_compare(src_funi, src_wkn, height=720, make_diff=True)
    src = core.std.MaskedMerge(src_wkn, src_funi,
                               kgf.hardsubmask(src_wkn, src_funi))
    hardsub_rem = core.std.MaskedMerge(
        src, src_funi, kgf.hardsubmask_fades(src, src_funi, 8, 2000))
    src = lvf.rfs(src, hardsub_rem, [(4018, 4138)])

    # Regular filterchain
    op, ed, eyec = (1534, 3692), (16280, 16399), (31888, 34046)
    opstart = op[0]
    h = 846
    w = get_w(h)
    b, c = vdf.get_bicubic_params('mitchell')

    luma = get_y(src)

    thr = 8000
    line_mask = gf.EdgeDetect(
        luma, 'FDOG').std.Median().std.Expr(f'x {thr} < x x 3 * ?')

    descale = core.descale.Debicubic(depth(luma, 32), w, h, b, c)

    rescaled = _rescale(depth(descale, 16), src.width, src.height)
    rescaled = core.std.MaskedMerge(luma, rescaled, line_mask)

    dering = core.std.MaskedMerge(
        rescaled, core.bilateral.Gaussian(rescaled, 0.3),
        hvf.HQDeringmod(rescaled, incedge=True, show=True))

    rescaled = lvf.rfs(rescaled, dering, [(opstart, opstart + 498)])
    merged = vdf.merge_chroma(rescaled, src)
    out = merged

    cred_m = vdf.drm(src, h, b=b, c=c, mthr=80, mode='ellipse')
    credit = lvf.rfs(out, core.std.MaskedMerge(out, src, cred_m), [op])
    credit = lvf.rfs(credit, src, [eyec, ed])
    out = credit

    deband = dbs.f3kpf(out, 17, 36, 36)
    deband = core.std.MaskedMerge(deband, out, line_mask)

    dedimm = gf.Tweak(deband, sat=1.28, cont=1.28)
    dedimm = lvf.rfs(deband, dedimm, [(1112, 1159), (7764, 7780), (9436, 9514),
                                      (20607, 20755), (26972, 27006)])

    grain = core.grain.Add(dedimm, 0.1)

    return depth(grain, 10)
示例#2
0
    def main(self: Filtering) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        out = src


        h = 800  # noqa
        w = get_w(h)  # noqa
        opstart, opend = 2830, 4986
        edstart, edend = 31504, 33661




        inp = get_y(out)
        out = inp



        # Remove the grain
        ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=0)
        preden = mvf.BM3D(out, sigma=2, radius1=1, ref=ref)
        out = preden




        # Rescale / Antialiasing / Limiting
        out = depth(out, 32)
        lineart = vdf.mask.FDOG().get_mask(out, lthr=0.065, hthr=0.065).std.Maximum().std.Minimum()
        lineart = lineart.std.Median().std.Convolution([1] * 9)


        descale_clips = [core.resize.Bicubic(out, w, h, filter_param_a=1/3, filter_param_b=1/3),
                         core.descale.Debicubic(out, w, h, 0, 1/2),
                         core.descale.Debilinear(out, w, h)]
        descale = core.std.Expr(descale_clips, 'x y z min max y z max min z min')

        upscale = vdf.scale.fsrcnnx_upscale(descale, height=h * 2, shader_file=r'_shaders\FSRCNNX_x2_56-16-4-1.glsl',
                                            upscaled_smooth=vdf.scale.eedi3_upscale(descale), profile='zastin',
                                            sharpener=partial(gf.DetailSharpen, sstr=1.65, power=4, mode=0, med=True))


        antialias = self.sraa_eedi3(upscale, 3, alpha=0.2, beta=0.4, gamma=100, mdis=20, nrad=3)

        downscale = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic', filter_param_a=0, filter_param_b=0)

        adaptmask = core.adg.Mask(downscale.std.PlaneStats(), 25).std.Minimum().std.Minimum().std.Convolution([1] * 9)
        contra = gf.ContraSharpening(downscale, depth(preden, 32), radius=2).rgsf.Repair(downscale, 1)
        contra = core.std.MaskedMerge(downscale, contra, adaptmask)


        scaled = core.std.MaskedMerge(out, contra, lineart)
        merged = vdf.misc.merge_chroma(depth(scaled, 16), src)
        out = merged


        detail_light_mask = lvf.mask.detail_mask(out, brz_a=1500, brz_b=600)

        deband = vdf.deband.dumb3kdb(out, 16, [33, 1], sample_mode=4, use_neo=True)
        deband = core.std.MaskedMerge(deband, out, detail_light_mask)
        out = deband


        # Restore the grain
        neutral = inp.std.BlankClip(960, 540, color=128 << 8)
        diff = join([inp.std.MakeDiff(preden), neutral, neutral])
        grain = core.std.MergeDiff(out, diff)
        out = grain



        crop_a = self.crop_and_fix(out, src, top=128, bottom=136)
        crop_b = self.crop_and_fix(out, src, top=132, bottom=140)
        crop = out
        crop = lvf.rfs(crop, crop_a, [(25696, 25750), (25768, 25963), (26916, 27095),
                                      (27213, 27319), (27368, 27395), (27615, 27810)])
        crop = lvf.rfs(crop, crop_b, [(25751, 25767), (25964, 26723), (26786, 26915),
                                      (27096, 27212), (27320, 27367), (27396, 27614)])
        out = crop




        ref = src
        creditless_mask = vdf.mask.diff_creditless_mask(
            ref, src[opstart:opend+1], JPBD_NCOP.clip_cut[:opend-opstart+1], opstart, thr=25 << 8, sw=3, sh=3, prefilter=True
        ).std.Deflate()
        ringing_mask = hvf.HQDeringmod(ref, mrad=1, msmooth=2, mthr=40, show=True)

        credit = out
        credit = lvf.rfs(credit, ref, [(edstart, edend)])
        credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, creditless_mask, 0), [(opstart, opend)])
        credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, ringing_mask, 0),
                         [(opstart + 169, opstart + 411)])
        out = credit



        endcard = out + out[31757] * 119
        out = endcard


        decs = vdf.noise.decsiz(out, sigmaS=10, min_in=110 << 8, max_in=192 << 8, gamma=1.1)
        out = decs


        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#3
0
def do_filter():
    """Vapoursynth filtering"""
    def _single_rate_aa(clip):
        nnargs = dict(nsize=0, nns=2, qual=1)
        eeargs = dict(alpha=0.2, beta=0.4, gamma=250, nrad=3, mdis=20)
        clip = core.eedi3m.EEDI3(clip,
                                 0,
                                 0,
                                 0,
                                 sclip=core.nnedi3.nnedi3(
                                     clip, 0, 0, 0, **nnargs),
                                 **eeargs).std.Transpose()
        clip = core.eedi3m.EEDI3(clip,
                                 0,
                                 0,
                                 0,
                                 sclip=core.nnedi3.nnedi3(
                                     clip, 0, 0, 0, **nnargs),
                                 **eeargs).std.Transpose()
        return clip

    # Fun part / Cutting
    src_funi, src_wkn = [depth(c, 16) for c in CLIPS_SRC]
    src_funi, src_wkn = src_funi[744:], src_wkn[0] + src_wkn

    # Dehardsubbing
    # comp = lvf.comparison.stack_compare(src_funi, src_wkn, height=540, make_diff=True)
    src = core.std.MaskedMerge(src_wkn, src_funi,
                               kgf.hardsubmask(src_wkn, src_funi))
    hardsub_rem = core.std.MaskedMerge(
        src, src_funi, kgf.hardsubmask_fades(src, src_funi, 8, 2000))
    src = lvf.rfs(src, hardsub_rem, [(3368, 3451)])

    # Regular filterchain
    op, ed, eyec = (1200, 3356), (18989, 19108), (31888, 34046)
    opstart = op[0]

    denoise = CoolDegrain(src, tr=1, thsad=36, blksize=8, overlap=4, plane=4)

    h = 846
    w = get_w(h)
    b, c = vdf.get_bicubic_params('mitchell')

    luma = get_y(denoise)

    descale = core.descale.Debicubic(depth(luma, 32), w, h, b, c)

    upscale = vdf.fsrcnnx_upscale(depth(descale, 16), descale.height * 2,
                                  "Shaders/FSRCNNX_x2_56-16-4-1.glsl",
                                  core.resize.Point)
    sraa = _single_rate_aa(upscale)
    rescaled = core.resize.Bicubic(sraa,
                                   src.width,
                                   src.height,
                                   filter_param_a=0,
                                   filter_param_b=0)

    dering = core.std.MaskedMerge(
        rescaled, core.bilateral.Gaussian(rescaled, 0.3),
        hvf.HQDeringmod(rescaled, incedge=True, show=True))
    rescaled = lvf.rfs(rescaled, dering, [(opstart, opstart + 498)])
    merged = vdf.merge_chroma(rescaled, src)
    out = merged

    dehalo = fine_dehalo(out,
                         rx=2.2,
                         darkstr=0,
                         brightstr=1,
                         contra=True,
                         useMtEdge=True)
    out = dehalo

    cred_m = vdf.drm(src, h, b=b, c=c, mthr=80, mode='ellipse')
    credit = lvf.rfs(out, core.std.MaskedMerge(out, src, cred_m), [op])
    credit = lvf.rfs(credit, src, [eyec, ed])
    out = credit

    thr = 7000
    line_mask = gf.EdgeDetect(
        out, 'FDOG').std.Median().std.Expr(f'x {thr} < x x 3 * ?')

    deband = dbs.f3kpf(out, 17, 36, 36)
    deband_b = dbs.f3kbilateral(out, 20, 64, 64)
    deband = lvf.rfs(deband, deband_b, [(14775, 14846)])
    deband = core.std.MaskedMerge(deband, out, line_mask)
    out = deband

    dedimm = gf.Tweak(out, sat=1.1, cont=1.1)
    dedimm = lvf.rfs(out, dedimm, [(12957, 13061)])
    out = dedimm

    grain = core.grain.Add(out, 0.1)
    out = grain

    return depth(out, 10)