Exemple #1
0
def do_filter():
    """Vapoursynth filtering"""
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1):
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        strong = TAAmbk(luma, aatype='Eedi3', alpha=0.4, beta=0.4)
        weak = TAAmbk(luma, aatype='Nnedi3')
        expr = 'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr)

        clip_aa = core.std.Expr([strong, weak, luma], expr)
        return core.std.ShufflePlanes([clip_aa, clip], [0, 1, 2], vs.YUV)

    src = SRC_CUT

    interpolate = core.resize.Bicubic(src, src_left=3)
    f_1 = 1006
    src = src[:EDSTART + f_1] + interpolate[EDSTART + f_1] + src[EDSTART +
                                                                 f_1:-1]

    src = depth(src, 16)

    blur = core.bilateral.Gaussian(src, [0.45, 0])
    den = CoolDegrain(blur, tr=1, thsad=60, blksize=8, overlap=4, plane=4)

    dering = core.std.MaskedMerge(den, hvf.YAHR(den, 2, 32),
                                  muvf.AnimeMask(den, 0.2), 0)

    aa_a = core.std.MaskedMerge(dering, _nneedi3_clamp(dering),
                                TAAmbk(dering, mtype=2, showmask=1))
    aa_b = TAAmbk(src, aatype='Nnedi3', mtype=1, nns=4, qual=2, nsize=6)
    aa = lvf.rfs(aa_a, aa_b, [(OPSTART, OPEND), (EDSTART, EDEND)])

    preden = core.knlm.KNLMeansCL(aa,
                                  a=2,
                                  h=2,
                                  d=0,
                                  device_type='gpu',
                                  channels='Y')
    diff = core.std.MakeDiff(aa, preden, 0)
    db_m = lvf.denoise.detail_mask(aa.std.Median(), brz_a=3000, brz_b=1500)

    db_a = dbs.f3kpf(aa, 17)
    db_b = core.placebo.Deband(preden,
                               radius=17,
                               threshold=5.5,
                               iterations=1,
                               grain=4,
                               planes=1 | 2 | 4)
    db_b = core.std.MergeDiff(db_b, diff, 0)
    db = lvf.rfs(db_a, db_b, [(9729, 9845), (13652, 14048)])
    db = core.std.MaskedMerge(db, aa, db_m)

    grain = mdf.adptvgrnMod_mod(db, 0.2, size=1.25, sharp=60, luma_scaling=8)

    final = depth(grain, 10)

    return final, src
