示例#1
0
def do_filter():
    """Vapoursynth filtering"""

    def _fsrcnnx(clip: vs.VideoNode) -> vs.VideoNode:
        blank = core.std.BlankClip(clip, format=vs.GRAY16, color=128 << 8)
        clip = join([clip, blank, blank])
        # The chroma is upscaled with box AKA nearest but we don't care since we only need the luma.
        # It's especially faster and speed is the key :^)
        clip = core.placebo.Shader(clip, 'Shaders/FSRCNNX_x2_56-16-4-1.glsl', clip.width*2, clip.height*2, filter='box')
        return get_y(clip)

    def _nnedi(clip: vs.VideoNode) -> vs.VideoNode:
        args = dict(nsize=4, nns=4, qual=2, pscrn=2)
        clip = clip.std.Transpose().nnedi3.nnedi3(0, True, **args) \
            .std.Transpose().nnedi3.nnedi3(0, True, **args)
        return core.resize.Spline36(clip, src_top=.5, src_left=.5)

    def _rescale(clip: vs.VideoNode, thr: int, downscaler: Callable[[vs.VideoNode], vs.VideoNode]) -> vs.VideoNode:
        return downscaler(core.std.Merge(_nnedi(clip), _fsrcnnx(clip), thr))

    src = SRC_CUT

    fixedges = lvf.ef(src, [1, 1, 1])

    denoise = CoolDegrain(depth(fixedges, 16), tr=1, thsad=48, thsadc=84, blksize=8, overlap=4, plane=4)


    w, h = 1280, 720
    b, c = vdf.get_bicubic_params('robidoux')
    luma = get_y(denoise)
    descale = depth(core.descale.Debicubic(depth(luma, 32), w, h, b, c), 16)
    rescale = _rescale(descale, 0.55, lambda c: core.resize.Bicubic(c, src.width, src.height, filter_param_a=0, filter_param_b=0))

    line_mask = lvf.denoise.detail_mask(rescale, brz_a=7000, brz_b=2000)
    rescale = core.std.MaskedMerge(luma, rescale, line_mask)



    credit_mask = vdf.drm(luma, b=b, c=c, mode='ellipse', sw=3, sh=3)
    credit = core.std.MaskedMerge(rescale, luma, credit_mask)


    merged = vdf.merge_chroma(credit, denoise)


    deband_mask = lvf.denoise.detail_mask(merged, brz_a=3000, brz_b=1500)
    deband = dbs.f3kpf(merged, 17, 36, 36)
    deband = core.std.MaskedMerge(deband, merged, deband_mask)
    grain = core.neo_f3kdb.Deband(deband, preset='depth', grainy=32, output_depth=10,
                                  dither_algo=3, keep_tv_range=True)

    return grain
示例#2
0
def do_filter():
    src = JPBD.src_cut

    fixedges = lvf.ef(src, [2, 1, 1])
    fixedges = depth(fixedges, 16)
    out = fixedges


    h = 720
    w = get_w(h)
    kernel = 'bilinear'


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


    luma = get_y(out)

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

    descale = kgf.get_descale_filter(kernel)(depth(luma, 32), w, h)
    rescale = vdf.fsrcnnx_upscale(depth(descale, 16), None, src.height, 'shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  partial(muvf.SSIM_downsample, kernel='Bicubic'))
    rescale = core.std.MaskedMerge(luma, rescale, line_mask)


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


    # Slight sharp though CAS
    sharp = hvf.LSFmod(out, strength=95, 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=36, depth=6)
    out = warp



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


    grain = placebo.deband(out, iterations=0, grain=6, chroma=False)
    grain_mask = core.adg.Mask(out.std.PlaneStats(), 14).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.std.MaskedMerge(out, grain, grain_mask)
    out = grain

    rescale_mask = vdf.drm(luma, h, kernel, sw=4, sh=4)
    ref = fixedges
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask, 0), [(12805, src.num_frames-1)])
    out = credit


    return depth(out, 10)
