Пример #1
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    opstart, opend = 480, 2637
    edstart, edend = 29707, 31863

    dehalo = gf.MaskedDHA(out,
                          rx=1.35,
                          ry=1.35,
                          darkstr=0.25,
                          brightstr=1.0,
                          maskpull=46,
                          maskpush=148)
    out = dehalo

    antialias = lvf.sraa(out, 1.5, 9, downscaler=core.resize.Bicubic)
    antialias_b = lvf.sraa(antialias, 1.05, 3, downscaler=core.resize.Bicubic)
    antialias_b = TAAmbk(antialias_b,
                         aatype='Eedi3SangNom',
                         cycle=4,
                         thin=2,
                         sharp=100,
                         mtype=0,
                         down8=False)
    antialias = lvf.rfs(antialias, antialias_b, [(19956, 20029)])
    out = antialias

    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)
    deband = dbs.f3kpf(out, 17, 24, 24)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband

    src_c, ncop, nced = [
        clip.std.Median()
        for clip in [src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut]
    ]
    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           ncop[:opend - opstart + 1], opstart, opend, 3, 3)
    ending_mask = vdf.dcm(out, src_c[edstart:edend + 1],
                          nced[:edend - edstart + 1], edstart, edend, 3, 3)
    credit_mask = core.std.Expr([opening_mask, ending_mask],
                                'x y +').std.Convolution([1] * 9)

    credit = lvf.rfs(out, core.std.MaskedMerge(out, src, credit_mask),
                     [(opstart, opend), (edstart, edend)])
    out = credit

    return depth(out, 10)
