예제 #1
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)
예제 #2
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)
예제 #3
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Vapoursynth filtering"""
    import lvsfunc as lvf
    import rekt
    import vardefunc as vdf
    from awsmfunc import bbmod
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y, insert_clip, join, plane

    src = JP_BD.clip_cut

    # Fixing animation f**k-ups
    if freeze_ranges:
        src = core.std.FreezeFrames(
            src,
            [s[0] for s in freeze_ranges],
            [e[1] for e in freeze_ranges],
            [f[2] for f in freeze_ranges]
        )

    # 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)

    cshift = flt.shift_chroma(bb_uv, left=0.6)
    cshift = lvf.rfs(bb_uv, cshift, cshift_left_ranges)

    bb32 = depth(cshift, 32)
    bb32_y = get_y(bb32)

    # Descaling + DPIR while it's at a lower res (so I can actually run it because >memory issues xd)
    descale = lvf.kernels.Catrom().descale(bb32_y, 1280, 720)
    downscale = lvf.kernels.Catrom(format=vs.YUV444PS).scale(bb32, 1280, 720)
    descale_444 = join([descale, plane(downscale, 1), plane(downscale, 2)])
    denoise_y = lvf.deblock.vsdpir(descale_444, strength=2.75, mode='deblock', matrix=1, i444=True, cuda=True)

    supersample = vdf.scale.fsrcnnx_upscale(get_y(denoise_y), shader_file=shader_file, downscaler=None)
    downscaled = SSIM_downsample(supersample, src.width, src.height, smooth=((3 ** 2 - 1) / 12) ** 0.5,
                                 sigmoid=True, filter_param_a=0, filter_param_b=0)

    # Create credit mask
    upscale = lvf.kernels.Catrom().scale(descale, src.width, src.height)
    credit_mask = lvf.scale.descale_detail_mask(bb32_y, upscale, threshold=0.055) \
        .std.Deflate().std.Deflate().std.Minimum()

    # Merge early for additional accuracy with DPIR
    merged = core.std.MaskedMerge(downscaled, bb32_y, credit_mask)

    down_y = lvf.kernels.Catrom().scale(merged, src.width/2, src.height/2)
    down_i444 = join([down_y, plane(bb32, 1), plane(bb32, 2)])
    deblock_down = lvf.deblock.vsdpir(down_i444, strength=3, mode='denoise', matrix=1, i444=True, cuda=True)

    scaled = depth(join([merged, plane(deblock_down, 1), plane(deblock_down, 2)]), 16)

    # Final bit of "denoising"
    dft = core.dfttest.DFTTest(scaled, sigma=2.0, tbsize=5, tosize=3, planes=[0])
    decs = vdf.noise.decsiz(dft, sigmaS=4, min_in=208 << 8, max_in=232 << 8)

    # AA
    baa = lvf.aa.based_aa(decs, str(shader_file))
    sraa = lvf.sraa(decs, rfactor=1.65)
    clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.3)

    dehalo = lvf.dehalo.masked_dha(clmp, rx=1.4, ry=1.4, brightstr=0.4)
    cwarp = core.warp.AWarpSharp2(dehalo, thresh=72, blur=3, type=1, depth=4, planes=[1, 2])

    # Merge credits (if applicable)
    merged = core.std.MaskedMerge(cwarp, depth(bb32, 16), depth(credit_mask, 16))

    deband = core.average.Mean([
        flt.masked_f3kdb(merged, rad=16, thr=[20, 24], grain=[24, 12]),
        flt.masked_f3kdb(merged, rad=20, thr=[28, 24], grain=[24, 12]),
        flt.masked_placebo(merged, rad=6, thr=2.5, itr=2, grain=4)
    ])

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

    no_flt = lvf.rfs(grain, depth(bb32, 16), no_filter)

    if edstart is not False:
        src_nced = depth(JP_NCED.clip_cut, 16)
        no_flt = insert_clip(no_flt, src_nced, edstart)

    return no_flt
예제 #4
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
예제 #5
0
def transpose_sraa(clip: vs.VideoNode, **kwargs: Any) -> vs.VideoNode:
    import lvsfunc as lvf

    aa = lvf.sraa(clip.std.Transpose(), **kwargs)
    return lvf.sraa(aa.std.Transpose(), **kwargs)
예제 #6
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import havsfunc as haf
    import lvsfunc as lvf
    import vardefunc as vdf
    from ccd import ccd
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y

    src = JP_BD.clip_cut
    src = depth(src, 32)

    src_y = get_y(src)
    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)

    # Rescaling
    descale = flt.auto_descale(src_y)

    supersample = vdf.scale.nnedi3cl_double(descale, use_znedi=True, pscrn=1)
    downscaled = SSIM_downsample(supersample,
                                 src.width,
                                 src.height,
                                 smooth=((3**2 - 1) / 12)**0.5,
                                 sigmoid=True,
                                 filter_param_a=0,
                                 filter_param_b=0)

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

    # Denoising
    l_mask_16 = depth(l_mask, 16).std.Minimum()
    dft = core.dfttest.DFTTest(scaled, sigma=1.25, tbsize=3, tosize=1)
    dft_masked = core.std.MaskedMerge(dft, scaled, l_mask_16)

    ccd_uv = ccd(dft, threshold=4, matrix='709')
    ccd_uv = core.std.MaskedMerge(ccd_uv, dft_masked, l_mask_16, planes=[1, 2])

    decs = vdf.noise.decsiz(ccd_uv, sigmaS=4, min_in=212 << 8, max_in=240 << 8)

    # AA and slight lineart enhancement
    baa = lvf.aa.based_aa(decs, shader_file)
    sraa = lvf.sraa(decs,
                    rfactor=1.5,
                    downscaler=lvf.kernels.Bicubic(b=-1 / 2, c=1 / 4).scale)
    clmp = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.5)

    sraa_strong = flt.transpose_sraa(decs,
                                     rfactor=1.2,
                                     downscaler=lvf.kernels.Bicubic(b=-1 / 2,
                                                                    c=1 /
                                                                    4).scale)
    clmp = lvf.rfs(clmp, sraa_strong, [])

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

    # Debanding and graining
    deband = core.average.Mean([
        flt.masked_f3kdb(darken, rad=18, thr=[28, 24]),
        flt.masked_placebo(darken, rad=15, thr=4)
    ])

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

    return grain
예제 #7
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)
예제 #8
0
def do_filter():
    """Vapoursynth filtering"""
    def _fsrcnnx(clip: vs.VideoNode, width: int, height: int) -> vs.VideoNode:
        blank = core.std.BlankClip(clip, format=vs.GRAY16, color=128 << 8)
        clip = join([clip, blank, blank])
        clip = core.placebo.Shader(clip, 'FSRCNNX_x2_56-16-4-1.glsl',
                                   clip.width * 2, clip.height * 2)
        return core.resize.Spline36(get_y(clip), width, height)

    src = SRC_CUT

    fe = lvf.ef(src, [1, 1, 1])
    fe = depth(fe, 16)

    h = 864
    w = get_w(864)
    b, c = 0, 1 / 2
    luma = get_y(fe)
    descale = core.descale.Debicubic(depth(luma, 32), w, h, b, c)
    descale = depth(descale, 16)

    rescale_a = nnedi3_rpow2(descale,
                             2,
                             src.width,
                             src.height,
                             nns=4,
                             qual=2,
                             pscrn=2)
    rescale_b = _fsrcnnx(descale, src.width, src.height)
    rescale = core.std.Merge(rescale_a, rescale_b, 0.75)

    rescale_mask = vrf.drm(fe, 864, b=b, c=c, mthr=80, sw=4, sh=4)
    rescale = core.std.MaskedMerge(rescale, luma, rescale_mask)

    rescale = lvf.rfs(rescale, luma, [(OPSTART + 483, OPSTART + 721),
                                      (OPSTART + 822, OPSTART + 1083)])
    merge = core.std.ShufflePlanes([rescale, fe], [0, 1, 2], vs.YUV)

    antialias = join([lvf.sraa(plane) for plane in split(merge)])
    antialias = lvf.rfs(merge, antialias, [(2836, 2870)])

    denoise = core.knlm.KNLMeansCL(antialias,
                                   a=2,
                                   h=0.65,
                                   d=0,
                                   device_type='gpu',
                                   channels='UV')

    preden = CoolDegrain(denoise,
                         tr=2,
                         thsad=60,
                         blksize=8,
                         overlap=4,
                         plane=4)
    diff = core.std.MakeDiff(denoise, preden)
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=3000, brz_b=1500)

    deband_a = dbs.f3kpf(preden, 17, 42, 42)
    deband_b = core.placebo.Deband(preden,
                                   radius=17,
                                   threshold=6,
                                   iterations=1,
                                   grain=0,
                                   planes=1 | 2 | 4)
    deband = lvf.rfs(deband_a, deband_b, [(2081, 2216), (2450, 2550),
                                          (3418, 3452), (3926, 3926)])

    deband = core.std.MaskedMerge(deband, preden, deband_mask)
    deband = core.std.MergeDiff(deband, diff)

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

    return final
예제 #9
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    # 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,
                                  planes=[0, 1, 2]).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)

    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, 41)
    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)
    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

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
예제 #10
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])
예제 #11
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=7, top=0, right=11, bottom=22)
        endcard = core.resize.Bicubic(endcard, ref.width, ref.height, vs.RGBS, dither_type='error_diffusion')

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

        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.4, cont=1.2)


    def _perform_motion_mask(clip: vs.VideoNode, brz: int)-> vs.VideoNode:
        clip = depth(clip, 8)
        sup = core.hqdn3d.Hqdn3d(clip).neo_fft3d.FFT3D().mv.Super(sharp=1)
        fv1 = core.mv.Analyse(sup, isb=False, delta=1, truemotion=False, dct=2)
        fv2 = core.mv.Analyse(sup, isb=True, delta=1, truemotion=True, dct=2)

        momask1 = core.mv.Mask(clip, fv1, ml=2, kind=1)
        momask2 = core.mv.Mask(clip, fv2, ml=3, kind=1)
        momask = core.std.Merge(momask1, momask2).rgvs.RemoveGrain(3).std.Binarize(brz)
        momask = momask.std.Minimum().std.Minimum()

        return depth(get_y(momask), 16)


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

    denoise_a = CoolDegrain(src, tr=2, thsad=48, blksize=8, overlap=4, plane=4)
    denoise = denoise_a


    antialias = _nneedi3_clamp(denoise)
    antialias_a = TAAmbk(antialias, aatype='Eedi3', cycle=3)
    antialias_b = lvf.sraa(denoise, 2, 13)

    motion_mask = _perform_motion_mask(denoise[16914:17001], 140).std.FreezeFrames([0, 18, 57], [2, 38, 86], [2, 38, 57])
    motion_mask = insert_clip(src.std.BlankClip(format=vs.GRAY16), motion_mask, 16914)


    antialias = lvf.rfs(antialias, core.std.MaskedMerge(antialias_a, antialias, motion_mask), [(16914, 17000)])
    antialias = lvf.rfs(antialias, antialias_b, [(18084, 18179)])


    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 = deband_a


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


    ending = lvf.rfs(grain, src, [(32079, 33098)])


    endcard = _perform_endcard(r'[BDMV][200902][Magia Record][Vol.5]\Scans\endcard13_front_descreen.png', src)
    endcard_length = 119
    final = core.std.Splice([ending, 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
예제 #12
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)
예제 #13
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    ep11 = JPBD_11.src_cut

    opstart = 0
    opstart_ep11, opend_ep11 = 744, 3140
    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')

    # Fix compositing error in the OP
    ncop, op_11 = src, ep11[opstart_ep11:opend_ep11 + 1]
    fix = lvf.rfs(ncop, op_11, [(0, 79), (1035, 1037)])
    src = depth(fix, 32)

    def denoise_and_rescale(clip):
        denoise = hybrid_denoise(clip, 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)
        return depth(merged, 16)

    out = denoise_and_rescale(src)
    to_zoom = denoise_and_rescale(depth(JPBD_11.src_cut[8590:8605], 32))

    zoom = core.std.FrameEval(to_zoom, partial(_zoom_prog, clip=to_zoom))
    out = insert_clip(out, zoom, 1685)

    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, show=False)
    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')
    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, 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

    return depth(out, 10)
예제 #14
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)


    h = 720
    w = get_w(h)
    # getnative script returns 0.2 0.5 as best combo but it introduces too much halos.
    # I think it's plain mitchell but robidoux is good too and very slightly sharp.
    b, c = vdf.get_bicubic_params('robidoux')
    opstart = 0



    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, show=False)
    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')
    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, 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


    return depth(out, 10)
예제 #15
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=10,
                                   top=17,
                                   right=17,
                                   bottom=23)
        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')

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

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

    denoise = CoolDegrain(src, tr=2, thsad=48, blksize=8, overlap=4, plane=4)

    antialias_a = _nneedi3_clamp(denoise)

    antialias_b = lvf.sraa(denoise, rep=6)
    antialias = lvf.rfs(antialias_a, antialias_b, [(29453, 29476),
                                                   (29510, 29532),
                                                   (29640, 29663),
                                                   (29775, 29798),
                                                   (29866, 29889),
                                                   (30011, 30034)])

    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 = core.neo_f3kdb.Deband(antialias,
                                   17,
                                   42,
                                   42,
                                   42,
                                   12,
                                   0,
                                   sample_mode=4,
                                   keep_tv_range=True)
    deband = core.std.MaskedMerge(deband, antialias, line_mask)

    grain_a = kgf.adaptive_grain(deband, 0.25, luma_scaling=10)
    grain_b = adptvgrnMod(deband,
                          2,
                          size=2,
                          luma_scaling=2,
                          static=False,
                          grain_chroma=False)
    grain = lvf.rfs(grain_a, grain_b, [(5149, 5598), (8691, 10137)])

    borders_mask = vdf.region_mask(
        src.std.BlankClip(format=vs.GRAY16, color=(256 << 8) - 1), 240 + 2,
        240 + 2, 0, 0)
    borders = core.std.MaskedMerge(src, grain, borders_mask)
    borders = lvf.rfs(grain, borders, [(5149, 5598)])

    endcard = _perform_endcard(
        '[BDMV][200304][Magia Record][Vol.1]/Scans/endcard1_front_descreen.png',
        src)
    endcard_length = 119
    final = core.std.Splice([borders, 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
예제 #16
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)
    edstart, edend = 13572, 15642

    denoise = mvf.BM3D(src, 1.1, radius1=1, depth=16)
    out = denoise

    antialias = lvf.sraa(out,
                         2,
                         13,
                         downscaler=core.resize.Bicubic,
                         gamma=500,
                         nrad=2,
                         mdis=16)
    out = antialias

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2250,
                                          brz_b=1600).std.Median()
    deband = dbs.f3kbilateral(out, 17, 48, 48)
    deband_a = dbs.f3kbilateral(out, 22, 96, 96)
    deband = lvf.rfs(deband, deband_a, [(edstart, edend)])
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband

    grain = core.grain.Add(out, 0.3, constant=True)
    out = grain

    endcard = endcard_source(
        r'endcards\yande.re 619247 cleavage cocytus crossover dress emilia_(re_zero) isekai_quartet masha mecha neko overlord thighhighs uniform wings youjo_senki.jpg',
        src)
    endcard_ar = endcard.width / endcard.height
    endcard_ev = bool(endcard.format.name == 'YUV420P8')

    endcard = depth(endcard, 16)
    endcard = gf.MaskedDHA(endcard,
                           rx=1.4,
                           ry=1.4,
                           darkstr=0.3,
                           brightstr=1.0,
                           maskpull=48,
                           maskpush=140)
    endcard = dbs.f3kpf(endcard, 22, 48, 48).grain.Add(10, constant=True)

    if endcard_ar > 16 / 9:
        w, h = get_w(src.height, endcard_ar, only_even=endcard_ev), src.height
    elif endcard_ar < 16 / 9:
        w, h = src.width, get_h(src.width, endcard_ar, only_even=endcard_ev)
    else:
        w, h = src.width, src.height

    endcard = core.resize.Bicubic(endcard,
                                  w,
                                  h,
                                  range_in=1,
                                  range=0,
                                  dither_type='error_diffusion')
    endcard = core.std.CropAbs(endcard,
                               1920,
                               1080,
                               top=round((endcard.height - 1080) / 2 / 2) * 2)
    final = core.std.Splice([out, endcard * (17263 - src.num_frames)],
                            mismatch=True)

    return core.resize.Bicubic(final,
                               format=vs.YUV420P10,
                               dither_type='error_diffusion')
예제 #17
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    denoise = mvf.BM3D(out, [2.5, 1.5], radius1=1)
    diff = core.std.MakeDiff(out, denoise)
    out = denoise

    luma = get_y(out)
    dehalo = gf.MaskedDHA(luma,
                          rx=2.5,
                          ry=2.5,
                          darkstr=0.15,
                          brightstr=1.2,
                          maskpull=48,
                          maskpush=140)
    out = dehalo

    dering = gf.HQDeringmod(out, sharp=3, drrep=24, thr=24, darkthr=0)
    out = dering

    antialias_mask = gf.EdgeDetect(out, 'FDOG')
    antialias = lvf.sraa(out,
                         1.5,
                         13,
                         gamma=100,
                         downscaler=core.resize.Spline64)
    out = core.std.MaskedMerge(out, antialias, antialias_mask)

    out = vdf.merge_chroma(out, denoise)

    warp = xvs.WarpFixChromaBlend(out, 64, depth=8)
    out = warp

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

    grain_original = core.std.MergeDiff(out, diff)
    grain_new = core.grain.Add(out, 0.15, 0, constant=True)
    grain_mask = core.adg.Mask(out.std.PlaneStats(),
                               30).std.Expr(f'x x {96<<8} - 0.25 * +')
    grain = core.std.MaskedMerge(grain_new, grain_original, grain_mask)
    out = grain

    # Ending credits
    antialias_ed_mask = gf.EdgeDetect(src, 'FDOG')
    antialias_ed = lvf.sraa(src, 2, 13)
    antialias_ed = core.std.MaskedMerge(out, antialias_ed, antialias_ed_mask)

    cred = lvf.rfs(
        out,
        core.std.MaskedMerge(antialias_ed, src,
                             lvf.src('spe_mask/03.png', src)[0]),
        [(1800, src.num_frames - 1)])
    out = cred

    return depth(out, 10)
예제 #18
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])
예제 #19
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main filterchain"""
    import lvsfunc as lvf
    import rekt
    import vardefunc as vdf
    from awsmfunc import bbmod
    from ccd import ccd
    from muvsfunc import SSIM_downsample
    from vsutil import depth, get_y

    src = JP_BD.clip_cut
    op1 = JP_NCOP.clip_cut  # Minor composition fix
    src = lvf.rfs(src, op1, [(1119, 1120)])

    rkt = rekt.rektlvls(src, [0, -1], [30, 17], [0], [17])
    bb_y = bbmod(rkt,
                 top=2,
                 left=2,
                 right=2,
                 bottom=2,
                 u=False,
                 v=False,
                 blur=9999)
    bb_uv = bbmod(bb_y, left=2, right=2, y=False)
    bb = depth(bb_uv, 32)

    descale = lvf.kernels.Spline36().descale(get_y(bb), 1280, 720)
    up_chr = vdf.scale.to_444(bb, 1920, 1080, True).resize.Bicubic(1280, 720)
    descale_merge = vdf.misc.merge_chroma(descale, up_chr)
    denoise_down = lvf.deblock.vsdpir(descale_merge,
                                      strength=0.5,
                                      mode='deblock',
                                      matrix=1,
                                      i444=True,
                                      cuda=True)

    supersample = vdf.scale.nnedi3_upscale(get_y(denoise_down))
    downscaled = SSIM_downsample(supersample,
                                 bb.width,
                                 bb.height,
                                 smooth=((3**2 - 1) / 12)**0.5,
                                 sigmoid=True,
                                 filter_param_a=0,
                                 filter_param_b=0)

    scaled = vdf.misc.merge_chroma(downscaled, bb)
    scaled = depth(scaled, 16)

    den_uv = ccd(scaled, matrix='709')
    decs = vdf.noise.decsiz(den_uv, sigmaS=8, min_in=200 << 8, max_in=232 << 8)

    nn_aa = lvf.aa.nnedi3(opencl=True, dh=False)(decs)
    sraa = lvf.sraa(decs, rfactor=1.75)
    clmp = lvf.aa.clamp_aa(decs, nn_aa, sraa)

    dehalo = lvf.dehalo.masked_dha(clmp, brightstr=0.65)

    deband = flt.masked_f3kdb(dehalo, rad=17, thr=[24, 16], grain=[24, 12])

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

    no_flt = lvf.rfs(grain, depth(bb, 16), no_filter)

    return no_flt
