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

        luma = get_y(clip)

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

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

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

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

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


    antialias = _nneedi3_clamp(denoise)


    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 = kgf.adaptive_grain(deband, 0.25, luma_scaling=10)

    final = core.resize.Bicubic(grain, format=vs.YUV420P10, dither_type='error_diffusion')
    final = core.std.Limiter(final, 16, [235 << 2, 240 << 2])

    return depth(final, 10)
コード例 #2
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
コード例 #3
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
コード例 #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=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
コード例 #5
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=4, top=12, right=0, bottom=21)
        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)

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

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

    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)
    antialias_b = TAAmbk(denoise, aatype='Eedi3', mtype=1)
    antialias = lvf.rfs(antialias_a, antialias_b, [(9478, 9501)])

    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_c = core.neo_f3kdb.Deband(deband_a,
                                     20,
                                     64,
                                     64,
                                     64,
                                     24,
                                     0,
                                     sample_mode=2,
                                     keep_tv_range=True)

    deband = lvf.rfs(deband_a, deband_b, [(edstart + 1870, edstart + 1900)])
    deband = lvf.rfs(
        deband,
        core.std.MaskedMerge(
            deband_c, deband_a,
            to_gray(lvf.src('masks/magia_07_mask_01.png'), src)),
        [(6729, 6865)])

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

    borders = vdf.region_mask(grain, 240, 240, 0, 0)
    borders = lvf.rfs(grain, borders, [(25623, 25670)])

    endcard = _perform_endcard(
        '[BDMV][200610][Magia Record][Vol.3]/Scans/endcard7_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
コード例 #6
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=14,
                                   top=12,
                                   right=18,
                                   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)
    edstart = 32012

    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)
    antialias_b = lvf.sraa(denoise, 2, rep=13)
    antialias = lvf.rfs(antialias_a, antialias_b, [(14667, 14696)])

    predenoise = mClean(antialias, thSAD=200, chroma=False)
    detail_mask = lvf.denoise.detail_mask(predenoise,
                                          rad=2,
                                          radc=2,
                                          brz_a=3250,
                                          brz_b=1250)
    adapt_mask = core.adg.Mask(predenoise.std.PlaneStats(), 40)
    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_ca = dbs.f3kbilateral(deband_b, 8, 270, 270)
    deband_cb = dbs.f3kbilateral(deband_b, 12, 110, 110)
    deband_c = core.std.MaskedMerge(deband_ca, deband_cb, adapt_mask)

    deband = lvf.rfs(deband_a, deband_b, [(edstart + 1870, edstart + 1900),
                                          (13041, 13180), (13932, 13949),
                                          (14121, 14168), (14647, 14666)])
    deband = lvf.rfs(deband, deband_c, [(14667, 14669), (14673, 14674),
                                        (14676, 14677)])

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

    crop = core.std.Crop(grain, 0, 0, 132, 132)
    edgefixe = core.edgefixer.ContinuityFixer(crop, 0, [2, 1, 1], 0, [1, 1, 1])
    borders = core.std.AddBorders(edgefixe, 0, 0, 132, 132)
    borders = lvf.rfs(grain, borders, [(0, 2905)])

    endcard = _perform_endcard(
        '[BDMV][200304][Magia Record][Vol.1]/Scans/endcard3_front_descreen.png',
        src)
    endcard_length = 117
    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