Exemple #2
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Regular VapourSynth filterchain"""
    import EoEfunc as eoe
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y, iterate

    src = pre_freeze().std.AssumeFPS(fpsnum=24000, fpsden=1001)
    src = depth(src, 16)

    # TO-DO: Figure out how they post-sharpened it. Probably some form of unsharpening?
    src_y = depth(get_y(src), 32)
    descale = lvf.kernels.Bicubic(b=0, c=3 / 4).descale(src_y, 1440, 810)
    double = vdf.scale.nnedi3cl_double(descale, pscrn=1)
    rescale = depth(SSIM_downsample(double, 1920, 1080), 16)
    scaled = vdf.misc.merge_chroma(rescale, src)

    denoise = core.knlm.KNLMeansCL(scaled, d=1, a=3, s=4, h=0.4, channels='Y')
    stab = haf.GSMC(denoise, radius=2, planes=[0])
    cdenoise = ccd(stab, threshold=5, matrix='709')
    decs = vdf.noise.decsiz(cdenoise,
                            sigmaS=4,
                            min_in=208 << 8,
                            max_in=232 << 8)

    dehalo = haf.YAHR(decs, blur=2, depth=32)
    halo_mask = lvf.mask.halo_mask(decs, rad=3, brz=0.3, thma=0.42)
    dehalo_masked = core.std.MaskedMerge(decs, dehalo, halo_mask)
    dehalo_min = core.std.Expr([dehalo_masked, decs], "x y min")

    aa = lvf.aa.nneedi3_clamp(dehalo_min, strength=1.5)
    # Some scenes have super strong aliasing that I really don't wanna scenefilter until BDs. Thanks, Silver Link!
    aa_strong = lvf.sraa(dehalo_min, rfactor=1.35)
    aa_spliced = lvf.rfs(aa, aa_strong, [])

    upscale = lvf.kernels.Bicubic(b=0, c=3 / 4).scale(descale, 1920, 1080)
    credit_mask = lvf.scale.descale_detail_mask(src_y, upscale, threshold=0.08)
    credit_mask = iterate(credit_mask, core.std.Deflate, 3)
    credit_mask = iterate(credit_mask, core.std.Inflate, 3)
    credit_mask = iterate(credit_mask, core.std.Maximum, 2)
    merge_credits = core.std.MaskedMerge(aa_spliced, src,
                                         depth(credit_mask, 16))

    deband = flt.masked_f3kdb(merge_credits, rad=18, thr=32, grain=[24, 0])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.15,
                                      luma_scaling=10,
                                      size=1.25,
                                      sharp=80,
                                      static=True,
                                      grain_chroma=False)

    return grain
Exemple #3
0
def do_filter():
    """Vapoursynth filtering"""
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1):
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        strong = TAAmbk(luma, aatype='Eedi3', alpha=0.4, beta=0.4)
        weak = TAAmbk(luma, aatype='Nnedi3')
        expr = 'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr)

        clip_aa = core.std.Expr([strong, weak, luma], expr)
        return core.std.ShufflePlanes([clip_aa, clip], [0, 1, 2], vs.YUV)

    src = SRC_CUT
    src += src[-1]*2

    interpolate = core.resize.Bicubic(src, src_left=3)
    f_1 = 1006
    src = src[:EDSTART+f_1] + interpolate[EDSTART+f_1] + src[EDSTART+f_1:-1]

    src = depth(src, 16)

    blur = core.bilateral.Gaussian(src, [0.45, 0])
    den = CoolDegrain(blur, tr=1, thsad=60, blksize=8, overlap=4, plane=4)



    dering = core.std.MaskedMerge(den, hvf.YAHR(den, 2, 32), muvf.AnimeMask(den, 0.2), 0)




    aa_a = core.std.MaskedMerge(dering, _nneedi3_clamp(dering), TAAmbk(dering, mtype=2, showmask=1))
    aa_b = TAAmbk(src, aatype='Nnedi3', mtype=1, nns=4, qual=2, nsize=6)
    aa_c = TAAmbk(dering, aatype='Eedi3SangNom', mtype=2, cycle=2)
    aa_d = TAAmbk(dering, aatype='Eedi3', cycle=2)
    aa = lvf.rfs(aa_a, aa_b, [(OPSTART, OPEND), (EDSTART, EDEND)])
    aa = lvf.rfs(aa, aa_c, [(6448, 6546)])
    aa = lvf.rfs(aa, aa_d, [(5467, 5550)])




    db_m = lvf.denoise.detail_mask(aa.std.Median(), brz_a=3000, brz_b=1500)

    db = dbs.f3kpf(aa, 17)
    db = core.std.MaskedMerge(db, aa, db_m)

    grain = mdf.adptvgrnMod_mod(db, 0.2, size=1.25, sharp=60, luma_scaling=8)

    final = depth(grain, 10)

    return final, src
Exemple #4
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Regular VapourSynth filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y, iterate

    src = pre_freeze()
    src = depth(src, 16)

    src_y = depth(get_y(src), 32)
    descale = lvf.kernels.Bicubic(b=0, c=3 / 4).descale(src_y, 1440, 810)
    double = vdf.scale.nnedi3cl_double(descale, pscrn=1)
    rescale = depth(SSIM_downsample(double, 1920, 1080), 16)
    scaled = vdf.misc.merge_chroma(rescale, src)

    denoise = core.knlm.KNLMeansCL(scaled, d=1, a=3, s=4, h=0.3, channels='Y')
    decs = vdf.noise.decsiz(denoise,
                            sigmaS=4,
                            min_in=208 << 8,
                            max_in=232 << 8)

    dehalo = haf.YAHR(decs, blur=2, depth=28)
    halo_mask = lvf.mask.halo_mask(decs, rad=3, brz=0.3, thma=0.42)
    dehalo_masked = core.std.MaskedMerge(decs, dehalo, halo_mask)

    aa = lvf.aa.nneedi3_clamp(dehalo_masked, strength=1.5)
    # Strong aliasing on the transformation scene (and probably elsewhere that I missed). Thanks, Silver Link!
    aa_strong = lvf.sraa(dehalo_masked, rfactor=1.35)
    aa_spliced = lvf.rfs(aa, aa_strong, [(7056, 7322)])

    upscale = lvf.kernels.Bicubic(b=0, c=3 / 4).scale(descale, 1920, 1080)
    credit_mask = lvf.scale.descale_detail_mask(src_y, upscale, threshold=0.08)
    credit_mask = iterate(credit_mask, core.std.Deflate, 3)
    credit_mask = iterate(credit_mask, core.std.Inflate, 3)
    credit_mask = iterate(credit_mask, core.std.Maximum, 2)
    merge_credits = core.std.MaskedMerge(aa_spliced, src,
                                         depth(credit_mask, 16))

    deband = flt.masked_f3kdb(merge_credits, rad=18, thr=32, grain=[24, 0])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.15,
                                      luma_scaling=10,
                                      size=1.25,
                                      sharp=80,
                                      static=True,
                                      grain_chroma=False)

    return grain
Exemple #5
0
def do_filter():
    """Vapoursynth filtering"""
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1):
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        strong = TAAmbk(luma, aatype='Eedi3', alpha=0.4, beta=0.4)
        weak = TAAmbk(luma, aatype='Nnedi3')
        expr = 'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr)

        clip_aa = core.std.Expr([strong, weak, luma], expr)
        return core.std.ShufflePlanes([clip_aa, clip], [0, 1, 2], vs.YUV)

    def _hell_deband(clip: vs.VideoNode):
        clip = depth(clip, 32)
        preden = vrf.knlmcl(clip, 2, 2, bits=32)
        diff = core.std.MakeDiff(clip, preden)
        deband = core.placebo.Deband(preden, radius=20, threshold=28, iterations=3, grain=8, planes=1|2|4)
        merge = core.std.MergeDiff(deband, diff)
        return depth(merge, 16)

    def _hell_mask(mask: vs.VideoNode, pand: int):
        mask = lvf.scale.iterate(mask, core.std.Median, 2)
        mask = hvf.mt_expand_multi(mask, 'ellipse', 0, sw=pand, sh=pand)
        mask = hvf.mt_inpand_multi(mask, 'ellipse', 0, sw=pand - int(pand/2), sh=pand - int(pand/2))
        mask = core.std.Expr(mask, 'x 25000 < 0 x 6 * ?')
        return mask

    src = SRC_CUT

    interpolate = core.resize.Bicubic(src, src_left=3)
    f_1, f_2 = 1006, 2006
    src = src[:EDSTART+f_1] + interpolate[EDSTART+f_1] + src[EDSTART+f_1:EDSTART+f_2] \
        + interpolate[EDSTART+f_2] + src[EDSTART+f_2:-2]

    # Fix bandings in motion
    src = core.std.FreezeFrames(src, 29782, 29786, 29782)
    src = core.std.FreezeFrames(src, 29787, 29788, 29787)
    src = core.std.FreezeFrames(src, 29789, 29791, 29791)

    src = depth(src, 16)

    blur = core.bilateral.Gaussian(src, [0.45, 0])
    den = CoolDegrain(blur, tr=1, thsad=60, blksize=8, overlap=4, plane=4)



    dering = core.std.MaskedMerge(den, hvf.YAHR(den, 2, 32), muvf.AnimeMask(den, 0.2), 0)




    aa_a = core.std.MaskedMerge(dering, _nneedi3_clamp(dering), TAAmbk(dering, mtype=2, showmask=1))
    aa_b = TAAmbk(src, aatype='Nnedi3', mtype=1, nns=4, qual=2, nsize=6)
    aa = lvf.rfs(aa_a, aa_b, [(OPSTART, OPEND), (EDSTART, EDEND)])




    db_m = lvf.denoise.detail_mask(aa.std.Median(), brz_a=3000, brz_b=1500)

    db_a = dbs.f3kpf(aa, 17)
    db_b = core.std.MaskedMerge(_hell_deband(aa), aa, _hell_mask(db_m, 60))
    db_c = core.placebo.Deband(aa, radius=18, threshold=5, iterations=1, grain=6, planes=1|2|4)
    db = lvf.rfs(db_a, db_b, [(7535, 7894), (8579, 8947), (9602, 9769)])
    db = lvf.rfs(db, db_c, [(29782, 29791)])
    db = core.std.MaskedMerge(db, aa, db_m)

    grain = mdf.adptvgrnMod_mod(db, 0.2, size=1.25, sharp=60, luma_scaling=8)

    final = depth(grain, 10)

    return final, src
Exemple #6
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Regular VapourSynth filterchain"""
    import EoEfunc.denoise as eoe
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y, iterate
    from xvs import WarpFixChromaBlend

    src = JP_clip.clip_cut.std.AssumeFPS(fpsnum=24000, fpsden=1001)
    src = depth(src, 16)

    # TO-DO: Figure out how they post-sharpened it. Probably some form of unsharpening?
    src_y = depth(get_y(src), 32)
    descale = lvf.kernels.Bicubic(b=0, c=3 / 4).descale(src_y, 1440, 810)
    double = vdf.scale.nnedi3cl_double(descale, pscrn=1)
    rescale = depth(SSIM_downsample(double, 1920, 1080), 16)
    scaled = vdf.misc.merge_chroma(rescale, src)

    denoise_ref = core.dfttest.DFTTest(scaled, sigma=1.8)
    denoise = lvf.denoise.bm3d(scaled, sigma=[0.75, 0.65], ref=denoise_ref)
    cdenoise = ccd(denoise, threshold=3, matrix='709')
    decs = vdf.noise.decsiz(cdenoise,
                            sigmaS=4,
                            min_in=208 << 8,
                            max_in=232 << 8)

    # Dehalo fuckery. F**k the sharpening, dude
    dehalo = haf.YAHR(decs, blur=2, depth=32)
    dehalo_2 = lvf.dehalo.masked_dha(dehalo, ry=2.5, rx=2.5)
    halo_mask = lvf.mask.halo_mask(decs, rad=3, brz=0.3, thma=0.42)
    dehalo_masked = core.std.MaskedMerge(decs, dehalo_2, halo_mask)
    dehalo_min = core.std.Expr([dehalo_masked, decs], "x y min")

    # Brightening the lines to undo the unsharpening's line darkening
    bright = haf.FastLineDarkenMOD(dehalo_min, strength=-24)

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

    line_mask = core.std.Prewitt(clmp)
    cwarp = WarpFixChromaBlend(clmp, thresh=96, depth=6)
    cwarp = core.std.MaskedMerge(cwarp, clmp, line_mask)

    upscale = lvf.kernels.Bicubic(b=0, c=3 / 4).scale(descale, 1920, 1080)
    credit_mask = lvf.scale.descale_detail_mask(src_y, upscale, threshold=0.08)
    credit_mask = iterate(credit_mask, core.std.Deflate, 3)
    credit_mask = iterate(credit_mask, core.std.Inflate, 3)
    credit_mask = iterate(credit_mask, core.std.Maximum, 2)
    merge_credits = core.std.MaskedMerge(cwarp, src, depth(credit_mask, 16))

    deband = flt.masked_f3kdb(merge_credits, rad=15, thr=20, grain=[12, 0])
    grain: vs.VideoNode = adptvgrnMod(deband,
                                      seed=42069,
                                      strength=0.15,
                                      luma_scaling=10,
                                      size=1.25,
                                      sharp=70,
                                      static=True,
                                      grain_chroma=False)

    return grain