예제 #20
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])
예제 #21
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)
예제 #22
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    out = depth(src, 16)

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

    y = get_y(out)
    lineart = core.std.Sobel(y).std.Binarize(
        75 << 8).std.Maximum().std.Inflate()

    antialias = lvf.sraa(y,
                         1.5,
                         9,
                         downscaler=core.resize.Spline36,
                         gamma=200,
                         mdis=18)

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

    minmax = core.std.Expr([y, sharp, antialias], 'x y z min max y z max min')
    merge = core.std.MaskedMerge(y, minmax, lineart)
    out = vdf.merge_chroma(merge, out)

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

    deband = dbs.f3kpf(out, 17, 24, 24)
    deband_b = dbs.f3kbilateral(out, 20, 128, 128)
    deband = lvf.rfs(deband, deband_b, [(17700, 17803), (22056, 22088),
                                        (22136, 22170)])
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    grain = adptvgrnMod(out,
                        0.2,
                        0.1,
                        1.25,
                        luma_scaling=14,
                        sharp=80,
                        static=False,
                        lo=19,
                        hi=[192, 240])
    out = grain

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 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, ...]]:
    """Main filterchain"""
    import EoEfunc as eoe
    import havsfunc as haf
    import kagefunc as kgf
    import lvsfunc as lvf
    import vardefunc as vdf
    from adptvgrnMod import adptvgrnMod
    from ccd import ccd
    from vsdpir import DPIR
    from vsutil import depth

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return out
예제 #25
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import EoEfunc as eoe
    import lvsfunc as lvf
    import vardefunc as vdf
    from ccd import ccd
    from finedehalo import fine_dehalo
    from vsutil import depth, get_y

    src, ep = JP_BD.clip_cut, JP_EP.clip_cut
    src = lvf.rfs(src, ep, [(811, 859)])
    src = depth(src, 16)

    # This noise can burn in hell.
    denoise_pre = get_y(src.dfttest.DFTTest(sigma=1.0))
    denoise_ret = core.retinex.MSRCP(denoise_pre,
                                     sigma=[50, 200, 350],
                                     upper_thr=0.005)
    denoise_mask = flt.detail_mask(denoise_ret, sigma=2.0,
                                   lines_brz=3000).rgvs.RemoveGrain(4)

    denoise_pre = core.dfttest.DFTTest(src, sigma=4.0)
    denoise_smd = eoe.dn.CMDegrain(src,
                                   tr=5,
                                   thSAD=275,
                                   freq_merge=True,
                                   prefilter=denoise_pre)
    denoise_masked = core.std.MaskedMerge(denoise_smd, src, denoise_mask)

    denoise_uv = ccd(denoise_masked, threshold=6)
    decs = vdf.noise.decsiz(denoise_uv,
                            sigmaS=8,
                            min_in=200 << 8,
                            max_in=235 << 8)

    # F**K THIS SHOW'S LINEART HOLY SHIT
    baa = lvf.aa.based_aa(decs.std.Transpose(), str(shader_file), gamma=120)
    baa = lvf.aa.based_aa(baa.std.Transpose(), str(shader_file), gamma=120)
    sraa = lvf.sraa(decs, rfactor=1.4)
    clmp_aa = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.65)

    # AAing introduces some haloing (zzzzzz)
    restr_edges = fine_dehalo(clmp_aa, decs)
    restr_dark = core.std.Expr([clmp_aa, restr_edges], "x y min")

    deband = core.average.Mean([
        flt.masked_f3kdb(restr_dark, rad=17, thr=[28, 20], grain=[12, 8]),
        flt.masked_f3kdb(restr_dark, rad=21, thr=[36, 32], grain=[24, 12]),
        flt.masked_placebo(restr_dark, rad=6.5, thr=2.5, itr=2, grain=4)
    ])

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

    return grain