Пример #2
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Regular VapourSynth filterchain"""
    import lvsfunc as lvf
    import vardefunc as vdf
    from vsutil import depth, get_y

    src, *_ = trim()
    src_CR = JP_CR.clip_cut
    src_NCOP, src_NCED = YT_NCOP.clip, YT_NCED.clip
    b = core.std.BlankClip(src, length=1)

    # OP/ED stack comps to check that it lines up
    op_scomp = lvf.scomp(src[opstart:opstart + src_NCOP.num_frames - 1] + b,
                         src_NCOP[:-op_offset] + b)  # noqa
    ed_scomp = lvf.scomp(src[edstart:edstart + src_NCED.num_frames - 1] + b,
                         src_NCED[:-ed_offset] + b)  # noqa

    # Blurring clips
    blur_src = core.bilateral.Gaussian(src, sigma=2.5)
    blur_NCOP = core.bilateral.Gaussian(src_NCOP, sigma=2.5)
    blur_NCED = core.bilateral.Gaussian(src_NCED, sigma=2.5)

    # Masking credits
    op_mask = vdf.dcm(
        blur_src, blur_src[opstart:opstart+src_NCOP.num_frames-op_offset], blur_NCOP[:-op_offset],
        start_frame=opstart, thr=28, prefilter=False) if opstart is not False \
        else get_y(core.std.BlankClip(src))
    ed_mask = vdf.dcm(
        blur_src, blur_src[edstart:edstart+src_NCED.num_frames-ed_offset], blur_NCED[:-ed_offset],
        start_frame=edstart, thr=25, prefilter=False) if edstart is not False \
        else get_y(core.std.BlankClip(src))
    credit_mask = core.std.Expr([op_mask, ed_mask], expr='x y +')
    credit_mask = depth(credit_mask, 16).std.Binarize()

    src = depth(src, 16)
    line_mask = vdf.mask.FDOG().get_mask(get_y(src))
    src_merge = core.std.MaskedMerge(src, depth(src_CR, 16), line_mask)

    src_y = get_y(src_merge)
    denoise_y = flt.bm3d_ref(src_y,
                             bm3d_sigma=1,
                             dec_sigma=8,
                             dec_min=192 << 8)
    denoise_y = core.std.MaskedMerge(denoise_y, src_y, line_mask)
    merged = vdf.misc.merge_chroma(denoise_y, src)

    dehalo = flt.bidehalo(merged, sigma=1, mask_args={'brz': 0.25})

    cmerged = core.std.MaskedMerge(dehalo, src, credit_mask)

    deband = flt.masked_f3kdb(cmerged,
                              thr=20,
                              grain=12,
                              mask_args={'brz': (1500, 3500)})
    grain = flt.default_grain(deband)

    return grain  # type: ignore
Пример #3
0
def mask_oped(clip: vs.VideoNode, src: vs.VideoNode,
              op: Optional[Tuple[int, int]], ed: Optional[Tuple[int, int]],
              src_op: vs.VideoNode, src_ed: vs.VideoNode) -> vs.VideoNode:
    merge = clip
    if op is not None:
        credit_op_m = dcm(clip, src[op[0]:op[1] + 1],
                          src_op[:op[1] - op[0] + 1], op[0], op[1], 2, 2)
        merge = core.std.MaskedMerge(merge, src, credit_op_m)
    if ed is not None:
        credit_ed_m = dcm(clip, src[ed[0]:ed[1] + 1],
                          src_ed[:ed[1] - ed[0] + 1], ed[0], ed[1], 2, 2)
        merge = core.std.MaskedMerge(merge, src, credit_ed_m)
    return merge
Пример #4
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src + src[-1]

    opstart, opend = 2638, 4794
    edstart, edend = 31767, 33924

    dehalo = gf.MaskedDHA(out,
                          rx=1.35,
                          ry=1.35,
                          darkstr=0.25,
                          brightstr=1.0,
                          maskpull=46,
                          maskpush=148)
    out = dehalo

    antialias = lvf.sraa(out, 1.5, 9, downscaler=core.resize.Bicubic)
    out = antialias

    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)
    deband = dbs.f3kpf(out, 17, 24, 24)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband

    src_c, ncop, nced = [
        clip.std.Median()
        for clip in [src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut]
    ]
    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           ncop[:opend - opstart + 1], opstart, opend, 3, 3)
    ending_mask = vdf.dcm(out, src_c[edstart:edend + 1],
                          nced[:edend - edstart + 1], edstart, edend, 3, 3)
    credit_mask = core.std.Expr([opening_mask, ending_mask],
                                'x y +').std.Convolution([1] * 9)

    credit = lvf.rfs(out, core.std.MaskedMerge(out, src, credit_mask),
                     [(opstart, opend), (edstart, edend)])
    out = credit

    return depth(out, 10)
Пример #5
0
def recreate_OP1E():
    src_nc = OP1D.clip_cut
    src_ep = EP13.clip_cut[6954:6954 + src_nc.num_frames]
    op = lvf.rfs(src_nc, src_ep, [(2048, 2156)])

    mask = vdf.dcm(op,
                   op[0:src_nc.num_frames - 1],
                   src_nc,
                   0,
                   thr=248,
                   prefilter=True)
    merge = core.std.MaskedMerge(op, src_nc, mask[2075])
    op = lvf.rfs(op, merge, [(2048, 2092)])

    pause = src_ep.std.FreezeFrames(2111, src_ep.num_frames - 1, 2111)
    fade = kgf.crossfade(pause[0:2159], core.std.BlankClip(pause),
                         32)[0:src_nc.num_frames]
    merge = core.std.MaskedMerge(op, fade,
                                 mask[2155].std.Minimum().std.Minimum())
    op = lvf.rfs(op, merge, [(2112, 2156)])

    pause = op.std.FreezeFrames(2121, op.num_frames - 1, 2121)
    fade = kgf.crossfade(pause[0:2159], core.std.BlankClip(pause),
                         32)[0:src_nc.num_frames]
    merge = core.std.MaskedMerge(op, fade,
                                 mask[2155].std.Minimum().std.Minimum())
    op = lvf.rfs(op, merge, [(2112, 2156)])

    mask_img = core.imwri.Read(MASK).resize.Point(format=fade.format.id,
                                                  matrix_s="709")
    mask = core.std.Binarize(mask_img, 128).std.Maximum().std.Deflate()
    return core.std.MaskedMerge(fade, op, mask, [0, 1, 2])
Пример #6
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import rekt
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from vsutil import depth, get_w, get_y

    src: vs.VideoNode = pre_corrections()  # type:ignore[assignment]
    src_NCED = JP_BD_NCED.clip_cut

    # Masking credits
    ed_mask = vdf.dcm(
        src, src[edstart:edstart+src_NCED.num_frames-ed_offset], src_NCED[:-ed_offset],
        start_frame=edstart, thr=25, prefilter=False) if edstart is not False \
        else get_y(core.std.BlankClip(src))
    credit_mask = depth(ed_mask, 16).std.Binarize()

    rkt = rekt.rektlvls(src, [0, 1079], [7, 7], [0, 1919], [7, 7],
                        prot_val=None)
    rkt = depth(rkt, 16)

    denoise_uv = ccd(rkt, threshold=7, matrix='709')
    stab = haf.GSMC(denoise_uv, radius=1, thSAD=200, planes=[0])
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=208 << 8, max_in=232 << 8)

    l_mask = vdf.mask.FDOG().get_mask(get_y(decs), lthr=0.065,
                                      hthr=0.065).std.Maximum().std.Minimum()
    l_mask = l_mask.std.Median().std.Convolution([1] * 9)

    aa_weak = lvf.aa.taa(decs, lvf.aa.nnedi3(opencl=True))
    aa_strong = lvf.aa.upscaled_sraa(decs,
                                     downscaler=lvf.kernels.Bicubic(b=-1 / 2,
                                                                    c=1 /
                                                                    4).scale)
    aa_clamp = lvf.aa.clamp_aa(decs, aa_weak, aa_strong, strength=1.5)
    aa_masked = core.std.MaskedMerge(decs, aa_clamp, l_mask)

    dehalo = haf.FineDehalo(aa_masked,
                            rx=1.6,
                            ry=1.6,
                            darkstr=0,
                            brightstr=1.25)
    darken = flt.line_darkening(dehalo, 0.275).warp.AWarpSharp2(depth=2)

    merged_credits = core.std.MaskedMerge(darken, decs, credit_mask)

    deband = flt.masked_f3kdb(merged_credits, rad=18, thr=32, grain=[32, 12])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.35,
                                      luma_scaling=8,
                                      size=1.05,
                                      sharp=80,
                                      grain_chroma=False)

    return grain
Пример #7
0
def mask_nc(clip: vs.VideoNode,
            src: vs.VideoNode,
            ncop: FileInfo,
            nced: FileInfo,
            OP: Optional[int] = None,
            ED: Optional[int] = None) -> vs.VideoNode:
    mask_op = vdf.dcm(src,
                      src[OP:OP + ncop.clip_cut.num_frames],
                      ncop.clip_cut,
                      OP,
                      thr=128,
                      prefilter=True) if OP else get_y(core.std.BlankClip(src))
    mask_ed = vdf.dcm(src,
                      src[ED:ED + nced.clip_cut.num_frames],
                      nced.clip_cut,
                      ED,
                      thr=128,
                      prefilter=True) if ED else get_y(core.std.BlankClip(src))
    credit_mask = depth(core.std.Expr([mask_op, mask_ed], expr='x y +'), 16)
    merge = core.std.MaskedMerge(depth(clip, 16), depth(src, 16), credit_mask)
    return merge
Пример #8
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    edstart, edend = 31888, src.num_frames-1


    shift = core.resize.Point(out, src_left=1).edgefixer.ContinuityFixer([2, 1, 1], 0, 0, 0)
    out = lvf.rfs(out, shift, [(235, 318)])



    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    denoise = mvf.BM3D(out, [1.5, 1], 1, profile1='lc', ref=ref)
    out = denoise


    y = get_y(out)
    lineart = vdf.edge_detect(y, 'FDOG', scale_value(0.065, 32, 16), (1, 1)).std.Median().std.BoxBlur(0, 1, 1, 1, 1)

    rescale = fake_rescale(y, 837.5, 1/3, 1/3, coef_dering=0.1, coef_dark=1.25,
                           coef_warp=1.15, coef_sharp=0.75, coef_finalsharp=0.85)
    rescale = core.std.MaskedMerge(y, rescale, lineart)

    out = vdf.merge_chroma(rescale, out)





    preden = core.dfttest.DFTTest(get_y(out), ftype=0, sigma=0.5, sbsize=16, sosize=12, tbsize=1)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=6000, brz_b=5000)
    detail_light_mask = lvf.denoise.detail_mask(preden, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.BoxBlur(0, 1, 1, 1, 1)

    detail_mask = core.std.Expr([preden, detail_mask_grow, detail_mask], f'x {40<<8} < y z ?')

    pf = vdf.merge_chroma(preden, out)
    deband = dumb3kdb(pf, 17, 40)
    deband_b = dumb3kdb(pf, 20, 80)

    deband = lvf.rfs(deband, deband_b, [(2194, 2216), (2283, 2306)])
    deband = core.std.MergeDiff(deband, out.std.MakeDiff(pf))
    deband = core.std.MaskedMerge(deband, out, detail_light_mask)
    out = deband


    grain = kgf.adaptive_grain(out, 0.35)
    out = grain



    ref = depth(src, 16)
    src_c, src_nced = [depth(x, 16) for x in [src, JPBD_NCED.src_cut[13:]]]

    ending_mask = vdf.dcm(out, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 2, 2).std.BoxBlur(0, 2, 2, 2, 2)

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, ending_mask), [(31900, src.num_frames-1)])
    out = credit



    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2], [0, 1, 2])
Пример #9
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    h = 720
    w = get_w(h)

    edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500)
    out = edgesfix

    clip = depth(out, 32)
    denoise = hybrid_denoise(clip, 0.45, 1.5)
    out = denoise

    luma = get_y(out)
    line_mask = line_mask_func(luma)

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, pscrn=1)
    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.2,
                                         beta=0.5,
                                         gamma=600,
                                         mdis=15)

    scaled = core.resize.Bicubic(antialias, src.width, src.height)
    rescale = core.std.MaskedMerge(luma, scaled, depth(line_mask, 32))
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    preden = core.knlm.KNLMeansCL(get_y(out),
                                  h=0.75,
                                  a=2,
                                  d=3,
                                  device_type='gpu',
                                  device_id=0)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(preden, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.Convolution([1, 1, 1, 1, 1, 1, 1, 1, 1])

    detail_mask = core.std.Expr([preden, detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')
    op_mask = mask_opening(out)
    op_mask = iterate(op_mask, core.std.Deflate, 2)

    deband_a = dbs.f3kpf(out, 17, 36, 42, thr=0.5, elast=2, thrc=0.2)
    deband_b = placebo.deband(out, 18, 5.5, 2, 0)
    deband_c = placebo.deband(out, 22, 10, 3, 0)
    deband = core.std.MaskedMerge(deband_a, deband_b, preden)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband = lvf.rfs(deband, core.std.MaskedMerge(deband_c, deband, op_mask),
                     [(OPSTART + 0, OPSTART + 38)])
    deband = lvf.rfs(deband, deband_b, [(OPSTART + 236, OPSTART + 284)])
    deband = lvf.rfs(deband, deband_c, [(OPSTART + 1934, OPSTART + 1944)])
    deband = core.neo_f3kdb.Deband(deband,
                                   preset='depth',
                                   grainy=24,
                                   grainc=24)
    out = deband

    ref, src, src_ncop = [
        depth(x, 16) for x in [denoise, src, JPBD_NCOP.src_cut]
    ]
    credit_mask = vdf.drm(ref, kernel='bilinear', mthr=65)
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask, 0),
                     [(0, 3164)])
    credit = lvf.rfs(credit, ref, [(34693, 34764)])
    out = credit

    src_c, src_ncop = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_ncop]
    ]
    opening_mask = vdf.dcm(out, src_c[OPSTART:OPEND + 1],
                           src_ncop[:OPEND - OPSTART + 1], OPSTART, OPEND, 4,
                           4).std.Inflate()
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, opening_mask),
                     [(OPSTART, OPEND)])
    out = credit

    grain = adptvgrnMod(out,
                        0.3,
                        0.15,
                        1.25,
                        luma_scaling=8,
                        sharp=80,
                        static=False,
                        lo=19)
    out = grain

    return depth(out, 10)
Пример #10
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')
    opstart, opend = 768, 3164
    edstart, edend = 30571, 32728
    full_stuff = [(3189, 3296), (13806, 13961)]

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)
    upscale_smooth = vdf.nnedi3_upscale(descale, pscrn=1)
    upscale = lvf.rfs(upscale, upscale_smooth, [(5534, 5598)])

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)

    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    antialias = lvf.rfs(
        out,
        lvf.sraa(out,
                 1.65,
                 9,
                 alpha=0.3,
                 beta=0.45,
                 gamma=240,
                 nrad=3,
                 mdis=25), [(opstart + 840, opstart + 881)])
    out = antialias

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)

    deband = dbs.f3kpf(out, 17, 42, 42)
    deband_b = placebo.deband(out, 22, 6, 2)
    deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)])

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

    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    # Fix random productions errors
    # AAAAAAAAAAAAARGHHHHHHHHHHHHHHH WHYYYY THE STUDIO DID THIS
    ncop = JPBD_NCOP.src_cut
    ncop = lvf.rfs(ncop,
                   depth(src, 8)[opstart:opend + 1], [(0, 79), (1035, 1037)])

    rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4)
    ref, rescale_mask, src, src_ncop, src_nced = [
        depth(x, 16)
        for x in [denoise, rescale_mask, src, ncop, JPBD_NCED.src_cut]
    ]

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask),
                     full_stuff)
    out = credit

    src_c, src_ncop, src_nced = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_ncop, src_nced]
    ]

    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           src_ncop[:opend - opstart + 1], opstart, opend, 4,
                           4).std.Inflate()
    ending_mask = vdf.dcm(out, src_c[edstart:edend + 1],
                          src_nced[:edend - edstart + 1], edstart, edend, 4,
                          4).std.Inflate()
    credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +')
    credit_mask = core.std.FreezeFrames(credit_mask, opstart + 1685,
                                        opstart + 1699, opstart + 1684)

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask),
                     [(opstart, opend), (edstart, edend)])
    out = credit

    return depth(out, 10)
Пример #11
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)
    src += src[-1]

    src = core.std.FreezeFrames(src, 3130, 3153, 3129)
    black = src.std.BlankClip().grain.Add(0.2)
    src = vdf.fade_filter(src, src, black, 3130, 3154)
    src = depth(src, 16)

    h = 882
    w = get_w(h)
    kernel = 'lanczos'
    taps = 5
    opstart, opend = 264, 2421
    edstart, edend = 31767, 33924


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



    luma = get_y(out)

    descale = kgf.get_descale_filter(kernel, taps=taps)(depth(luma, 32), w, h)
    upscale = vdf.fsrcnnx_upscale(depth(descale, 16), src.width, src.height, '_assets/shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  partial(core.resize.Bicubic, filter_param_a=0, filter_param_b=0))
    out = upscale



    unwarp = line_darkening(out, 0.275).warp.AWarpSharp2(depth=-2.5)
    sharp = hvf.LSFmod(unwarp, strength=90, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True)

    stabilize = stabilization(out, sharp, 2, 1, 8, 16)
    out = vdf.merge_chroma(stabilize, denoise)



    antialias = lvf.sraa(out, 1.4, rep=7, downscaler=core.resize.Bicubic)
    out = lvf.rfs(antialias, vdf.merge_chroma(upscale, denoise), [(edstart, edend)])



    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)

    deband = dbs.f3kpf(out, 17, 36, 36)
    deband_b = dbs.f3kpf(out, 17, 56, 56)
    deband = lvf.rfs(deband, out, [(3149, 3153)])
    deband = lvf.rfs(deband, deband_b, [(30213, 30422)])

    deband = core.std.MaskedMerge(deband, out, deband_mask)
    deband = core.neo_f3kdb.Deband(deband, preset='depth', grainy=24, grainc=18, keep_tv_range=True)
    out = deband




    grain = kgf.adaptive_grain(out, 0.2, luma_scaling=14)
    out = grain




    rescale_mask = vdf.drm(src, h, kernel, taps, mthr=40, sw=4, sh=4)
    creditless_mask = core.std.Expr([
        vdf.dcm(src, src[opstart:opend+1], JPBD_NCOP.src_cut[:opend-opstart+1],
                opstart, opend, 2, 2).std.Deflate(),
        vdf.dcm(src, src[edstart:edend+1], JPBD_NCED.src_cut[:edend-edstart+1],
                edstart, edend, 2, 2).std.Deflate()], 'x y +')

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, src, rescale_mask, 0),
                     [(opstart+425, opstart+698), (33971, src.num_frames-1)])
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, src, creditless_mask, 0),
                     [(opstart, opend), (edstart, edend)])
    credit = lvf.rfs(credit, src, [(7670, 7717), (20824, 20871), (26581, 26628)])
    out = credit


    return depth(out, 10)
Пример #12
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)

    h = 882
    w = get_w(h)
    kernel = 'lanczos'
    taps = 5
    opstart, opend = 1918, 4076
    edstart, edend = 31768, 33925

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

    luma = get_y(out)

    descale = kgf.get_descale_filter(kernel, taps=taps)(depth(luma, 32), w, h)
    upscale = vdf.fsrcnnx_upscale(
        depth(descale, 16), src.width, src.height,
        '_assets/shaders/FSRCNNX_x2_56-16-4-1.glsl',
        partial(core.resize.Bicubic, filter_param_a=0, filter_param_b=0))
    out = upscale

    import G41Fun as gf
    from vsTAAmbk import TAAmbk
    dehalo = gf.MaskedDHA(out,
                          rx=2.8,
                          ry=2.8,
                          darkstr=0.4,
                          brightstr=1.4,
                          maskpull=48,
                          maskpush=140)
    aaa = TAAmbk(dehalo, 'Eedi3SangNom', cycle=4, mtype=0)
    aaa = lvf.rfs(out, aaa, [(16052, 16105)])
    out = aaa

    unwarp = line_darkening(out, 0.275).warp.AWarpSharp2(depth=-2.5)
    sharp = hvf.LSFmod(unwarp,
                       strength=90,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)

    stabilize = stabilization(out, sharp, 2, 1, 8, 16)
    out = vdf.merge_chroma(stabilize, denoise)

    antialias = lvf.sraa(out, 1.4, rep=7, downscaler=core.resize.Bicubic)
    out = lvf.rfs(antialias, vdf.merge_chroma(upscale, denoise),
                  [(edstart, edend)])

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)

    deband = dbs.f3kpf(out, 17, 36, 36)

    deband = core.std.MaskedMerge(deband, out, deband_mask)
    deband = core.neo_f3kdb.Deband(deband,
                                   preset='depth',
                                   grainy=24,
                                   grainc=18,
                                   keep_tv_range=True)
    out = deband

    grain = kgf.adaptive_grain(out, 0.2, luma_scaling=14)
    out = grain

    rescale_mask = vdf.drm(src, h, kernel, taps, mthr=40, sw=4, sh=4)
    creditless_mask = core.std.Expr([
        vdf.dcm(src, src[opstart:opend + 1],
                JPBD_NCOP.src_cut[:opend - opstart + 1], opstart, opend, 2,
                2).std.Deflate(),
        vdf.dcm(src, src[edstart:edend + 1],
                JPBD_NCED.src_cut[:edend - edstart + 1], edstart, edend, 2,
                2).std.Deflate()
    ], 'x y +')

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, src, rescale_mask,
                                                  0),
                     [(opstart + 425, opstart + 698),
                      (33972, src.num_frames - 1), (21962, 22009)])
    credit = lvf.rfs(credit,
                     core.std.MaskedMerge(credit, src, creditless_mask, 0),
                     [(opstart, opend), (edstart, edend)])
    credit = lvf.rfs(credit, src, [(5057, 5104), (12371, 12418)])
    out = credit

    return depth(out, 10)
Пример #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])
Пример #14
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    # src += src[-1]
    src = depth(src, 16)
    out = src

    opstart, opend = 480, 2637
    edstart, edend = 32249, 34405



    # Remove the noise
    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    denoise = mvf.BM3D(out, sigma=[2, 1], radius1=1, ref=ref)
    out = denoise




    # Limited antialiasing
    y = get_y(out)
    lineart = core.std.Sobel(y).std.Binarize(75<<8).std.Maximum().std.Inflate()
    aa = lvf.sraa(y, 2, 13, downscaler=partial(core.resize.Bicubic, filter_param_a=-0.5, filter_param_b=0.25))
    sharp = hvf.LSFmod(aa, strength=70, Smode=3, edgemode=0, source=y)


    y = core.std.MaskedMerge(y, sharp, lineart)
    out = vdf.merge_chroma(y, out)






    # Deband masks
    planes = split(out)

    preden = core.dfttest.DFTTest(out, sigma=14.0, sigma2=10.0, sbsize=1, sosize=0).rgvs.RemoveGrain(3)
    grad_mask, yrangebig = morpho_mask(preden)


    rgb = core.resize.Bicubic(preden, 960, 540, format=vs.RGB48).std.SetFrameProp('_Matrix', delete=True)
    chroma_masks = [core.std.Prewitt(p).std.Binarize(5500).rgvs.RemoveGrain(11) for p in split(rgb) + split(preden)[1:]]
    chroma_mask = core.std.Expr(chroma_masks, 'x y + z + a + b +').std.Maximum()
    chroma_mask = core.std.Merge(chroma_mask, chroma_mask.std.Minimum()).std.BoxBlur(0, 1, 1, 1, 1)

    fdogmask = vdf.edge_detect(preden.std.Median(), 'FDOG', 8250, (4, 1)).std.BoxBlur(0, 2, 1, 2, 1)
    detail_mask = lvf.denoise.detail_mask(planes[0].std.BoxBlur(0, 1, 1, 1, 1), brz_a=3300, brz_b=2000)


    # Debanding stages
    debands = [None] * 3
    deband_y_strong = dbs.f3kbilateral(planes[0], 16, 65)
    deband_y_normal = dumb3kdb(planes[0], 16, 36)
    deband_y_light = core.std.MaskedMerge(dumb3kdb(planes[0], 14, 32), planes[0], detail_mask)
    debands[1] = dbs.f3kbilateral(planes[1], 12, 50)
    debands[2] = dbs.f3kbilateral(planes[2], 12, 50)


    debands[0] = core.std.MaskedMerge(deband_y_strong, deband_y_normal, grad_mask)
    debands[0] = core.std.MaskedMerge(debands[0], deband_y_light, yrangebig)
    debands[1], debands[2] = [core.std.MaskedMerge(debands[i], planes[i], chroma_mask) for i in range(1, 3)]
    deband = join(debands)
    deband = lvf.rfs(deband, core.std.MaskedMerge(dbs.f3kbilateral(out, 20, 97), out, fdogmask), [(opstart+2019, opstart+2036), (opstart+1504, opstart+1574)])
    out = deband


    # Regraining
    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 25)
    adgmask_b = core.adg.Mask(ref, 10)

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

    stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, 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, seed=333)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain



    # Credits OP and ED
    ref = src
    src_ncop, src_nced = [depth(c, 16) for c in [JPBD_NCOP.src_cut, JPBD_NCED.src_cut]]
    src_c, src_ncop, src_nced = [c.std.BoxBlur(0, 2, 1, 2, 1) for c in [src, src_ncop, src_nced]]

    opening_mask = vdf.dcm(out, src_c[opstart:opend+1], src_ncop[:opend-opstart+1], opstart, opend, 2, 2)
    ending_mask = vdf.dcm(out, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 2, 2)
    credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +').std.Inflate()

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask), [(opstart, opend), (edstart, edend)])
    out = credit





    # Fix letterboxes ending
    crop = core.std.Crop(out, 0, 0, 132, 132).edgefixer.ContinuityFixer(0, 1, 0, 0)
    crop = core.std.AddBorders(crop, 0, 0, 132, 132)
    out = lvf.rfs(out, crop, [(edstart, edend)])




    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2], [0, 1, 2])
Пример #15
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])
Пример #16
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')
    opstart, opend = 1392, 3788
    edstart, edend = 31889, src.num_frames - 1
    full_stuff = [(3801, 3908), (16203, 16358)]

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)
    upscale_smooth = vdf.nnedi3_upscale(descale, pscrn=1)
    upscale = lvf.rfs(upscale, upscale_smooth, [(18547, 18586)])

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)

    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    antialias = lvf.rfs(
        out,
        lvf.sraa(out,
                 1.65,
                 9,
                 alpha=0.3,
                 beta=0.45,
                 gamma=240,
                 nrad=3,
                 mdis=25), [(opstart + 840, opstart + 881)])
    out = antialias

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)

    deband = dbs.f3kpf(out, 17, 42, 42)
    deband_b = placebo.deband(out, 22, 6, 2)
    deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)])

    deband_c = placebo.deband(out, 17, 8, 3)
    import kagefunc
    deband_mask_c = kagefunc.retinex_edgemask(preden)
    deband_mask_c = iterate(deband_mask_c, core.std.Maximum,
                            3).std.Binarize(15000).std.Deflate()
    deband = lvf.rfs(deband,
                     core.std.MaskedMerge(deband_c, deband, deband_mask_c),
                     [(7409, 7600), (7960, 8055)])

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

    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4)
    ref, rescale_mask, src, src_ncop, src_nced = [
        depth(x, 16) for x in
        [denoise, rescale_mask, src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut]
    ]

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask),
                     full_stuff)
    out = credit

    src_c, src_ncop, src_nced = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_ncop, src_nced]
    ]

    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           src_ncop[:opend - opstart + 1], opstart, opend, 4,
                           4).std.Inflate()
    ending_mask = vdf.dcm(out, src_c[edstart:edend + 1],
                          src_nced[:edend - edstart + 1], edstart, edend, 4,
                          4).std.Inflate()
    credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +')

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask),
                     [(opstart, opend), (edstart, edend)])
    out = credit

    return depth(out, 10)
Пример #17
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src
    opstart, opend = 3106, 5263
    h = 720
    w = get_w(h)

    fixedges = awf.bbmod(out, 2, 2, 2, 2, 64 << 8, 999)
    out = fixedges

    decomb = hvf.Vinverse(out)
    decomb = lvf.rfs(out, decomb, [(10171, 10179)])
    ref = decomb
    out = decomb

    clean = core.knlm.KNLMeansCL(out,
                                 h=0.55,
                                 a=2,
                                 d=3,
                                 device_type='gpu',
                                 device_id=0,
                                 channels='UV')
    clean = core.knlm.KNLMeansCL(clean,
                                 h=0.55,
                                 a=2,
                                 d=3,
                                 device_type='gpu',
                                 device_id=0,
                                 channels='Y')
    diff_den = core.std.MakeDiff(out, clean)
    out = depth(clean, 32)

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, correct_shift=False,
                                 pscrn=1).resize.Bicubic(src.width,
                                                         src.height,
                                                         src_left=.5,
                                                         src_top=.5)
    rescale = core.std.MaskedMerge(luma, upscale, line_mask)

    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    moozzi = warping(out, 0.4, 4)
    sharp = hvf.LSFmod(moozzi,
                       strength=95,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

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

    grain_org = core.std.MergeDiff(out, diff_den)
    out = grain_org

    credit_mask = vdf.diff_rescale_mask(ref, mthr=40, sw=5, sh=5)
    credit_mask = vdf.region_mask(credit_mask, 10, 10, 10,
                                  10).std.Inflate().std.Inflate()
    antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic)
    credit = lvf.rfs(out, core.std.MaskedMerge(out, antialias, credit_mask),
                     [(10178, 10248), (21423, 22764)])

    out = credit

    src_c, ncop = [clip.std.Median() for clip in [src, JPBD_NCOP.src_cut]]
    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           ncop[:opend - opstart + 1], opstart, opend, 3,
                           3).std.Convolution([1] * 9)

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

    logo_mask = lvf.src('credit_mask_logo.png', out).std.Convolution([1] * 9)
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, logo_mask),
                     [(20992, 23225)])
    credit = lvf.rfs(credit, src, [(97766, src.num_frames - 1)])
    out = credit

    return depth(out, 10)
Пример #18
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import muvsfunc as muf
    import debandshit as dbs
    import vardefunc as vdf
    from vsutil import depth, get_y, insert_clip, join, plane

    src = JP_DVD.clip_cut.std.AssumeFPS(fpsnum=24000, fpsden=1001)
    src_ncop, src_nced = JP_BD_NCOP.clip_cut, JP_BD_NCED.clip_cut
    src_ncop = src_ncop + src_ncop[-1] * 11
    src_nced = src_nced + src_nced[-1]
    src_03 = JP_BD_03.clip_cut

    src_ncop = flt.rekt(src_ncop)
    src_nced = flt.rekt(src_nced)
    src_03 = flt.rekt(src_03)

    # Fixing an animation error in the NCOP
    sqmask_ncop = lvf.mask.BoundingBox((419, 827), (1500, 68))
    masked_ncop = core.std.MaskedMerge(src_ncop, src_03, sqmask_ncop.get_mask(src_ncop))
    masked_ncop = lvf.rfs(src_ncop, masked_ncop, [(opstart+2064, opstart+2107)])

    op_mask = vdf.dcm(
        src_03, src_03[opstart:opstart+masked_ncop.num_frames-op_offset], masked_ncop[:-op_offset],
        start_frame=opstart, thr=85, prefilter=True) if opstart is not False \
        else get_y(core.std.BlankClip(src))
    op_mask = depth(core.resize.Bicubic(op_mask, 1296, 728).std.Crop(top=4, bottom=4), 16)

    # Stick credits ontop of NC because it looks way better
    masked_ncop = src_ncop.resize.Bicubic(chromaloc_in=1, chromaloc=0)
    cwarp_ncop = masked_ncop.warp.AWarpSharp2(thresh=88, blur=3, type=1, depth=6, planes=[1, 2])
    descale_ncop = lvf.kernels.Bicubic().descale(plane(depth(src_ncop, 16), 0), 1280, 720)
    chroma_down_ncop = core.resize.Bicubic(cwarp_ncop, 1280, 720, vs.YUV444P16)
    scaled_ncop = join([descale_ncop, plane(chroma_down_ncop, 1), plane(chroma_down_ncop, 2)])
    scaled_ncop = scaled_ncop.resize.Bicubic(1296, 728).std.Crop(top=4, bottom=4)
    downscale_03 = src_03.resize.Bicubic(1296, 728, vs.YUV444P16).std.Crop(top=4, bottom=4)
    merge_credits_03 = core.std.MaskedMerge(scaled_ncop, downscale_03, op_mask)

    for prop, val in PROPS_DVD:
        src = src.std.SetFrameProp(prop, intval=val)

    dvd_i444 = vdf.scale.to_444(depth(src, 32), src.width, src.height, join_planes=True)
    dvd_rgb = dvd_i444.resize.Bicubic(format=vs.RGB24, dither_type='error_diffusion', matrix_in=6)

    upscale = vsgan.run(dvd_rgb)
    conv = core.resize.Bicubic(upscale, format=vs.YUV444P16, matrix=1)
    scaled = depth(muf.SSIM_downsample(conv, 1296, 720), 16)

    splice_op = lvf.rfs(scaled, merge_credits_03, [(0, 203), (263, 1740), (1836, 2018)])

    # Splicing for the ED. Halves of the ED have visuals, others are credits
    masked_nced = src_nced.resize.Bicubic(chromaloc_in=1, chromaloc=0)
    cwarp_nced = masked_nced.warp.AWarpSharp2(thresh=88, blur=3, type=1, depth=6, planes=[1, 2])
    descale_nced = lvf.kernels.Bicubic().descale(plane(depth(src_nced, 16), 0), 1280, 720)
    chroma_down_nced = core.resize.Bicubic(cwarp_nced, 1280, 720, vs.YUV444P16)
    scaled_nced = join([descale_nced, plane(chroma_down_nced, 1), plane(chroma_down_nced, 2)])
    scaled_nced = scaled_nced.resize.Bicubic(1296, 728).std.Crop(top=4, bottom=4)

    ed_nc = scaled_nced
    ed_dvd = splice_op[31888:]

    sq_top = lvf.mask.BoundingBox((0, 0), (ed_nc.width, ed_nc.height/2)).get_mask(ed_nc)
    sq_left = lvf.mask.BoundingBox((0, 0), (ed_nc.width/2, ed_nc.height)).get_mask(ed_nc)
    sq_right = sq_left.std.Invert()

    mask_top = core.std.MaskedMerge(ed_dvd, ed_nc, sq_top)
    mask_left = core.std.MaskedMerge(ed_dvd, ed_nc, sq_left)
    mask_right = core.std.MaskedMerge(ed_dvd, ed_nc, sq_right)

    ed_splice = lvf.rfs(ed_dvd, mask_top, [(0, 1213), (1613, 1673), (1794, None)])
    ed_splice = lvf.rfs(ed_splice, mask_left, [(1390, 1503)])
    ed_splice = lvf.rfs(ed_splice, mask_right, [(1214, 1389), (1504, 1612), (1674, 1793)])

    splice_ed = insert_clip(splice_op, ed_splice, edstart)

    # Back to more regular filtering
    stab = haf.GSMC(splice_ed, radius=2, planes=[0])
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=208 << 8, max_in=232 << 8)

    detail_mask = flt.detail_mask(decs, brz=(1800, 3500))
    deband = dbs.debanders.dumb3kdb(decs, threshold=32, grain=16)
    deband_masked = core.std.MaskedMerge(deband, decs, detail_mask)

    grain = vdf.noise.Graigasm(  # Mostly stolen from Varde tbh
        thrs=[x << 8 for x in (32, 80, 128, 176)],
        strengths=[(0.25, 0.0), (0.2, 0.0), (0.15, 0.0), (0.0, 0.0)],
        sizes=(1.2, 1.15, 1.05, 1),
        sharps=(65, 50, 40, 40),
        grainers=[
            vdf.noise.AddGrain(seed=69420, constant=True),
            vdf.noise.AddGrain(seed=69420, constant=False),
            vdf.noise.AddGrain(seed=69420, constant=False)
        ]).graining(deband_masked)

    return grain
Пример #19
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    ep10 = JPBD_10.src_cut

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')
    opstart, opend = 744, 3140
    opstart_ep10, opend_ep10 = 768, 3164
    full_stuff = [(3145, 3269), (18289, 18444), (29158, 33410)]

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 2),
                           right=1212)
    fixstudioshit = lvf.rfs(src, border, [31759])

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 6),
                           right=1212)
    fixstudioshit = lvf.rfs(fixstudioshit, border, [31760])

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 6),
                           right=1274)
    fixstudioshit = lvf.rfs(fixstudioshit, border, [(31761, 31762)])

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 6),
                           right=1300)
    fixstudioshit = lvf.rfs(fixstudioshit, border, [31763])

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 6),
                           right=1322)
    fixstudioshit = lvf.rfs(fixstudioshit, border, [31764])

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 6),
                           right=1342)
    fixstudioshit = lvf.rfs(fixstudioshit, border, [31765])

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 6),
                           right=1356)
    fixstudioshit = lvf.rfs(fixstudioshit, border, [31766])

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 6),
                           right=1368)
    fixstudioshit = lvf.rfs(fixstudioshit, border, [31767])

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 6),
                           right=1376)
    fixstudioshit = lvf.rfs(fixstudioshit, border, [31768])

    border = rkt.rekt_fast(src,
                           lambda x: core.fb.FillBorders(x, 0, 0, 0, 6),
                           right=1382)
    fixstudioshit = lvf.rfs(fixstudioshit, border, [(31769, 31793)])

    src = fixstudioshit

    # Fix compositing error in the OP
    op_src, op_10 = src[opstart:opend + 1], ep10[opstart_ep10:opend_ep10 + 1]
    fix = lvf.rfs(op_src, op_10, [(0, 79), (1035, 1037)])
    fix_src = insert_clip(src, fix, opstart)
    src = depth(fix_src, 32)

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)

    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    antialias = lvf.rfs(
        out,
        lvf.sraa(out,
                 1.65,
                 9,
                 alpha=0.3,
                 beta=0.45,
                 gamma=240,
                 nrad=3,
                 mdis=25), [(opstart + 840, opstart + 881)])
    out = antialias

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)

    deband = dbs.f3kpf(out, 17, 42, 42)
    deband_b = placebo.deband(out, 22, 6, 2)
    deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)])

    deband_c = placebo.deband(out, 17, 6, 3)
    deband = lvf.rfs(deband, deband_c, [(12529, 12615)])

    deband_d = placebo.deband(out, 10, 3, 1)
    deband = lvf.rfs(deband, deband_d, [(21077, 21304), (22141, 22278),
                                        (22861, 22944), (29354, 29425),
                                        (33555, 33614)])

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

    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4)
    ref, rescale_mask, src, src_ncop = [
        depth(x, 16) for x in [denoise, rescale_mask, src, JPBD_NCOP.src_cut]
    ]

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask),
                     full_stuff)
    out = credit

    src_c, src_ncop = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_ncop]
    ]

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

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

    return depth(out, 10)
Пример #20
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)

    h = 882
    w = get_w(h)
    kernel = 'lanczos'
    taps = 5
    opstart, opend = 936, 3092
    edstart, edend = 31769, 33926

    clip_in = depth(src, 32)
    dedimm = gf.Tweak(clip_in, sat=1.65, cont=1.65)
    dedimm = vdf.fade_filter(clip_in, clip_in, dedimm, 26133, 26183)
    out = depth(dedimm, 16)

    denoise = CoolDegrain(out, tr=1, thsad=24, blksize=8, overlap=4, plane=4)
    out = denoise

    luma = get_y(out)

    descale = kgf.get_descale_filter(kernel, taps=taps)(depth(luma, 32), w, h)
    upscale = vdf.fsrcnnx_upscale(
        depth(descale, 16), src.width, src.height,
        '_assets/shaders/FSRCNNX_x2_56-16-4-1.glsl',
        partial(core.resize.Bicubic, filter_param_a=0, filter_param_b=0))
    out = upscale

    unwarp = line_darkening(out, 0.275).warp.AWarpSharp2(depth=-2.5)
    sharp = hvf.LSFmod(unwarp,
                       strength=90,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)

    stabilize = stabilization(out, sharp, 2, 1, 8, 16)
    out = vdf.merge_chroma(stabilize, denoise)

    antialias = lvf.sraa(out, 1.4, rep=7, downscaler=core.resize.Bicubic)
    out = lvf.rfs(antialias, vdf.merge_chroma(upscale, denoise),
                  [(edstart, edend)])

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)

    deband = dbs.f3kpf(out, 17, 30, 30)

    deband = core.std.MaskedMerge(deband, out, deband_mask)
    deband = core.neo_f3kdb.Deband(deband,
                                   preset='depth',
                                   grainy=24,
                                   grainc=18,
                                   keep_tv_range=True)
    out = deband

    grain = kgf.adaptive_grain(out, 0.2, luma_scaling=14)
    out = grain

    rescale_mask = vdf.drm(src, h, kernel, taps, mthr=40, sw=4, sh=4)
    creditless_mask = core.std.Expr([
        vdf.dcm(src, src[opstart:opend + 1],
                JPBD_NCOP.src_cut[:opend - opstart + 1], opstart, opend, 2,
                2).std.Deflate(),
        vdf.dcm(src, src[edstart:edend + 1],
                JPBD_NCED.src_cut[:edend - edstart + 1], edstart, edend, 2,
                2).std.Deflate()
    ], 'x y +')

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, src, rescale_mask,
                                                  0),
                     [(opstart + 425, opstart + 698),
                      (33973, src.num_frames - 1)])
    credit = lvf.rfs(credit,
                     core.std.MaskedMerge(credit, src, creditless_mask, 0),
                     [(opstart, opend), (edstart, edend)])
    credit = lvf.rfs(credit, src, [(16911, 16970), (24486, 24533)])
    out = credit

    return depth(out, 10)
Пример #21
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 _line_mask(clip: vs.VideoNode, thr: int) -> vs.VideoNode:
        mask = core.std.Prewitt(clip)
        mask = core.std.Expr(mask, 'x 2 *').std.Median()
        mask = core.std.Expr(mask, f'x {thr} < x x 3 * ?')
        return mask.std.Inflate().std.Deflate()

    def _ssharp(clip: vs.VideoNode,
                strength: float,
                width: int,
                height: int,
                factor: float = 2,
                b: float = -1,
                c: float = 6) -> vs.VideoNode:
        source = clip
        sharp = core.resize.Bicubic(clip, clip.width*factor, clip.height*factor, \
            filter_param_a=b, filter_param_b=c).resize.Lanczos(width, height)

        source = core.resize.Spline64(source, sharp.width, sharp.height)

        sharp = core.rgvs.Repair(sharp, source, 13)
        sharp = mvf.LimitFilter(source,
                                sharp,
                                thrc=0.5,
                                elast=6,
                                brighten_thr=0.5,
                                planes=0)

        final = core.std.Expr([sharp, source],
                              f'x {strength} * y 1 {strength} - * +')
        return final

    def to_gray(clip: vs.VideoNode, ref: vs.VideoNode) -> vs.VideoNode:
        clip = core.std.AssumeFPS(clip, ref)
        return core.resize.Point(clip,
                                 format=vs.GRAY16,
                                 matrix_s=mvf.GetMatrix(ref))

    def _perform_masks_credit(path: Path) -> List[MaskCredit]:
        return [
            MaskCredit(lvf.src(str(mask)), int(str(mask.stem).split('_')[2]),
                       int(str(mask.stem).split('_')[3]))
            for mask in path.glob('*')
        ]

    def _w2x(clip: vs.VideoNode) -> vs.VideoNode:
        waifu2x = core.w2xc.Waifu2x(mvf.ToRGB(clip, depth=32), noise=2, scale=2) \
            .resize.Bicubic(clip.width, clip.height)
        return mvf.ToYUV(waifu2x, css='420', depth=16)

    def _perform_filtering_ending(clip: vs.VideoNode,
                                  adapt_mask: vs.VideoNode) -> vs.VideoNode:
        luma = get_y(clip)
        denoise_a = mvf.BM3D(luma, 2.25, 1)
        denoise_b = mvf.BM3D(luma, 1.25, 1)
        denoise = core.std.MaskedMerge(denoise_a, denoise_b, adapt_mask)
        grain = core.grain.Add(denoise, 0.3, constant=True)
        return core.std.MaskedMerge(denoise, grain, adapt_mask)

    # pylint: disable=unused-argument
    def _diff(n: int, f: vs.VideoFrame, new: vs.VideoNode,
              adapt: vs.VideoNode) -> vs.VideoNode:
        psa = f.props['PlaneStatsAverage']
        if psa > 0.5:
            clip = new
        elif psa < 0.4:
            clip = adapt
        else:
            weight = (psa - 0.4) * 10
            clip = core.std.Merge(adapt, new, weight)
        return clip

    def aa_stonks(clip: vs.VideoNode) -> vs.VideoNode:
        mask = core.std.Prewitt(get_y(clip)).std.Binarize(4000)
        mask = iterate(mask, core.std.Maximum, 4)
        mask = iterate(mask, core.std.Minimum, 2)
        mask = iterate(mask, core.std.Deflate, 4)
        mask = vdf.region_mask(mask, 400, 400, 0, 0)

        descale = core.descale.Debicubic(depth(get_y(clip), 32), 1440, 810)
        upscale = core.caffe.Waifu2x(descale, 3, 2, model=6)
        downscale = core.descale.Debilinear(upscale, 1920, 1080)
        merged = vdf.merge_chroma(depth(downscale, 16), clip)
        merged = core.std.MaskedMerge(clip, merged, mask)

        return core.warp.AWarpSharp2(merged, 128, 2, depth=16)

    opstart, opend = 1272, 3428
    edstart, edend = 31769, 33926
    src = JPBD.src_cut
    src = depth(src, 16)
    src = core.std.FreezeFrames(src, opstart + 2132, opend, opstart + 2132)

    denoise = mdf.hybriddenoise_mod(src, 0.55, 2.25)
    diff = core.std.MakeDiff(src, denoise, [0, 1, 2])

    luma = get_y(denoise)

    upscale = _nnedi3(luma, 1.5, dict(nsize=0, nns=3, qual=1, pscrn=1))
    sraa = _sraa(upscale, dict(nsize=0, nns=3, qual=1, pscrn=1),
                 dict(alpha=0.2, beta=0.5, gamma=80, nrad=3, mdis=18))
    sraa = core.rgvs.Repair(sraa, upscale, 3)
    rescale = _ssharp(sraa, 0.55, src.width, src.height, 2)

    artefacts_mask = core.std.BlankClip(rescale, color=(256 << 8) - 1)
    artefacts_mask = vdf.region_mask(artefacts_mask, 2, 2, 2, 2).std.Inflate()
    rescale = core.std.MaskedMerge(luma, rescale, artefacts_mask)

    lineart_mask = _line_mask(luma, 8000)
    antialias = core.std.MaskedMerge(luma, rescale, lineart_mask)

    antialias_merged = vdf.merge_chroma(antialias, denoise)

    antialias_strong_a = aa_stonks(denoise)
    antialias_strong_b = TAAmbk(denoise, 'Eedi3', cycle=3, mtype=0)
    antialias_merged = lvf.rfs(antialias_merged, antialias_strong_a,
                               [(4782, 4785)])
    antialias_merged = lvf.rfs(antialias_merged, antialias_strong_b,
                               [(11808, 11898)])

    src_c, src_ncop = [
        c.knlm.KNLMeansCL(a=6, h=20, d=0, device_type='gpu')
        for c in [src, JPBD_NCOP.src_cut[:opend - opstart + 1]]
    ]
    credit_mask = vdf.dcm(src, src_c[opstart:opend + 1], src_ncop, opstart,
                          opend, 2, 2).std.Deflate()
    credit = core.std.MaskedMerge(antialias_merged, denoise, credit_mask)

    masks_credit_ = _perform_masks_credit(Path('masks_' + JPBD.name[-2:] +
                                               '/'))

    for mask in masks_credit_:
        credit = lvf.rfs(
            credit,
            core.std.MaskedMerge(credit, denoise,
                                 to_gray(mask.mask, src).std.Deflate()),
            [(mask.start_frame, mask.end_frame)])

    deband_mask = lvf.denoise.detail_mask(credit, brz_a=3000, brz_b=1500)
    deband_a = dbs.f3kpf(credit, 18, 36, 36)
    deband_b = dbs.f3kpf(credit, 18, 42, 42)
    deband_c = placebo.Deband(credit,
                              radius=16,
                              threshold=4,
                              iterations=1,
                              grain=0)
    deband_d = placebo.Deband(deband_b,
                              radius=20,
                              threshold=5,
                              iterations=1,
                              grain=0)
    deband = lvf.rfs(deband_a, deband_b, [(opstart, opstart + 146)])
    deband = lvf.rfs(deband, deband_c, [(opstart + 1225, opstart + 1238)])
    deband = lvf.rfs(deband, deband_d, [(opstart + 970, opstart + 984)])
    deband = core.std.MaskedMerge(deband, credit, deband_mask)

    grain_original = core.std.MergeDiff(deband, diff, [0, 1, 2])
    grain_new = core.neo_f3kdb.Deband(deband,
                                      preset='depth',
                                      grainy=32,
                                      grainc=32)
    avg = core.std.PlaneStats(deband)
    adapt_mask = core.adg.Mask(get_y(avg), 28)
    grain_adapt = core.std.MaskedMerge(grain_new, grain_original, adapt_mask)

    grain = core.std.FrameEval(
        deband, partial(_diff, new=grain_new, adapt=grain_adapt), avg)

    grain = lvf.rfs(grain, grain_new, [(opstart + 147, opstart + 496),
                                       (opstart + 575, opstart + 644),
                                       (opstart + 702, opstart + 969),
                                       (opstart + 1076, opstart + 1117),
                                       (opstart + 1428, opstart + 1461),
                                       (opstart + 1859, opstart + 2035)])
    grain = lvf.rfs(grain, grain_original, [(14412, 14728), (31146, 31299)])

    w2x = _w2x(denoise).grain.Add(1, 0.5, constant=True)
    w2x = lvf.rfs(grain, w2x, [(opstart + 1211, opstart + 1224)])

    ending = _perform_filtering_ending(src, adapt_mask)
    ending = vdf.merge_chroma(ending, denoise)
    final = lvf.rfs(w2x, ending, [(edstart, edend)])

    return depth(final, 10)
Пример #22
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = src.std.SetFrameProp('_Matrix', intval=1)

    # Variables
    edstart, edend = 165528, src.num_frames-1
    h = 844
    w = get_w(h)


    edges_a = core.edgefixer.ContinuityFixer(src, *[[1, 0, 0]]*4)
    edges_b = core.edgefixer.ContinuityFixer(src, [0, 0, 0], [1, 0, 0], [0, 0, 0], [1, 0, 0])
    edges = lvf.rfs(edges_a, edges_b, [(8900, 9001)])
    out = depth(edges, 32)


    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=300)
    denoise = hybrid_denoise(out, 0.25, 1.05, dict(a=2, d=1), dict(ref=depth(ref, 32)))
    out = denoise



    y = get_y(out)
    lineart = vdf.edge_detect(y, 'FDOG', 0.065, (1, 1)).std.Median().std.BoxBlur(0, 1, 1, 1, 1)


    descale_clips = [core.resize.Bicubic(y, w, h, filter_param_a=1/3, filter_param_b=1/3),
                     core.descale.Debicubic(y, w, h, 0, 1/2),
                     core.descale.Debicubic(y, w, h, 1/3, 1/3)]
    descale = core.std.Expr(descale_clips, 'x y z min max y z max min z min')
    descale_bcsharp = core.descale.Debicubic(y, get_w(842), 842, 0, 1)
    descale_bcsharp = gf.MaskedDHA(depth(descale_bcsharp, 16), rx=1.4, ry=1.4, darkstr=0.05, brightstr=1.0, maskpull=48, maskpush=140)


    upsc_args = dict(shader_file='shaders/FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='zastin',
                     sharpener=partial(gf.DetailSharpen, sstr=1.65, power=4, mode=0, med=True))

    upscale = vdf.fsrcnnx_upscale(descale, height=h*2, **upsc_args)
    antialias = sraa_eedi3(upscale, 3, alpha=0.2, beta=0.4, gamma=100, mdis=20, nrad=3)
    downscale_a = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic', filter_param_a=0, filter_param_b=0)


    upscale = eedi3_upscale(descale_bcsharp)
    antialias = sraa_eedi3(depth(upscale, 32), 3, alpha=0.2, beta=0.4, gamma=100, mdis=20, nrad=3)
    downscale_b = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic', filter_param_a=0, filter_param_b=0)



    downscale = lvf.rfs(downscale_a, downscale_b, [(52931, 53004), (53459, 53696), (54218, 54441),
                                                   (55137, 55254), (55420, 55570)])
    scaled = core.std.MaskedMerge(y, downscale, lineart)

    merged = vdf.merge_chroma(scaled, out)
    out = depth(merged, 16)



    crop = core.std.Crop(out, left=4, right=2)
    fb = core.fb.FillBorders(crop, 1, 1, 0, 0, mode="fillmargins")
    resize = core.resize.Bicubic(fb, 1920)
    out = lvf.rfs(out, resize, [(8900, 9001)])



    detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200)

    deband = dumb3kdb(out, 16, 42)
    deband = core.std.MaskedMerge(deband, out, detail_light_mask)
    out = deband





    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 30)
    adgmask_b = core.adg.Mask(ref, 12)

    stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80, static=True)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain




    ref = depth(src, 16)
    src_c, src_nced = [c.std.BoxBlur(0, 1, 1, 1, 1) for c in [src, JPBD_NCED.src_cut]]
    creditless_mask = vdf.dcm(ref, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 3, 3).std.Deflate()
    rescale_mask = vdf.drm(ref, h, b=1/3, c=1/3, mthr=30)
    rescale_mask = vdf.region_mask(rescale_mask, 20, 20, 20, 20).std.Binarize(6000).std.Maximum().std.Maximum().std.Inflate()

    credit = out
    credit = lvf.rfs(credit, ref, [(0, 672)])
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, creditless_mask, 0), [(edstart, edend)])
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask[5602], 0), [(5561, 5752)])
    out = credit


    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2])
Пример #23
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src
    if out.num_frames < 34046:
        while out.num_frames != 34046:
            out += out[-1]
    opstart, opend = 0, 2157
    h = 720
    w = get_w(h)


    fixedges = awf.bbmod(out, 2, 2, 2, 2, 64<<8, 999)
    out = fixedges


    decomb = hvf.Vinverse(out)
    decomb = lvf.rfs(out, decomb, [(2187, 2195)])
    ref = decomb
    out = decomb

    from adptvgrnMod import adptvgrnMod
    first_denoise = hybrid_denoise(out, 0.35, 1.5)
    regrain = adptvgrnMod(first_denoise, 0.275, 0.175, 1.25, 45)
    regrain = lvf.rfs(out, regrain, [(28691, 28818)])
    out = regrain


    clean = core.knlm.KNLMeansCL(out, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='UV')
    clean = core.knlm.KNLMeansCL(clean, h=0.55, a=2, d=3, device_type='gpu', device_id=0, channels='Y')
    diff_den = core.std.MakeDiff(out, clean)
    out = depth(clean, 32)



    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, correct_shift=False, pscrn=1).resize.Bicubic(src.width, src.height, src_left=.5, src_top=.5)
    rescale = core.std.MaskedMerge(luma, upscale, line_mask)

    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)


    moozzi = warping(out, 0.4, 4)
    sharp = hvf.LSFmod(moozzi, strength=95, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True)
    out = sharp


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


    grain_org = core.std.MergeDiff(out, diff_den)
    out = grain_org


    credit_mask = vdf.diff_rescale_mask(ref, mthr=40, sw=5, sh=5)
    credit_mask = vdf.region_mask(credit_mask, 10, 10, 10, 10).std.Inflate().std.Inflate()
    antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic)
    credit = lvf.rfs(out, core.std.MaskedMerge(out, antialias, credit_mask),
                     [(2188, 2305), (33926, src.num_frames-1)])
    credit = lvf.rfs(credit, core.std.MaskedMerge(out, ref, credit_mask), [(31684, 33925)])

    out = credit


    src_c, ncop = [clip.std.Median() for clip in [src, JPBD_NCOP.src_cut]]
    opening_mask = vdf.dcm(out, src_c[opstart:opend+1], ncop[:opend-opstart+1], opstart, opend, 3, 3)
    credit_mask = opening_mask.std.Convolution([1]*9)

    credit = lvf.rfs(out, core.std.MaskedMerge(out, src, credit_mask), [(opstart, opend)])
    out = credit


    return depth(out, 10)
Пример #24
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Regular VapourSynth filterchain"""
    import lvsfunc as lvf
    import vardefunc as vdf
    from vsutil import depth, get_y

    src, *_ = trim()
    src_CR = JP_CR.clip_cut
    src_NCOP, src_NCED = YT_NCOP.clip, YT_NCED.clip
    b = core.std.BlankClip(src, length=1)

    # OP/ED stack comps to check that it lines up
    op_scomp = lvf.scomp(src[opstart:opstart + src_NCOP.num_frames - 1] + b,
                         src_NCOP[:-op_offset] + b)  # noqa
    ed_scomp = lvf.scomp(src[edstart:edstart + src_NCED.num_frames - 1] + b,
                         src_NCED[:-ed_offset] + b)  # noqa

    # Blurring clips
    blur_src = core.bilateral.Gaussian(src, sigma=2.5)
    blur_NCOP = core.bilateral.Gaussian(src_NCOP, sigma=2.5)
    blur_NCED = core.bilateral.Gaussian(src_NCED, sigma=2.5)

    # Masking credits
    op_mask = vdf.dcm(
        blur_src, blur_src[opstart:opstart+src_NCOP.num_frames-op_offset], blur_NCOP[:-op_offset],
        start_frame=opstart, thr=28, prefilter=False) if opstart is not False \
        else get_y(core.std.BlankClip(src))
    ed_mask = vdf.dcm(
        blur_src, blur_src[edstart:edstart+src_NCED.num_frames-ed_offset], blur_NCED[:-ed_offset],
        start_frame=edstart, thr=25, prefilter=False) if edstart is not False \
        else get_y(core.std.BlankClip(src))
    credit_mask = core.std.Expr([op_mask, ed_mask], expr='x y +')
    credit_mask = depth(credit_mask, 16).std.Binarize()

    # This time, AoD has better lines but worse gradients (over-debanded + super grained),
    # but only on certain dark and texture-heavy (but low-motion) scenes, but ugh effort
    src = depth(src, 16)
    line_mask = vdf.mask.FDOG().get_mask(get_y(src))
    src_merge = core.std.MaskedMerge(depth(src_CR, 16), src, line_mask)
    src_merge = lvf.rfs(src, src_merge, [(2637, 2722), (10933, 10978),
                                         (11388, 11479), (13058, 13406),
                                         (13539, 14029), (14052, 14300),
                                         (14422, 14560)])

    src_merge = depth(src_merge, 16)

    src_y = get_y(src_merge)
    denoise_y = flt.bm3d_ref(src_y,
                             bm3d_sigma=1,
                             dec_sigma=8,
                             dec_min=192 << 8)
    denoise_y = core.std.MaskedMerge(denoise_y, src_y, line_mask)
    merged = vdf.misc.merge_chroma(denoise_y, src)

    dehalo = flt.bidehalo(merged, sigma=1, mask_args={'brz': 0.25})

    cmerged = core.std.MaskedMerge(dehalo, src, credit_mask)

    deband = flt.masked_f3kdb(cmerged,
                              thr=20,
                              grain=12,
                              mask_args={'brz': (1500, 3500)})
    grain = flt.default_grain(deband)

    return grain  # type: ignore