Exemple #7
0
out = fvf.ReplaceFrames(
    out, vp9,
    "[0 4] [10 14] [45 49] [70 74] [202 206] [223 232] [275 280] [295 311] [420 424] [573 577] [582 585] [596 601] [607 611] [613 622] [626 627] [633 636] [641 642] 645 [648 651] [656 666] [720 814] [979 981] [1003 1004] [1340 1342] [1358 1362] 1360 [1370 1374] [1380 1383] [1394 1398] [1404 1412] [1433 1434] [1441 1448] [1454 1458] [1465 1467] [1479 1482] [1491 1514] [1528 1530] [1554 1559] [1633 1634] [1651 1655] [1660 1664] [1674 1675] [1729 1730] [1760 1765] [1781 1794] [1810 1813] 1859 1938 [1985 1988] [1996 2000] [2006 2010] [2021 2025] 2184 [2195 2198] [2214 2225] [2236 2239] 2258 [2445 2478] [2483 2485] [2490 2493] [2499 2500] [2840 2842] [3258 3263] [3270 3271] [3289 3307] [3507 3531] [3648 3661] [3825 3833] [3838 3842] [3849 3871] [3946 3950] [3956 3961] [4288 4289] [4509 4513] [4611 4612] [4838 4850] [4863 4869] [5040 5043] [5053 5055] [5284 5285] [5406 5407] [5607 5609] [5692 5704] [5890 5895] [6005 6018] [6062 6068] [6477 6504] [6584 6585] 6613 [6638 6640] [6774 6780] 6705 [6779 6804] [6810 6817] [7089 7090] [7230 7234] [7264 7281] [7690 7691] [7731 7733]"
)
out = fvf.ReplaceFrames(out, av2, "[5286 5405] [6194 6273]")
out = fvf.ReplaceFrames(
    out, h264,
    "[281 286] [1731 1734] [1739 1759] [2183 2213] [2250 2253] [2453 2455] [2464 2467] [2480 2482] [2486 2489] [2494 2495] [2646 2747] [3662 3671] [3951 3955] [4563 4583] [6025 6049] [6056 6061] [6069 6109] [6367 6416] [6580 6583] [6586 6598] [6560 6612] [6629 6637] [6641 6643] [6651 6657] [6698 6700] 6735 [6835 6878] [7197 7198]"
)
out = fvf.ReplaceFrames(out,
                        core.std.MaskedMerge(h264, av1, av1.std.Binarize(46)),
                        "[3951 3955]")
out = fvf.ReplaceFrames(
    out,
    haf.YAHR(core.std.MaskedMerge(muf.abcxyz(out), out,
                                  out.std.Binarize(100))),
    "[1790 1794] [2266 2279]")
out = fvf.ReplaceFrames(
    out, taa.TAAmbk(out, 2),
    "[357 409] [761 850] [1785 1804] [2224 2252] [2258 2343] [2346 2430] [2436 2444] [2501 2588] [2646 3047] [3068 3249] [3472 3574] [3575 3671] [3575 3660] [3775 3824] [4355 4362] [4529 4539] [4770 4877] [4891 4995] [6417 6476] [7197 7204] [7795 7921]"
)
out = fvf.ReplaceFrames(
    out, core.placebo.Deband(out, iterations=2, threshold=10, radius=20),
    "[3672 3677]")

deband_s = core.placebo.Deband(av1,
                               iterations=2,
                               threshold=18,
                               radius=9,
                               dither=False)