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

        luma = get_y(clip)

        def _strong(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(alpha=0.25,
                        beta=0.5,
                        gamma=40,
                        nrad=2,
                        mdis=20,
                        vcheck=3)
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        def _weak(clip: vs.VideoNode) -> vs.VideoNode:
            args = dict(nsize=3, nns=2, qual=2)
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip,
                                        luma.width,
                                        luma.height,
                                        src_left=-.5,
                                        src_top=-.5)

        clip_aa = core.std.Expr(
            [_strong(luma), _weak(luma), luma],
            'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr))
        return vdf.merge_chroma(clip_aa, clip)

    def _perform_endcard(path: str, ref: vs.VideoNode) -> vs.VideoNode:
        endcard = lvf.src(path).std.AssumeFPS(ref)
        endcard = core.std.CropRel(endcard, left=6, top=20, right=0, bottom=6)
        endcard = core.resize.Bicubic(endcard,
                                      ref.width,
                                      ref.height,
                                      vs.RGBS,
                                      dither_type='error_diffusion')

        endcard = iterate(
            endcard, partial(core.w2xc.Waifu2x, noise=3, scale=1, photo=True),
            2)

        endcard = core.resize.Bicubic(endcard,
                                      format=vs.YUV444PS,
                                      matrix_s='709',
                                      dither_type='error_diffusion')
        endcard = lvf.util.quick_resample(
            endcard,
            lambda c: core.neo_f3kdb.Deband(c, 15, 36, 36, 36, 24, 24, 4))

        return Tweak(endcard, sat=1.2, bright=-0.05, cont=1.2)

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

    denoise_a = CoolDegrain(src, tr=2, thsad=48, blksize=8, overlap=4, plane=4)
    denoise_b = CoolDegrain(src, tr=3, thsad=96, blksize=8, overlap=4, plane=4)
    denoise = lvf.rfs(denoise_a, denoise_b, [(edstart + 1870, edstart + 1900)])

    antialias_a = _nneedi3_clamp(denoise)
    downscaler = lambda c, w, h: core.fmtc.resample(
        c, w, h, kernel='gauss', invks=True, invkstaps=1, taps=1, a1=32)
    antialias_b = rekt_fast(
        denoise,
        lambda c: lvf.sraa(c, 1.45, rep=13, downscaler=downscaler),
        top=482)
    antialias = lvf.rfs(antialias_a, antialias_b, [(8185, 8280)])

    predenoise = mClean(antialias, thSAD=200, chroma=False)
    detail_mask = lvf.denoise.detail_mask(predenoise,
                                          rad=2,
                                          radc=2,
                                          brz_a=3250,
                                          brz_b=1250)
    ret_mask = kgf.retinex_edgemask(predenoise).std.Binarize(
        9250).std.Median().std.Inflate()
    line_mask = core.std.Expr([detail_mask, ret_mask], 'x y max')

    deband_a = core.neo_f3kdb.Deband(antialias,
                                     17,
                                     42,
                                     42,
                                     42,
                                     12,
                                     0,
                                     sample_mode=4,
                                     keep_tv_range=True)
    deband_a = core.std.MaskedMerge(deband_a, antialias, line_mask)
    deband_b = core.neo_f3kdb.Deband(deband_a,
                                     18,
                                     48,
                                     48,
                                     48,
                                     0,
                                     0,
                                     sample_mode=2,
                                     keep_tv_range=True)

    deband = lvf.rfs(deband_a, deband_b, [(edstart + 1870, edstart + 1900)])
    deband = lvf.rfs(deband, deband_b, [(13611, 13661), (20022, 20057)])

    grain = kgf.adaptive_grain(deband, 0.25, luma_scaling=10)

    endcard = _perform_endcard(
        '[BDMV][200610][Magia Record][Vol.3]/Scans/endcard6_front_descreen.png',
        src)
    endcard_length = 119
    final = core.std.Splice([grain, endcard * endcard_length], True)
    final = core.resize.Bicubic(final,
                                format=vs.YUV420P10,
                                dither_type='error_diffusion')
    final = core.std.Limiter(final, 16, [235 << 2, 240 << 2])

    return depth(final, 10), endcard_length
示例#2
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut

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

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

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

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

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

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

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

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

        pre = get_y(out)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2],
                                          [0, 1, 2])