Пример #25
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src += src[-1]
    ep10 = JPBD_10.src_cut

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')
    opstart, opend = 2973, 5370
    edstart, edend = 31887, src.num_frames - 1
    opstart_ep10, opend_ep10 = 768, 3164
    full_stuff = [(5449, 5580), (16465, 16620)]

    # Fix compositing error in the OP
    op_src, op_10 = src[opstart:opend + 1], ep10[opstart_ep10:opend_ep10 + 1]
    fix = lvf.rfs(op_src, op_10, [(0, 79), (1035, 1037)])
    fix_src = insert_clip(src, fix, opstart)
    src = depth(fix_src, 32)

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)

    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    antialias = lvf.rfs(
        out,
        lvf.sraa(out,
                 1.65,
                 9,
                 alpha=0.3,
                 beta=0.45,
                 gamma=240,
                 nrad=3,
                 mdis=25), [(opstart + 840, opstart + 881)])
    out = antialias

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)

    deband = dbs.f3kpf(out, 17, 42, 42)
    deband_b = placebo.deband(out, 22, 6, 2)
    deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)])

    deband_c = placebo.deband(deband, 17, 5, 1)
    deband_c = dbs.f3kbilateral(deband_c, 22, 64, 64)
    deband = lvf.rfs(deband, deband_c, [(15612, 15695)])

    deband_mask2 = vdf.edge_detect(
        out.knlm.KNLMeansCL(d=2, a=2, h=0.4, device_type='GPU', channels='Y'),
        'FDOG', 1100, (8, 1))
    deband_mask2 = iterate(deband_mask2, core.std.Deflate, 4)
    deband_d = placebo.deband(out, 16, 12, 3)
    deband_d = core.std.MaskedMerge(deband_d, out, deband_mask2)
    deband = lvf.rfs(deband, deband_d, [(16339, 16542)])

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

    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4)
    ref, rescale_mask, src, src_ncop, src_nced = [
        depth(x, 16) for x in
        [denoise, rescale_mask, src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut]
    ]

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask),
                     full_stuff)
    out = credit

    src_c, src_ncop, src_nced = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_ncop, src_nced]
    ]

    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           src_ncop[:opend - opstart + 1], opstart, opend, 4,
                           4).std.Inflate()
    ending_mask = vdf.dcm(out, src_c[edstart:edend + 1],
                          src_nced[:edend - edstart + 1], edstart, edend, 4,
                          4).std.Inflate()
    credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +')

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask),
                     [(opstart, opend), (edstart, edend)])
    out = credit

    return depth(out, 10)