示例#3
0
def do_filter():
    """Vapoursynth filtering"""
    scene_change = []
    with open('k.log') as file:
        lines = file.readlines()
        for line in lines:
            line = line.split()
            scene_change.append(int(line[0]))

    src = CLIP_SRC

    # Lol?
    border = awf.bbmod(src, 4, thresh=128, blur=15, y=True, u=True, v=True)
    border = lvf.ef(border, [6, 3, 3], radius=[12, 6, 6])
    border = lvf.rfs(src, border, scene_change)
    out = depth(border, 16)

    # joletb has stronk eyes
    planes = split(out)
    planes[1], planes[2] = [
        core.resize.Spline16(plane, src_top=-0.25) for plane in planes[1:]
    ]
    out = join(planes)

    # qual=2 produces weird artefacts and a stronger alpha/beta/gamma smudges details.
    new_fields = core.eedi3m.EEDI3(out,
                                   1,
                                   alpha=0.25,
                                   beta=0.3,
                                   gamma=400,
                                   nrad=3,
                                   mdis=20,
                                   vcheck=3,
                                   sclip=core.nnedi3.nnedi3(out,
                                                            1,
                                                            nsize=3,
                                                            nns=3,
                                                            qual=1,
                                                            pscrn=4))
    out = new_fields

    # omegartifacted frames
    def freeze_frame_after(clip, frame):
        return core.std.FreezeFrames(clip, frame, frame, frame + 1)

    def freeze_frame_before(clip, frame):
        return core.std.FreezeFrames(clip, frame, frame, frame - 1)

    cursed_frames = [
        2326, 8907, 12211, 12551, 13990, 14403, 15462, 17673, 19382, 23099,
        23738, 24031, 24802, 25083
    ]
    for cursed_frame in cursed_frames:
        out = freeze_frame_after(out, cursed_frame)
    cursed_frames = [5695, 9115, 9116, 17671, 18432]
    for cursed_frame in cursed_frames:
        out = freeze_frame_before(out, cursed_frame)

    # omegartifacted frames ²
    denoise_li = hvf.SMDegrain(out, thSAD=200)
    denoise_hi = hvf.SMDegrain(out, thSAD=350)
    denoise = lvf.rfs(denoise_li, denoise_hi, scene_change)

    def hard_denoise(clip):
        clip = hvf.SMDegrain(clip, thSAD=500)
        clip = knlm_denoise(clip, (2, 2), dict(a=8))
        return clip

    cursed_frames = [
        595, 1191, 2643, 2663, 2664, 2665, 2666, 2667, 2671, 2672, 2674, 2675,
        2679, 3999, 4419, 6351, 6355, 6547, 8906, 11731, 14176, 14177, 14178,
        14179, 18430, 18435, 18437, 18438, 18439, 27766
    ]
    cursed_frames += range(10767, 10776)
    cursed_frames += range(25013, 25018)
    cursed_frames += range(27663, 27668)
    cursed_frames += range(29642, 29646)
    cursed_frames += range(31384, 31388)

    uncursed = hard_denoise(out)
    denoise = lvf.rfs(denoise, uncursed, cursed_frames)
    out = denoise

    # It helps to fix the the aliasing left
    antialias = lvf.sraa(out, rep=13)
    out = antialias

    # Compensative line darkening and sharpening
    luma = get_y(out)
    darken = hvf.Toon(luma, 0.20)
    darken_mask = core.std.Expr([
        core.std.Convolution(
            luma, [5, 10, 5, 0, 0, 0, -5, -10, -5], divisor=4, saturate=False),
        core.std.Convolution(
            luma, [5, 0, -5, 10, 0, -10, 5, 0, -5], divisor=4, saturate=False)
    ], [
        'x y max {neutral} / 0.86 pow {peak} *'.format(
            neutral=1 << (luma.format.bits_per_sample - 1),
            peak=(1 << luma.format.bits_per_sample) - 1)
    ])
    darken = core.std.MaskedMerge(luma, darken, darken_mask)

    # Slight sharp through CAS
    sharp = hvf.LSFmod(darken,
                       strength=65,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = vdf.merge_chroma(sharp, out)

    # Chroma planes are pure crap
    chromableed = xvs.WarpFixChromaBlend(out, 96, depth=8)
    out = chromableed

    detail_mask = lvf.denoise.detail_mask(out, brz_a=2700, brz_b=1500)
    deband = placebo.deband(out, 17, 5.75, grain=4)
    deband_b = placebo.deband(out, 24, 8, 2, grain=4)
    deband_c = placebo.deband(out, 17, 8, grain=4)
    deband_d = placebo.deband(out, 20, 12, 3, grain=4)

    deband = lvf.rfs(deband, deband_b, [(4596, 4669), (23036, 23098)])
    deband = lvf.rfs(deband, deband_c, [(1646, 1711), (29768, 29840),
                                        (29932, 30037), (30163, 30243)])
    deband = lvf.rfs(deband, deband_d, [(1712, 1830)])

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

    return depth(out, 10)
示例#4
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
示例#5
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    h = 720
    w = get_w(h)

    fixedges = lvf.ef(src, [2, 1, 1])
    out = depth(fixedges, 16)

    denoise = hybrid_denoise(out, 0.65, 3)
    denoise_b = hybrid_denoise(out, 0.3, 1)
    denoise_c = hvf.KNLMeansCL(out, 5, 3, 6, 2, device_type='gpu', device_id=0)

    denoise = lvf.rfs(denoise, denoise_b, [(75124, 82725)])
    denoise = vdf.fade_filter(denoise, denoise, denoise_c, 82726, 82790)
    denoise = lvf.rfs(denoise, denoise_c, [(82791, src.num_frames - 1)])

    diff = core.std.MakeDiff(out, denoise)
    out = denoise

    luma = get_y(out)

    line_mask = vdf.edge_detect(luma, 'FDOG', 7000, (1, 1))
    line_mask = iterate(line_mask, core.std.Median, 4)

    # Not FSRCNNX this time )^:
    descale = depth(core.descale.Debilinear(depth(luma, 32), w, h), 16)
    upscale = lvf.sraa(descale,
                       2,
                       3,
                       src.width,
                       src.height,
                       _ssim_downsample,
                       alpha=0.2,
                       beta=0.6,
                       gamma=400,
                       nrad=2,
                       mdis=15)
    rescaled = core.std.MaskedMerge(luma, upscale, line_mask)
    out = vdf.merge_chroma(rescaled, out)

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

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

    avg = out.std.PlaneStats()
    adg_mask16 = core.adg.Mask(avg, 16)

    grain_hi = core.std.MergeDiff(out, diff)
    grain_hi = core.std.Merge(grain_hi, out,
                              [0, 0.5])  # Half the grain on chroma planes
    grain_hi = core.std.MaskedMerge(out, grain_hi, core.adg.Mask(avg, 6))

    grain_lo = core.neo_f3kdb.Deband(out,
                                     preset='depth',
                                     grainy=24,
                                     keep_tv_range=True)
    grain_lo = core.std.MaskedMerge(grain_lo, grain_hi, core.adg.Mask(avg, 14))

    grain_b = core.std.MaskedMerge(out, out.grain.Add(0.1, constant=True),
                                   adg_mask16)

    grain = lvf.rfs(grain_hi, grain_lo, [(0, 16168), (24078, 41084),
                                         (63274, 75123)])
    grain = lvf.rfs(grain, grain_b, [(75124, 82725)])

    # Credits
    deband_c = placebo.deband(sharp, 17, 6, 3, 0)
    grain_c = core.std.MaskedMerge(deband_c,
                                   deband_c.grain.Add(6.5, constant=True),
                                   adg_mask16)
    grain = lvf.rfs(grain, grain_c, [(82791, src.num_frames - 1)])
    grain = vdf.fade_filter(grain, grain, grain_c, 82726, 82790)

    out = grain

    return depth(out, 10)