示例#3
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
示例#4
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    # Variables
    opstart, opend = 792, 2948
    edstart, edend = 31648, 33807
    full_zone = [(18461, 18508), (31588, 31647), (33988, src.num_frames - 1)
                 ]  # eyecatch, episode name and next episode
    shabc_zone = [(edstart + 15, edstart + 1215),
                  (edstart + 1882, edstart + 2126)]
    h = 720
    w = get_w(h)

    # Bicubic sharp parts don't have bad edges
    edges_a = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    edges_b = awf.bbmod(src, left=6, thresh=32, blur=200)
    edges = lvf.rfs(edges_a, edges_b, [(edstart + 1275, edstart + 1757)])
    edges = lvf.rfs(edges, src, [(opstart, opend)] + full_zone)
    out = depth(edges, 32)

    # Denoise
    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450)
    denoise = hybrid_denoise(out, 0.35, 1.4, dict(a=2, d=1),
                             dict(ref=depth(ref, 32)))
    out = denoise

    # Descale
    luma = get_y(out)
    lineart = vdf.edge_detect(luma, 'FDOG', 0.055,
                              (1, 1)).std.Median().std.BoxBlur(0, 1, 1, 1, 1)

    descale_a = core.descale.Despline36(luma, w,
                                        h).std.SetFrameProp('descaleKernel',
                                                            data='spline36')
    descale_b = core.descale.Debicubic(luma, w, h, 0, 1).std.SetFrameProp(
        'descaleKernel', data='sharp_bicubic')
    descale = lvf.rfs(descale_a, descale_b, shabc_zone)

    # Chroma reconstruction
    # y_m is the assumed mangled luma.
    # Descale 1080p -> Bad conversion in 422 720p -> Regular 1080p 420
    radius = 2
    y, u, v = descale, plane(out, 1), plane(out, 2)
    y_m = core.resize.Point(y, 640, 720,
                            src_left=-1).resize.Bicubic(960,
                                                        540,
                                                        filter_param_a=1 / 3,
                                                        filter_param_b=1 / 3)

    # 0.25 for 444 and 0.25 for right shifting
    y_m, u, v = [
        c.resize.Bicubic(w,
                         h,
                         src_left=0.25 + 0.25,
                         filter_param_a=0,
                         filter_param_b=.5) for c in [y_m, u, v]
    ]

    y_fixup = core.std.MakeDiff(y, y_m)
    yu, yv = Regress(y_m, u, v, radius=radius, eps=1e-7)

    u_fixup = ReconstructMulti(y_fixup, yu, radius=radius)
    u_r = core.std.MergeDiff(u, u_fixup)

    v_fixup = ReconstructMulti(y_fixup, yv, radius=radius)
    v_r = core.std.MergeDiff(v, v_fixup)

    # -0.5 * 720/1080 = -1/3
    # -1/3 for the right shift
    # https://forum.doom9.org/showthread.php?p=1802716#post1802716
    u_r, v_r = [
        c.resize.Bicubic(960,
                         540,
                         src_left=-1 / 3,
                         filter_param_a=-.5,
                         filter_param_b=.25) for c in [u_r, v_r]
    ]

    upscale = vdf.fsrcnnx_upscale(
        descale,
        height=h * 2,
        shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl',
        upscaler_smooth=eedi3_upscale,
        profile='zastin')

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

    downscale = muvf.SSIM_downsample(antialias,
                                     src.width,
                                     src.height,
                                     filter_param_a=0,
                                     filter_param_b=0)
    downscale = core.std.MaskedMerge(luma, downscale, lineart)

    merged_a = join([downscale, u_r, v_r])
    merged_b = vdf.merge_chroma(downscale, denoise)
    merged = lvf.rfs(merged_a, merged_b, shabc_zone)
    out = depth(merged, 16)

    warp = xvs.WarpFixChromaBlend(out, 80, 2, depth=8)
    out = warp

    dering = gf.MaskedDHA(out,
                          rx=1.25,
                          ry=1.25,
                          darkstr=0.05,
                          brightstr=1.0,
                          maskpull=48,
                          maskpush=140)
    out = dering

    qtgmc = hvf.QTGMC(out, Preset="Slower", InputType=1, ProgSADMask=2.0)
    qtgmc = vdf.fade_filter(out, out, qtgmc, edstart + 1522,
                            edstart + 1522 + 24)
    qtgmc = lvf.rfs(out, qtgmc, [(edstart + 1522 + 25, edstart + 1757)])
    out = qtgmc

    out = lvf.rfs(out, depth(denoise, 16), [(opstart, opend)])

    detail_dark_mask = detail_dark_mask_func(get_y(out),
                                             brz_a=8000,
                                             brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(out, 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([get_y(out), detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')

    deband = dumb3kdb(out, 22, 30)
    import rekt as rkt
    import debandshit as dbs
    deband_b = rkt.rekt_fast(
        out,
        lambda c: dbs.f3kbilateral(c, 22, 120, 120).grain.Add(0.2, 0.15),
        left=376,
        right=1062,
        bottom=500)
    deband_c = dumb3kdb(out, 24, 48)
    deband = lvf.rfs(deband, deband_b, [(7312, 7388)])
    deband = lvf.rfs(deband, deband_c, [(29089, 29100)])
    deband = core.std.MaskedMerge(deband, out, detail_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)
    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(edges, 16)
    credit = out
    rescale_mask = vdf.diff_rescale_mask(ref, h, b=0, c=1, mthr=40, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4).std.BoxBlur(0, 1, 1, 1, 1)

    credit = lvf.rfs(credit, ref, full_zone)
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask),
                     [(edstart, edend)])
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#5
0
def do_filter():
    """Vapoursynth filtering"""
    # Source and dithering
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    # Variables
    opstart, opend = 17310, 19468
    edstart, edend = 31889, src.num_frames - 1
    h = 846
    w = get_w(h)
    cubic_filters = ['catrom', 'mitchell', 'robidoux', 'robidoux sharp']
    cubic_filters = [vdf.get_bicubic_params(cf) for cf in cubic_filters]

    # Remove the dynamic grain
    degrain = hybrid_denoise(out, 0.35, 1.2, dict(a=2, d=1))
    out = degrain

    y = get_y(out)
    y32 = depth(y, 32)
    lineart = vdf.edge_detect(y32, 'kirsch', 0.055,
                              (1, 1)).std.Median().std.Inflate()

    # Use multiple descaling kernel for a sharper result
    descale_clips = [
        core.descale.Debicubic(y32, w, h, b, c) for b, c in cubic_filters
    ]
    descale = core.std.Expr(descale_clips,
                            'x y z a min min min x y z max max min')

    # Fix descaling artifacts (yes even for catrom there's still artifacts)
    conv = core.std.Convolution(descale, [1, 2, 1, 2, 0, 2, 1, 2, 1])
    thr, coef = 0.013, 3.2
    descale_fix = core.std.Expr([descale, conv],
                                f'x y - abs {thr} < y x ?').std.PlaneStats()
    adapt_mask = core.adg.Mask(
        descale_fix,
        12).std.Invert().std.Expr(f'x 0.80 - {coef} * 0.20 + 0 max 1 min')

    descale = core.std.MaskedMerge(descale, descale_fix, adapt_mask)

    # Double using eedi3+nnedi, fsrcnnx and a sharpener
    upscale = vdf.fsrcnnx_upscale(descale,
                                  w * 2,
                                  h * 2,
                                  r'shaders\FSRCNNX_x2_56-16-4-1.glsl',
                                  upscaler_smooth=eedi3_upscale,
                                  profile='zastin',
                                  sharpener=partial(gf.DetailSharpen,
                                                    sstr=1.25,
                                                    power=4))

    # Antialiasing by eedi3
    aa_strong = sraa_eedi3(upscale, 13, alpha=0.3, beta=0.5, gamma=40)
    aa = aa_strong

    # Rescale to 1080p with Bicubic b=0, c=0 AKA Hermite
    down = muvf.SSIM_downsample(aa,
                                src.width,
                                src.height,
                                filter_param_a=0,
                                filter_param_b=0)

    upscale = depth(core.std.MaskedMerge(y32, down, lineart), 16)

    merged = vdf.merge_chroma(upscale, out)
    out = merged

    # Very bad halo
    dehalo = rkt.rekt_fast(out,
                           lambda x: gf.MaskedDHA(x,
                                                  rx=4.5,
                                                  ry=4.5,
                                                  darkstr=0.05,
                                                  brightstr=1.0,
                                                  maskpull=48,
                                                  maskpush=140),
                           left=620,
                           right=440,
                           top=200,
                           bottom=176)
    mask_halo = get_y(out.std.MakeDiff(dehalo,
                                       0)).rgvs.RemoveGrain(2).std.Median()
    mask_halo = core.hist.Luma(mask_halo).std.Binarize(
        33000).std.Maximum().std.Inflate()
    mask_halo = vdf.region_mask(mask_halo,
                                left=630,
                                right=440,
                                top=200,
                                bottom=176)
    blur_dehalo = core.std.BoxBlur(dehalo, hradius=1, vradius=1)
    dehalo = core.std.MaskedMerge(dehalo, blur_dehalo, mask_halo)
    out = lvf.rfs(out, dehalo, [(15936, 15973)])

    # Deband with prefilter
    y = get_y(out)
    detail_light_mask = lvf.denoise.detail_mask(y, brz_a=2500, brz_b=1200)

    pf = iterate(out, core.std.Maximum, 2).std.Convolution([10] * 9, planes=0)
    diff = core.std.MakeDiff(out, pf)

    deband = core.f3kdb.Deband(pf,
                               17,
                               36,
                               36,
                               36,
                               12,
                               12,
                               2,
                               keep_tv_range=True,
                               output_depth=16)
    deband = core.std.MergeDiff(deband, diff)
    deband = core.std.MaskedMerge(deband, out, detail_light_mask)
    out = deband

    # Ending part
    ref = degrain
    pfed = ref.std.Median().std.Convolution([1] * 9, planes=0)
    diff_ed = core.std.MakeDiff(ref, pfed)
    deband_ed = core.f3kdb.Deband(pfed,
                                  22,
                                  30,
                                  30,
                                  30,
                                  32,
                                  32,
                                  2,
                                  keep_tv_range=True,
                                  output_depth=16)
    deband_ed = core.std.MergeDiff(deband_ed, diff_ed)
    out = lvf.rfs(out, deband_ed, [(edstart, edend)])

    # Regraining
    grain = adptvgrnMod(out,
                        0.25,
                        0.15,
                        size=out.height / h,
                        sharp=80,
                        luma_scaling=10,
                        static=True)
    out = grain

    # Restore 1080p stuff
    ref = src
    rescale_mask = vdf.drm(ref, h, mthr=65, sw=4, sh=4)

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0), [(opstart, opend),
                                                       (3917, 4024)])
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#6
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)
    src += src[-1]

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')
    full_stuff = [(313, 1993), (15602, 15757), (19240, 19295)]

    denoise = hybrid_denoise(src, 0.5, 2)
    denoise_b = hybrid_denoise(src, 0.6, 7.5, bm3d_args=dict(profile1='high'))
    deband = lvf.rfs(denoise, denoise_b, [(4002, 4061)])
    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, _aa_extra(depth(denoise, 16)), [(2794, 2949)])
    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 = core.std.MaskedMerge(deband, out, deband_mask)
    deband_b = rkt.rekt_fast(
        deband, lambda x: core.neo_f3kdb.Deband(
            x, 8, 96, 96, 96, sample_mode=1, keep_tv_range=True), 1112, 264,
        184, 0)
    deband = lvf.rfs(deband, deband_b, [(4002, 4061)])
    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)
    grain_b = adptvgrnMod(grain,
                          0.6,
                          size=1.85,
                          static=False,
                          luma_scaling=4,
                          grain_chroma=False)
    grain = lvf.rfs(grain, grain_b, [(204, 2049)])
    out = grain

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

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask),
                     full_stuff)
    credit = lvf.rfs(
        credit,
        core.std.MaskedMerge(credit, ref,
                             vdf.region_mask(rescale_mask, 1450, 0, 947, 0)),
        [(33860, 33925)])
    credit = lvf.rfs(credit, src, [(0, 203), (2049, 2229), (31768, 33839)])
    out = credit

    smooth = gf.JohnFPS(out[31888:33840], 60000, 1001)
    clips = [out[:31888], smooth, out[33840:]]
    vfr = muvf.VFRSplice(clips, 'symphogearg_01_timecode.txt')
    cfr = core.std.AssumeFPS(vfr, src)
    out = cfr

    return depth(out, 10)