Пример #26
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    ep10 = JPBD_10.src_cut

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')
    opstart, opend = 672, 3068
    edstart, edend = 31888, src.num_frames - 1
    opstart_ep10, opend_ep10 = 768, 3164
    full_stuff = [(3853, 3984), (16130, 16279)]

    # Fix borders of the henshin
    start, end = 26596, 27387
    white_clip = core.std.BlankClip(src, color=[235, 128, 128])

    # Good length for the three henshins
    hibiki = TRANSFOS.src_cut[912:1716]
    hibiki = core.std.DeleteFrames(hibiki, [203, 204])
    hibiki = core.std.DeleteFrames(hibiki, range(316, 320))
    hibiki = core.std.DeleteFrames(hibiki, range(391, 394))

    tsubasa = TRANSFOS.src_cut[2178:2738]
    tsubasa = core.std.DuplicateFrames(white_clip[:8] + tsubasa, range(10, 20))
    tsubasa = core.std.DuplicateFrames(tsubasa, range(196, 203))
    tsubasa = core.std.DuplicateFrames(tsubasa, [443, 443, 443])

    yukine = TRANSFOS.src_cut[3240:3828]

    # The intro
    intro = 203
    new_tranfos = hibiki[:intro]

    # Adjust croppings
    hibiki_crop_a = core.std.Crop(hibiki[intro:], src.width / 3, src.width / 3,
                                  0, 0)
    dev = -150
    hibiki_crop_b = core.std.Crop(hibiki[intro:], src.width / 3 + dev,
                                  src.width / 3 - dev, 0, 0)
    dev = -270
    hibiki_crop_c = core.std.Crop(hibiki[intro:], src.width / 3 + dev,
                                  src.width / 3 - dev, 0, 0)
    hibiki_crop = lvf.rfs(hibiki_crop_a, hibiki_crop_b,
                          [(391 - intro, 471 - intro)])
    hibiki_crop = lvf.rfs(hibiki_crop, hibiki_crop_c,
                          [(472 - intro, 552 - intro)])

    tsubasa_crop_a = core.std.Crop(tsubasa, src.width / 3, src.width / 3, 0, 0)
    dev = -400
    tsubasa_crop_b = core.std.Crop(tsubasa, src.width / 3 + dev,
                                   src.width / 3 - dev, 0, 0)
    tsubasa_crop = lvf.rfs(tsubasa_crop_a, tsubasa_crop_b,
                           [(445 - intro, 460 - intro)])
    tsubasa_crop = (tsubasa_crop[:461 - intro] + core.std.FrameEval(
        tsubasa_crop[461 - intro:478 - intro],
        partial(_prog_crop, clip=tsubasa[461 - intro:478 - intro], dev=dev)) +
                    tsubasa_crop[478 - intro:])

    yukine_crop = core.std.Crop(yukine, src.width / 3, src.width / 3, 0, 0)

    # Stack & merge
    new_tranfos += core.std.StackHorizontal(
        [tsubasa_crop, hibiki_crop, yukine_crop])
    src = insert_clip(src, new_tranfos[:end - start], start)

    # Fix compositing error in the OP
    op_src, op_10 = src[opstart:opend + 1], ep10[opstart_ep10:opend_ep10 + 1]
    fix = lvf.rfs(op_src, op_10, [(0, 79), (1035, 1037)])
    fix_src = insert_clip(src, fix, opstart)
    src = depth(fix_src, 32)

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)
    upscale_smooth = vdf.nnedi3_upscale(descale, pscrn=1)
    upscale = vdf.fade_filter(upscale, upscale, upscale_smooth, 18018, 18068)
    upscale = lvf.rfs(upscale, upscale_smooth, [(18068, 18134)])

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)

    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    antialias = lvf.rfs(
        out,
        lvf.sraa(out,
                 1.65,
                 9,
                 alpha=0.3,
                 beta=0.45,
                 gamma=240,
                 nrad=3,
                 mdis=25), [(opstart + 840, opstart + 881)])
    antialias_a = lvf.sraa(out,
                           1.3,
                           3,
                           alpha=0.3,
                           beta=0.45,
                           gamma=40,
                           nrad=3,
                           mdis=25)
    antialias_b = lvf.sraa(out,
                           1.85,
                           13,
                           alpha=0.3,
                           beta=0.6,
                           gamma=400,
                           nrad=2,
                           mdis=15)
    antialias = vdf.fade_filter(antialias, antialias_a, antialias_b, 12718,
                                12861)
    antialias = lvf.rfs(antialias, antialias_b, [(24063, 24149)])
    out = antialias

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)

    deband = dbs.f3kpf(out, 17, 42, 42)
    deband_b = placebo.deband(out, 22, 6, 2)
    deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)])

    deband_c = placebo.deband(out, 10, 3, 1)
    deband = lvf.rfs(deband, deband_c, [(241, 300), (11076, 11183)])

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

    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4)
    ref, rescale_mask, src, src_ncop, src_nced = [
        depth(x, 16) for x in
        [denoise, rescale_mask, src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut]
    ]

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask),
                     full_stuff)
    out = credit

    src_c, src_ncop, src_nced = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_ncop, src_nced]
    ]

    opening_mask = vdf.dcm(out, src_c[opstart:opend + 1],
                           src_ncop[:opend - opstart + 1], opstart, opend, 4,
                           4).std.Inflate()
    ending_mask = vdf.dcm(out, src_c[edstart:edend + 1],
                          src_nced[:edend - edstart + 1], edstart, edend, 4,
                          4).std.Inflate()
    credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +')

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask),
                     [(opstart, opend), (edstart, edend)])
    out = credit

    return depth(out, 10)