예제 #26
0
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]:
    """Main VapourSynth filterchain"""
    import EoEfunc as eoe
    import lvsfunc as lvf
    import vardefunc as vdf
    from ccd import ccd
    from finedehalo import fine_dehalo
    from vsutil import depth, get_y, insert_clip

    src = JP_BD.clip_cut
    src_c = src
    src_ncop, src_nced = JP_NCOP.clip_cut, JP_NCED.clip_cut
    b = core.std.BlankClip(src, length=1)

    # OP/ED stack comps to check if they line up
    if opstart is not False:
        op_scomp = lvf.scomp(src[opstart:opstart+src_ncop.num_frames-1]+b, src_ncop[:-op_offset]+b) \
            .text.Text('src', 7).text.Text('op', 9)
    if edstart is not False:
        ed_scomp = lvf.scomp(src[edstart:edstart+src_nced.num_frames-1]+b, src_nced[:-ed_offset]+b) \
            .text.Text('src', 7).text.Text('ed', 9)

    # Splicing in NCs and diff'ing back the credits
    if opstart is not False:
        src = insert_clip(src, src_ncop[:-op_offset], opstart)
        src = lvf.rfs(src, src_c, [(opstart + 811, opstart + 859)])
    if edstart is not False:
        src = insert_clip(src, src_nced[:-ed_offset], edstart)

    den_src, den_ncs = map(partial(core.dfttest.DFTTest, sigma=10),
                           [src_c, src])
    den_src, den_ncs = depth(den_src, 32), depth(den_ncs, 32)
    diff = core.std.MakeDiff(den_src, den_ncs).dfttest.DFTTest(sigma=50.0)

    # For some reason there's noise from previous credits remaining? Removing that here
    diff_brz = vdf.misc.merge_chroma(diff.std.Binarize(0.03), diff)
    diff = core.std.Expr([diff, diff_brz], "x y min")

    src = depth(src, 16)

    # This noise can burn in hell.
    denoise_pre = get_y(src.dfttest.DFTTest(sigma=1.0))
    denoise_ret = core.retinex.MSRCP(denoise_pre,
                                     sigma=[50, 200, 350],
                                     upper_thr=0.005)
    denoise_mask = flt.detail_mask(denoise_ret, sigma=2.0,
                                   lines_brz=3000).rgvs.RemoveGrain(4)

    denoise_pre = core.dfttest.DFTTest(src, sigma=4.0)
    denoise_smd = eoe.dn.CMDegrain(src,
                                   tr=5,
                                   thSAD=275,
                                   freq_merge=True,
                                   prefilter=denoise_pre)
    denoise_masked = core.std.MaskedMerge(denoise_smd, src, denoise_mask)

    denoise_uv = ccd(denoise_masked, threshold=6)
    decs = vdf.noise.decsiz(denoise_uv,
                            sigmaS=8,
                            min_in=200 << 8,
                            max_in=235 << 8)

    # F**K THIS SHOW'S LINEART HOLY SHIT
    baa = lvf.aa.based_aa(decs.std.Transpose(), str(shader_file), gamma=120)
    baa = lvf.aa.based_aa(baa.std.Transpose(), str(shader_file), gamma=120)
    sraa = lvf.sraa(decs, rfactor=1.4)
    clmp_aa = lvf.aa.clamp_aa(decs, baa, sraa, strength=1.65)

    # AAing introduces some haloing (zzzzzz)
    restr_edges = fine_dehalo(clmp_aa, decs)
    restr_dark = core.std.Expr([clmp_aa, restr_edges], "x y min")

    # Masking credits at the end if there's no NCED
    get_max = core.std.Expr([restr_dark, decs], "x y max")

    if opstart is False:
        restr_dark = lvf.rfs(restr_dark, get_max, [(None, 3500)])
    if edstart is False:
        restr_dark = lvf.rfs(restr_dark, get_max, [(-5000, None)])

    deband = core.average.Mean([
        flt.masked_f3kdb(restr_dark, rad=17, thr=[28, 20], grain=[12, 8]),
        flt.masked_f3kdb(restr_dark, rad=21, thr=[36, 32], grain=[24, 12]),
        flt.masked_placebo(restr_dark, rad=6.5, thr=2.5, itr=2, grain=4)
    ])

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

    merge_creds = core.std.MergeDiff(depth(grain, 32), diff)

    return merge_creds