示例#7
0
        ed = awf.ReplaceFrames(ed, nnedi, "2014 2020 2026")
    if i in [2, 5, 10]:
        ed = awf.ReplaceFrames(ed, nnedi, "2017")
    if i in [6]:
        ed = awf.ReplaceFrames(ed, nnedi, "2018 2024 2051")
    if i in [2, 11]:
        ed = awf.ReplaceFrames(ed, nnedi, "2019 2033 2036")
    if i in [6, 10]:
        ed = awf.ReplaceFrames(ed, nnedi, "2030")
    if i in [11]:
        ed = awf.ReplaceFrames(ed, nnedi, "2043 2047 2050")

    ed = ed.std.Crop(top=56, bottom=60)

    ededge = rekt.rekt_fast(yes,
                            fun=lambda m: ed.std.Crop(left=4, right=4),
                            left=4,
                            right=4)

    diff = vdf.mask.Difference().creditless(src_clip=ededge + ededge[0],
                                            credit_clip=ededge,
                                            nc_clip=nced,
                                            start_frame=0,
                                            thr=70,
                                            prefilter=True,
                                            expand=5)
    diffedge = vdf.mask.Difference().creditless(src_clip=ededge + ededge[0],
                                                credit_clip=ededge,
                                                nc_clip=nced,
                                                start_frame=0,
                                                thr=20,
                                                prefilter=True,
示例#8
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)