Пример #27
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 _line_mask(clip: vs.VideoNode, thr: int) -> vs.VideoNode:
        mask = core.std.Prewitt(clip)
        mask = core.std.Expr(mask, 'x 2 *').std.Median()
        mask = core.std.Expr(mask, f'x {thr} < x x 3 * ?')
        return mask.std.Inflate().std.Deflate()

    def _ssharp(clip: vs.VideoNode,
                strength: float,
                width: int,
                height: int,
                factor: float = 2,
                b: float = -1,
                c: float = 6) -> vs.VideoNode:
        source = clip
        sharp = core.resize.Bicubic(clip, clip.width*factor, clip.height*factor, \
            filter_param_a=b, filter_param_b=c).resize.Lanczos(width, height)

        source = core.resize.Spline64(source, sharp.width, sharp.height)

        sharp = core.rgvs.Repair(sharp, source, 13)
        sharp = mvf.LimitFilter(source,
                                sharp,
                                thrc=0.5,
                                elast=6,
                                brighten_thr=0.5,
                                planes=0)

        final = core.std.Expr([sharp, source],
                              f'x {strength} * y 1 {strength} - * +')
        return final

    def to_gray(clip: vs.VideoNode, ref: vs.VideoNode) -> vs.VideoNode:
        clip = core.std.AssumeFPS(clip, ref)
        return core.resize.Point(clip,
                                 format=vs.GRAY16,
                                 matrix_s=mvf.GetMatrix(ref))

    def _perform_masks_credit(path: Path) -> List[MaskCredit]:
        return [
            MaskCredit(lvf.src(str(mask)), int(str(mask.stem).split('_')[2]),
                       int(str(mask.stem).split('_')[3]))
            for mask in path.glob('*')
        ]

    # pylint: disable=unused-argument
    def _diff(n: int, f: vs.VideoFrame, new: vs.VideoNode,
              adapt: vs.VideoNode) -> vs.VideoNode:
        psa = f.props['PlaneStatsAverage']
        if psa > 0.5:
            clip = new
        elif psa < 0.4:
            clip = adapt
        else:
            weight = (psa - 0.4) * 10
            clip = core.std.Merge(adapt, new, weight)
        return clip

    def _ret_mask(clip: vs.VideoNode, thr: int) -> vs.VideoNode:
        mask = kgf.retinex_edgemask(clip)
        mask = core.std.Median(mask).std.Binarize(thr)
        mask = iterate(mask, core.std.Median, 2)
        mask = iterate(mask, core.std.Maximum, 3)
        mask = iterate(mask, core.std.Minimum, 2)
        return mask

    opstart, opend = 1774, 3944
    edstart, edend = 31781, 33938
    src = JPBD.src_cut
    src = depth(src, 16)

    denoise_a = mdf.hybriddenoise_mod(src, 0.55, 2.25)
    denoise_b = mdf.hybriddenoise_mod(src, 0.55, 10)
    denoise = lvf.rfs(denoise_a, denoise_b, [(opstart, opstart + 44)])
    diff = core.std.MakeDiff(src, denoise, [0, 1, 2])

    luma = get_y(denoise)

    upscale = _nnedi3(luma, 1.5, dict(nsize=0, nns=3, qual=1, pscrn=1))
    sraa = _sraa(upscale, dict(nsize=0, nns=3, qual=1, pscrn=1),
                 dict(alpha=0.2, beta=0.5, gamma=80, nrad=3, mdis=18))
    sraa = core.rgvs.Repair(sraa, upscale, 3)
    rescale = _ssharp(sraa, 0.55, src.width, src.height, 2)

    artefacts_mask = core.std.BlankClip(rescale, color=(256 << 8) - 1)
    artefacts_mask = vdf.region_mask(artefacts_mask, 2, 2, 2, 2).std.Inflate()
    rescale = core.std.MaskedMerge(luma, rescale, artefacts_mask)

    lineart_mask = _line_mask(luma, 8000)
    antialias = core.std.MaskedMerge(luma, rescale, lineart_mask)

    antialias_merged = vdf.merge_chroma(antialias, denoise)

    src_c, src_ncop = [
        c.knlm.KNLMeansCL(a=6, h=20, d=0, device_type='gpu')
        for c in [src, JPBD_NCOP.src_cut[:opend - opstart + 1]]
    ]
    credit_mask = vdf.dcm(src, src_c[opstart:opend + 1], src_ncop, opstart,
                          opend, 2, 2).std.Deflate()
    credit = core.std.MaskedMerge(antialias_merged, denoise, credit_mask)

    masks_credit_ = _perform_masks_credit(Path('masks_' + JPBD.name[-2:] +
                                               '/'))

    for mask in masks_credit_:
        credit = lvf.rfs(
            credit,
            core.std.MaskedMerge(credit, denoise,
                                 to_gray(mask.mask, src).std.Deflate()),
            [(mask.start_frame, mask.end_frame)])

    deband_mask = lvf.denoise.detail_mask(credit, brz_a=3000, brz_b=1500)
    dark_mask = core.std.Expr([deband_mask, _ret_mask(credit, 12500)], 'x y +')
    deband_a = dbs.f3kpf(credit, 18, 36, 36)
    deband_b = dbs.f3kpf(credit, 18, 42, 42)
    deband_c = placebo.Deband(credit,
                              radius=12,
                              threshold=20,
                              iterations=3,
                              grain=0)
    deband_d = placebo.Deband(credit,
                              radius=10,
                              threshold=8,
                              iterations=2,
                              grain=0)
    deband = lvf.rfs(deband_a, deband_b, [(opstart + 483, opstart + 554)])
    deband = lvf.rfs(deband, deband_c, [(opstart, opstart + 44)])
    deband = lvf.rfs(deband, core.std.MaskedMerge(deband_d, credit, dark_mask),
                     [(opstart + 1070, opstart + 1103)])
    deband = lvf.rfs(deband, deband_d, [(opstart + 1104, opstart + 1124)])
    deband = core.std.MaskedMerge(deband, credit, deband_mask)

    grain_original = core.std.MergeDiff(deband, diff, [0, 1, 2])
    grain_original_nochroma = core.std.MergeDiff(deband, diff, [0])
    grain_new = core.neo_f3kdb.Deband(deband,
                                      preset='depth',
                                      grainy=32,
                                      grainc=32)
    grain_new_nochroma = vdf.merge_chroma(grain_new, deband)
    avg = core.std.PlaneStats(deband)
    adapt_mask = core.adg.Mask(get_y(avg), 28)
    grain_adapt = core.std.MaskedMerge(grain_new, grain_original, adapt_mask)

    gf3_args = dict(g1str=5,
                    g2str=3.85,
                    g3str=3.5,
                    g1shrp=50,
                    g2shrp=60,
                    g3shrp=60,
                    g1size=1.65,
                    g2size=1.60,
                    g3size=1.25)
    grain_a = hvf.GrainFactory3(deband, **gf3_args)
    grain_b = mdf.adptvgrnMod_mod(deband,
                                  2,
                                  size=1.5,
                                  sharp=60,
                                  static=False,
                                  luma_scaling=14)

    grain = core.std.FrameEval(
        deband, partial(_diff, new=grain_new, adapt=grain_adapt), avg)

    grain = lvf.rfs(grain, grain_original, [(5058, 5253), (7871, 7989)])
    grain = lvf.rfs(grain, grain_new_nochroma,
                    [(opstart + 117, opstart + 873),
                     (opstart + 921, opstart + 993)])
    grain = lvf.rfs(grain, grain_original_nochroma,
                    [(opstart + 874, opstart + 920),
                     (opstart + 994, opstart + 1069),
                     (opstart + 1125, opstart + 1202)])
    grain = lvf.rfs(grain, grain_a, [(opstart, opstart + 44)])
    grain = lvf.rfs(grain, grain_b, [(opstart + 1070, opstart + 1124)])

    stabilize = hvf.GSMC(src, radius=2, planes=0)
    ending = vdf.merge_chroma(stabilize, denoise)
    final = lvf.rfs(grain, ending, [(edstart, edend)])

    final = final[:opstart] + final[opstart + 2:opstart + 2160] + final[opend +
                                                                        1:]
    return depth(final, 10), opstart, opend