예제 #27
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)
예제 #28
0
def transpose_sraa(clip: vs.VideoNode, **kwargs: Any) -> vs.VideoNode:
    from lvsfunc import sraa

    aa = sraa(clip.std.Transpose(), **kwargs)
    return sraa(aa.std.Transpose(), **kwargs)
예제 #29
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    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, [(828, 836)])
    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

    ref = decomb
    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()
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask),
                     [(0, 725), (31741, 33864)])
    antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic)
    credit = lvf.rfs(credit, core.std.MaskedMerge(out, antialias, credit_mask),
                     [(833, 933), (1060, 1229), (1716, 1887), (2665, 2830),
                      (4813, 4947), (8179, 8272), (13757, 13810),
                      (20630, 20737), (20866, 20951), (21338, 21409),
                      (21480, 21520), (24719, 24786), (24829, 24869),
                      (28206, 28298), (28299, 28426), (33927, 34046)])
    out = credit

    return depth(out, 10)
예제 #30
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)

    h = 882
    w = get_w(h)
    kernel = 'lanczos'
    taps = 5

    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 = antialias

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

    deband = dbs.f3kpf(out, 17, 30, 30)
    deband_b = placebo.deband(out, 24, 8, 5)
    deband_c = dbs.f3kpf(out, 17, 54, 48)
    deband = lvf.rfs(deband, deband_b, [(0, 105)])
    deband = lvf.rfs(deband, deband_c, [(25188, 25220)])

    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

    credit_mask = vdf.drm(src, h, kernel, taps, mthr=40, sw=4, sh=4)
    credit = lvf.rfs(out, core.std.MaskedMerge(out, src, credit_mask, 0),
                     [(196, 2107), (11352, 11416), (30402, 30602),
                      (31431, 33501), (33837, src.num_frames - 1)])
    credit = lvf.rfs(credit, src, [(3856, 3897)])
    out = credit

    return depth(out, 10)