Пример #28
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    h = 720
    w = get_w(h)

    edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500)
    out = edgesfix

    clip = depth(out, 32)
    denoise = hybrid_denoise(clip, 0.45, 1.5)
    out = denoise

    luma = get_y(out)
    line_mask = line_mask_func(luma)

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, pscrn=1)
    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.4,
                                         beta=0.3,
                                         gamma=400,
                                         mdis=15).resize.Bilinear(
                                             src.width, src.height)

    rescale = core.std.MaskedMerge(luma, antialias, depth(line_mask, 32))
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    preden = core.knlm.KNLMeansCL(get_y(out),
                                  h=0.75,
                                  a=2,
                                  d=3,
                                  device_type='gpu',
                                  device_id=0)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(preden, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.Convolution([1, 1, 1, 1, 1, 1, 1, 1, 1])

    detail_mask = core.std.Expr([preden, detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')
    custom_mask_a = lvf.src('rezeros2_07_25374-25642.png', detail_mask)
    custom_mask_a = core.std.Expr([custom_mask_a, detail_mask], 'x y +')

    deband_a = dbs.f3kpf(out, 17, 36, 42, thr=0.5, elast=2, thrc=0.2)
    deband_b = placebo.deband(out, 18, 5.5, 2, 0)
    deband_d = core.neo_f3kdb.Deband(out, 20, 30, 30, 30, 0, 0, 4)
    deband_e = placebo.deband(out, 18, 8, 2, 0)

    deband = core.std.MaskedMerge(deband_a, deband_b, preden)

    deband = lvf.rfs(deband, deband_d, [(1457, 1677), (8414, 8684),
                                        (8788, 8915), (9348, 10179),
                                        (11325, 11459), (12647, 12857),
                                        (13025, 13574), (13874, 13987),
                                        (20809, 21076), (23936, 25063),
                                        (25219, 25373), (26231, 26530),
                                        (26668, 26800), (26818, 27048),
                                        (27174, 27454), (27503, 27943),
                                        (28492, 28622), (29948, 30563),
                                        (30965, 31498), (31624, 32005),
                                        (32107, 32325), (32451, 35407),
                                        (37171, 37955)])
    deband = lvf.rfs(deband, deband_e, [(22116, 22173), (22454, 22459),
                                        (38028, 38035)])
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    deband = lvf.rfs(deband,
                     core.std.MaskedMerge(deband_e, deband, custom_mask_a),
                     [(25374, 25642), (25708, 25889)])

    deband = core.neo_f3kdb.Deband(deband,
                                   preset='depth',
                                   grainy=24,
                                   grainc=24)
    out = deband

    ref, src, src_nced = [
        depth(x, 16) for x in [denoise, src, JPBD_NCED.src_cut[221:]]
    ]
    credit_mask = vdf.drm(ref, kernel='bilinear', mthr=65)
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask, 0),
                     [(113, 3315), (37171, src.num_frames - 1)])
    credit = lvf.rfs(credit, ref, [(3316, 3435), (35408, 35485)])
    out = credit

    src_c, src_nced = [
        c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu')
        for c in [src, src_nced]
    ]
    ending_mask = vdf.dcm(out, src_c[EDSTART:EDEND + 1],
                          src_nced[:EDEND - EDSTART + 1], EDSTART, EDEND, 4,
                          4).std.Inflate()
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, ending_mask),
                     [(EDSTART, EDEND)])
    out = credit

    grain = adptvgrnMod(out,
                        0.3,
                        0.15,
                        1.25,
                        luma_scaling=8,
                        sharp=80,
                        static=False,
                        lo=19)
    out = grain

    return depth(out, 10)
Пример #29
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import rekt
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from awsmfunc import bbmod
    from ccd import ccd
    from vsutil import depth, get_y
    from xvs import WarpFixChromaBlend

    src = JP_BD.clip_cut
    src_NCOP, src_NCED = JP_BD_NCOP.clip_cut, JP_BD_NCED.clip_cut
    src_NCOP = src_NCOP + src_NCOP[-1] * 11
    src_NCED = src_NCED + src_NCED[-1]
    src_03 = JP_BD_03.clip_cut
    # b = core.std.BlankClip(src, length=1)

    # Fixing an animation error in the NCOP
    sqmask_NCOP = lvf.mask.BoundingBox((419, 827), (1500, 68))
    masked_NCOP = core.std.MaskedMerge(src_NCOP, src_03,
                                       sqmask_NCOP.get_mask(src_NCOP))
    masked_NCOP = lvf.rfs(src_NCOP, masked_NCOP,
                          [(opstart + 2064, opstart + 2107)])

    # OP/ED stack comps to check that it lines up
    # op_scomp = lvf.scomp(src[opstart:opstart+src_NCOP.num_frames-1]+b, masked_NCOP[:-op_offset]+b)  # noqa
    # ed_scomp = lvf.scomp(src[edstart:edstart+src_NCED.num_frames-1]+b, src_NCED[:-ed_offset]+b)  # noqa

    # Masking credits
    op_mask = vdf.dcm(
        src, src[opstart:opstart+src_NCOP.num_frames-op_offset], masked_NCOP[:-op_offset],
        start_frame=opstart, thr=25, prefilter=True) if opstart is not False \
        else get_y(core.std.BlankClip(src))
    ed_mask = vdf.dcm(
        src, src[edstart:edstart+src_NCED.num_frames-ed_offset], src_NCED[:-ed_offset],
        start_frame=edstart, thr=25, prefilter=False) if edstart is not False \
        else get_y(core.std.BlankClip(src))
    credit_mask = core.std.Expr([op_mask, ed_mask], expr='x y +')
    credit_mask = depth(credit_mask, 16).std.Binarize()

    # Edgefixing
    ef = bbmod(src, left=1, right=1, top=1, bottom=1, u=False, v=False)
    ef = bbmod(ef, left=2, right=2, top=2, bottom=2, y=False)
    ef = depth(ef, 32)

    # Descaling + Rescaling
    src_y = get_y(ef)
    descaled = lvf.kernels.Lanczos(taps=5).descale(src_y, 1280, 720)
    rescaled = vdf.scale.nnedi3_upscale(descaled)
    downscaled = lvf.kernels.BicubicDidee().scale(rescaled, 1920, 1080)

    l_mask = vdf.mask.FDOG().get_mask(src_y, lthr=0.065,
                                      hthr=0.065).std.Maximum().std.Minimum()
    l_mask = l_mask.std.Median().std.Convolution([1] * 9)

    rescaled_masked = core.std.MaskedMerge(src_y, downscaled, l_mask)
    scaled = depth(vdf.misc.merge_chroma(rescaled_masked, ef), 16)

    unwarp = flt.line_darkening(scaled, 0.145).warp.AWarpSharp2(depth=2)
    sharp = haf.LSFmod(unwarp,
                       strength=65,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    mask_sharp = core.std.MaskedMerge(scaled, sharp, depth(l_mask, 16))

    upscaled = lvf.kernels.Bicubic().scale(descaled, 1920, 1080)
    descale_mask = lvf.scale.descale_detail_mask(src_y, upscaled)
    scale_restore_mask = core.std.Expr([credit_mask, descale_mask], "x y +")
    credits_merged = core.std.MaskedMerge(mask_sharp, depth(ef, 16),
                                          scale_restore_mask)

    # Denoising
    denoise_y = core.knlm.KNLMeansCL(credits_merged,
                                     d=1,
                                     a=3,
                                     s=4,
                                     h=0.15,
                                     channels='Y')
    denoise_uv = ccd(denoise_y, threshold=6, matrix='709')
    stab = haf.GSMC(denoise_uv, radius=2, planes=[0])
    decs = vdf.noise.decsiz(stab, sigmaS=8, min_in=208 << 8, max_in=232 << 8)

    # Fixing chroma
    cshift = core.resize.Bicubic(decs, chromaloc_in=1, chromaloc=0)
    cwarp = WarpFixChromaBlend(cshift, thresh=88, blur=3, depth=6)

    # Regular debanding + graining
    detail_mask = flt.detail_mask(cwarp, brz=(1800, 3500))
    deband = vdf.deband.dumb3kdb(cwarp, threshold=32, grain=16)
    deband_masked = core.std.MaskedMerge(deband, cwarp, detail_mask)
    grain: vs.VideoNode = adptvgrnMod(deband_masked,
                                      0.2,
                                      luma_scaling=10,
                                      size=1.35,
                                      static=True,
                                      grain_chroma=False)

    return grain
Пример #30
0
def main() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Vapoursynth filtering"""
    # Don't worry, this script is barely readable anymore even for me
    import rekt
    from awsmfunc import bbmod
    from havsfunc import ContraSharpening
    from lvsfunc.aa import upscaled_sraa
    from lvsfunc.comparison import stack_compare
    from lvsfunc.mask import BoundingBox
    from lvsfunc.util import replace_ranges
    from vardefunc import dcm
    from vardefunc.deband import dumb3kdb
    from vardefunc.mask import FreyChen
    from vsutil import depth, get_y, insert_clip

    src = JP_BD.clip_cut
    b = core.std.BlankClip(src, length=1)

    if opstart is not False:
        src_NCOP = NCOP.clip_cut
        op_scomp = stack_compare(
            src[opstart:opstart + src_NCOP.num_frames - 1] + b,
            src_NCOP[:-op_offset] + b,
            make_diff=True)  # noqa
    if edstart is not False:
        src_NCED = NCED.clip_cut
        #ed_scomp = stack_compare(src[edstart:edstart+src_NCED.num_frames-1]+b, src_NCED[:-ed_offset]+b, make_diff=True)  # noqa

    # Masking credits
    op_mask = dcm(
        src, src[opstart:opstart+src_NCOP.num_frames], src_NCOP,
        start_frame=opstart, thr=25, prefilter=True) if opstart is not False \
        else get_y(core.std.BlankClip(src))
    ed_mask = dcm(
        src, src[edstart:edstart+src_NCED.num_frames], src_NCED,
        start_frame=edstart, thr=25, prefilter=True) if edstart is not False \
        else get_y(core.std.BlankClip(src))
    credit_mask = core.std.Expr([op_mask, ed_mask], expr='x y +')
    credit_mask = depth(credit_mask, 16).std.Binarize()

    # Fixing an animation f**k-up
    for f in op_replace:
        src = insert_clip(src, src[f], f - 1)

    # Edgefixing
    ef = rekt.rektlvls(
        src,
        prot_val=[16, 235],
        min=16,
        max=235,
        rownum=[0, src.height - 1],
        rowval=[16, 16],
        colnum=[0, src.width - 1],
        colval=[16, 16],
    )

    bb_y = bbmod(ef,
                 left=1,
                 top=1,
                 right=1,
                 bottom=1,
                 thresh=32,
                 y=True,
                 u=False,
                 v=False)
    bb_uv = bbmod(bb_y,
                  left=2,
                  top=2,
                  right=2,
                  bottom=2,
                  y=False,
                  u=True,
                  v=True)
    bb32 = depth(bb_uv, 32)

    # --- Very specific filtering that should probably be removed for future episodes entirely
    # Fading for some... well, fades.
    fade = flt.fader(bb32, start_frame=4437, end_frame=4452)
    fade = flt.fader(fade, start_frame=18660, end_frame=18697)

    # Different sport names
    rkt_aa_ranges: Union[Union[int, None, Tuple[Optional[int], Optional[int]]],
                         List[Union[int, None,
                                    Tuple[Optional[int],
                                          Optional[int]]]], None] = [  # noqa
                                              (8824, 8907), (9828, 9911),
                                              (10995, 11078), (11904, 12010)
                                          ]

    rkt_aa = rekt.rekt_fast(fade,
                            fun=lambda x: upscaled_sraa(x),
                            top=854,
                            left=422,
                            bottom=60,
                            right=422)
    rkt_aa = replace_ranges(fade, rkt_aa, rkt_aa_ranges)

    # QP GET!
    rkt_aa2_ranges: Union[Union[int, None, Tuple[Optional[int],
                                                 Optional[int]]],
                          List[Union[int, None,
                                     Tuple[Optional[int],
                                           Optional[int]]]], None] = [  # noqa
                                               (26333, 26333), (28291, 28344),
                                               (30271, 30364)
                                           ]
    rkt_aa2 = rekt.rekt_fast(rkt_aa,
                             fun=lambda x: upscaled_sraa(x),
                             top=714,
                             left=354,
                             bottom=224,
                             right=354)
    rkt_aa2 = replace_ranges(fade, rkt_aa, rkt_aa2_ranges)

    # Table stuff
    rkt_aa3_ranges: Union[Union[int, None, Tuple[Optional[int],
                                                 Optional[int]]],
                          List[Union[int, None,
                                     Tuple[Optional[int],
                                           Optional[int]]]], None] = [  # noqa
                                               (32797, 32952)
                                           ]
    rkt_aa3 = rekt.rekt_fast(rkt_aa2,
                             fun=lambda x: upscaled_sraa(x),
                             top=488,
                             left=312,
                             bottom=390,
                             right=850)
    rkt_aa3 = replace_ranges(fade, rkt_aa2, rkt_aa3_ranges)

    rkt_aa = rkt_aa3

    # Clipping error Nyatalante/Achilles
    fixed_frame = source(
        JP_BD.workdir.to_str() + r"/assets/01/FGCBD_01_8970_fixed.png", rkt_aa)
    fix_error = replace_ranges(rkt_aa, fixed_frame, [(8968, 8970)])

    sp_out32 = fix_error
    sp_out16 = depth(sp_out32, 16)

    # Rescaling
    l_mask = FreyChen().get_mask(get_y(sp_out16)).morpho.Close(size=6)
    l_mask = core.std.Binarize(l_mask, 24 << 8).std.Maximum().std.Maximum()
    scaled, credit_mask = flt.rescaler(sp_out32,
                                       height=720,
                                       shader_file=shader)
    scaled = core.std.MaskedMerge(sp_out16, scaled, l_mask)
    scaled = core.std.MaskedMerge(scaled, sp_out16, credit_mask)

    # Denoising
    denoise = flt.multi_denoise(scaled, l_mask)

    # Anti-aliasing
    aa_clamped = flt.clamp_aa(denoise, strength=3.0)
    aa_rfs = replace_ranges(denoise, aa_clamped, aa_ranges)

    # Fix edges because they get f****d during the denoising and AA stages
    box = BoundingBox((1, 1), (src.width - 2, src.height - 2))
    fix_edges = core.std.MaskedMerge(scaled, aa_rfs, box.get_mask(scaled))

    # Regular debanding, but then...
    deband = flt.multi_debander(fix_edges, sp_out16)

    # --- More very specific filtering that should almost definitely be removed for other episodes
    boxes = [
        BoundingBox((0, 880), (1920, 200)),
        BoundingBox((1367, 0), (552, 1080)),
        BoundingBox((1143, 0), (466, 83)),
        BoundingBox((1233, 84), (237, 84)),
    ]

    boxed_deband = flt.placebo_debander(fix_edges,
                                        iterations=2,
                                        threshold=8,
                                        radius=14,
                                        grain=4)
    boxed_mask = core.std.BlankClip(
        boxed_deband.std.ShufflePlanes(planes=0, colorfamily=vs.GRAY))
    for bx in boxes:  # Gonna be awfully slow but OH WELLLLLL
        boxed_mask = core.std.Expr(
            [boxed_mask, bx.get_mask(boxed_mask)], "x y max")

    boxed_deband_merged = core.std.MaskedMerge(deband, boxed_deband,
                                               boxed_mask)
    boxed_deband_merged = replace_ranges(deband, boxed_deband_merged,
                                         [(20554, 20625)])

    stronger_deband = dumb3kdb(fix_edges, radius=18, threshold=[48, 32])
    stronger_deband = replace_ranges(boxed_deband_merged, stronger_deband,
                                     [(22547, 22912), (28615, 28846),
                                      (33499, 33708), (37223, 37572),
                                      (37636, 37791), (38047, 38102),
                                      (38411, 38733)])

    deband_csharp = ContraSharpening(stronger_deband, scaled, 17)

    sp_out = deband_csharp

    # Back to regular graining
    grain = flt.grain(sp_out)

    return grain