def _perform_masks_credit(path: Path) -> List[MaskCredit]: return [ MaskCredit(lvf.src(str(mask)), int(str(mask.stem).split('_')[2]), int(str(mask.stem).split('_')[3])) for mask in path.glob('*') ]
from acsuite import eztrim from vsTAAmbk import TAAmbk from cooldegrain import CoolDegrain import vardefunc as vrf import debandshit as dbs import modfunc as mdf import havsfunc as hvf import muvsfunc as muvf import lvsfunc as lvf core.max_cache_size = 1024 * 16 PATH = r'アズールレーン\[200122]アニメ『アズールレーン』VOLUME 2\BD2\BDMV\STREAM\00001' SRC = PATH + '.m2ts' SRC_CLIP = lvf.src(SRC) FRAME_START, FRAME_END = 24, -26 SRC_CUT = SRC_CLIP[FRAME_START:FRAME_END] OPSTART, OPEND = 3309, 5466 EDSTART, EDEND = 32126, SRC_CUT.num_frames - 1 A_SRC = PATH + '.wav' A_SRC_CUT = PATH + '_cut_track_1.wav' A_ENC_CUT = PATH + '.m4a' NAME = sys.argv[0][:-3] QPFILE = NAME + '_qpfile.log' OUTPUT = NAME + '.264' CHAPTER = 'アズールレーン/chapter' + NAME[-2:] + '.txt' OUTPUT_FINAL = NAME + '.mkv'
#!/usr/bin/env python3 import vapoursynth as vs import audiocutter import lvsfunc as lvf from subprocess import call core = vs.core ts_in = r'Zesty Fries/00006.m2ts' src = lvf.src(ts_in) ac = audiocutter.AudioCutter() vid = ac.split(src, [(29921, 32845)]) ac.ready_qp_and_chapters(vid) vid.set_output(0) if __name__ == "__main__": ac.cut_audio(r'ToB_OP1_cut.flac', audio_source=r'Zesty Fries/00006.flac')
import sys from typing import Callable from pymkv import MKVFile, MKVTrack from acsuite import eztrim from vsutil import core, vs, depth, get_y, join from cooldegrain import CoolDegrain import vardefunc as vdf import debandshit as dbs import lvsfunc as lvf PATH = r'[BDMV] CHOYOYU\CHOYOYU_2\BDMV\STREAM\00003' SRC = PATH + '.m2ts' SRC_CLIP = lvf.src(PATH + '.dgi') FRAME_START, FRAME_END = 0, -24 SRC_CUT = SRC_CLIP[FRAME_START:FRAME_END] A_SRC = PATH + '.mka' A_SRC_CUT = PATH + '_cut_track_1.wav' A_ENC_CUT = PATH + '_track_1.m4a' NAME = sys.argv[0][:-3] QPFILE = NAME + '_qpfile.log' OUTPUT = NAME + '.264' CHAPTER = 'chapters/chapter' + NAME[-2:] + '.txt' OUTPUT_FINAL = NAME + '.mkv' X264 = r'C:\Encode Stuff\x264_tmod_Broadwell_r3000\mcf\x264_x64.exe' X264_ARGS = dict(
#!/usr/bin/env python3 import ntpath import os import subprocess import lvsfunc as lvf from acsuite import eztrim path_a = r'BDMV/[KUNO-DIY][BDMV][CLANNAD][Blu-ray BOX Disc 1-5 Fin]/CLANNAD_5/BDMV/STREAM/00002.m2ts' path_b = r'BDMV/[KUNO-DIY][BDMV][CLANNAD][Blu-ray BOX Disc 1-5 Fin]/CLANNAD_5/BDMV/STREAM/00004.m2ts' src_a = lvf.src(path_a) src_b = lvf.src(path_b) if __name__ == "__main__": paths = [path_a, path_b] clips = [src_a, src_b] files = [f"{ntpath.basename(__file__)[3:-3]}_{i}_cut.mka" for i in 'AB'] print("\n[*] Trimming tracks") for c, p, f in zip(clips, paths, files): print(f" [+] Trimming {f}") eztrim(c, (0, -48), p, f, quiet=True) print("\n[*] Writing concact file") concat = open(f"{ntpath.basename(__file__)[3:-3]}_concat.txt", "w") for f in files: print(f" [+] Appending {f[:-4]}.wav") concat.write(f"file {f[:-4]}.wav\n") concat.close()
paths = [ r'BDMV/Fate Extra Last Encore/Vol3/BDROM/BDMV/STREAM/00001.m2ts', r'BDMV/Fate Extra Last Encore/Vol3/BDROM/BDMV/STREAM/00010.m2ts', r'BDMV/Fate Extra Last Encore/Vol3/BDROM/BDMV/STREAM/00001.m2ts' ] files = [f"{ntpath.basename(__file__)[3:-3]}_{i}_cut.wav" for i in 'ABC'] trims = [(24, 33429), (24, -24), (33429, 0)] if __name__ == "__main__": print("\n[*] Trimming tracks") for p, f, t in zip(paths, files, trims): print(f" [+] Trimming {f} with trims {t}") eztrim(lvf.src(p), t, f"{os.path.splitext(p)[0]}.wav", f, quiet=True) print("\n[*] Writing concact file") concat = open(f"{ntpath.basename(__file__)[3:-3]}_concat.txt", "w") for f in files: print(f" [+] Adding {f}") concat.write(f"file {f}\n") concat.close() print("\n[*] Concatinating trimmed tracks") subprocess.run([ "ffmpeg", "-f", "concat", "-i", f"{ntpath.basename(__file__)[3:-3]}_concat.txt", "-loglevel", "panic", "-stats", "-c", "copy", f"{ntpath.basename(__file__)[3:-3]}_cut.wav" ]) print(" [+] Tracks successfully concatinated")
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src dbzone = (14775, 14846) opstart, opend = 1200, 3356 edstart, edend = 31888, src.num_frames - 1 h = 846 w = get_w(h) cubic_filters = ['catrom', 'mitchell', 'robidoux', 'robidoux sharp'] cubic_filters = [vdf.get_bicubic_params(cf) for cf in cubic_filters] degrain = hybrid_denoise(out, 0.35, 1.2, dict(a=2, d=1)) degrain_b = hybrid_denoise(out, 0.55, 3, dict(a=2, d=1)) degrain = lvf.rfs(degrain, degrain_b, [dbzone]) out = degrain y = get_y(out) y32 = depth(y, 32) lineart = vdf.edge_detect(y32, 'kirsch', 0.055, (1, 1)).std.Median().std.Inflate() descale_clips = [ core.descale.Debicubic(y32, w, h, b, c) for b, c in cubic_filters ] descale = core.std.Expr(descale_clips, 'x y z a min min min x y z max max min') conv = core.std.Convolution(descale, [1, 2, 1, 2, 0, 2, 1, 2, 1]) thr, coef = 0.013, 3 descale_fix = core.std.Expr([descale, conv], f'x y - abs {thr} < y x ?').std.PlaneStats() adapt_mask = core.adg.Mask( descale_fix, 12).std.Invert().std.Expr(f'x 0.5 - {coef} * 0.5 + 0 max 1 min') descale = core.std.MaskedMerge(descale, descale_fix, adapt_mask) upscale = vdf.fsrcnnx_upscale(descale, w * 2, h * 2, r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale, profile='zastin', sharpener=partial(gf.DetailSharpen, sstr=1.25, power=4)) aa_strong = sraa_eedi3(upscale, 13, alpha=0.3, beta=0.5, gamma=40) aa = aa_strong down = muvf.SSIM_downsample(aa, src.width, src.height, filter_param_a=0, filter_param_b=0) upscale = depth(core.std.MaskedMerge(y32, down, lineart), 16) merged = vdf.merge_chroma(upscale, out) out = merged # Very bad halo dehalo_a = gf.MaskedDHA(out, rx=2.75, ry=2.75, darkstr=0.25, brightstr=1.0, maskpull=48, maskpush=140) dehalo_a = core.std.MaskedMerge(out, dehalo_a, lvf.src('lapis_05_halomask_1.png', out)) dehalo_b = gf.MaskedDHA(out, rx=2.25, ry=2.25, darkstr=0.25, brightstr=1.0, maskpull=48, maskpush=140) dehalo = lvf.rfs(out, dehalo_a, [(11677, 11765)]) dehalo = lvf.rfs(dehalo, dehalo_b, [(20509, 20690), (21242, 21276), (25834, 25856), (26614, 26648), (26682, 26761), (27685, 27719), (27861, 27895), (27955, 28025)]) out = dehalo y = get_y(out) detail_light_mask = lvf.denoise.detail_mask(y, brz_a=2500, brz_b=1200) pf = iterate(out, core.std.Maximum, 2).std.Convolution([10] * 9, planes=0) diff = core.std.MakeDiff(out, pf) deband = core.f3kdb.Deband(pf, 17, 36, 36, 36, 12, 12, 2, keep_tv_range=True, output_depth=16) deband_b = core.f3kdb.Deband(pf, 17, 48, 48, 48, 12, 12, 2, keep_tv_range=True, output_depth=16) deband = lvf.rfs(deband, deband_b, [dbzone]) deband = core.std.MergeDiff(deband, diff) deband = core.std.MaskedMerge(deband, out, detail_light_mask) out = deband ref = degrain pfed = ref.std.Median().std.Convolution([1] * 9, planes=0) diff_ed = core.std.MakeDiff(ref, pfed) deband_ed = core.f3kdb.Deband(pfed, 22, 30, 30, 30, 32, 32, 2, keep_tv_range=True, output_depth=16) deband_ed = core.std.MergeDiff(deband_ed, diff_ed) out = lvf.rfs(out, deband_ed, [(edstart, edend)]) grain = adptvgrnMod(out, 0.25, 0.15, size=out.height / h, sharp=80, luma_scaling=10, static=True) out = grain # # Restore 1080p stuff ref = src rescale_mask = vdf.drm(ref, h, mthr=65, sw=4, sh=4) credit = out credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask, 0), [(opstart, opend), (3369, 3451)]) credit = lvf.rfs(credit, ref, [(18989, 19108)]) out = credit return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
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)
from vsutil import depth, get_y, get_w import lvsfunc as lvf import vapoursynth as vs core = vs.core X264 = r'C:\Encode Stuff\x264_tmod_Broadwell_r3007\mcf\x264_x64.exe' NAME = Path(sys.argv[0]).stem OUTPUT = NAME + '.264' NUM = NAME[-2:] VIDEO_FILES = ['FUNI/[HorribleSubs] Lapis ReLiGHTs - {} [1080p].mkv'.format(NUM), 'WKN/Lapis ReLIGHTs E{} [1080p][AAC][JapDub][GerSub][Web-DL].mkv'.format(NUM)] CLIPS_SRC = [lvf.src(c) for c in VIDEO_FILES] AUDIO_SRC = Path(VIDEO_FILES[1]).stem + 'mka' X264_ARGS = dict( threads=27, ref=16, trellis=2, bframes=16, b_adapt=2, direct='auto', deblock='-1:-1', me='umh', subme=10, psy_rd='0.90:0.00', merange=24, keyint=240, min_keyint=23, rc_lookahead=96, crf=15, qcomp=0.7, aq_mode=3, aq_strength=0.85 ) def do_filter(): """Vapoursynth filtering""" def _nnedi3(clip: vs.VideoNode, factor: float, args: dict)-> vs.VideoNode: upscale = clip.std.Transpose().nnedi3.nnedi3(0, True, **args) \ .std.Transpose().nnedi3.nnedi3(0, True, **args) sraa = _sraa(upscale, dict(nsize=3, nns=3, qual=1, pscrn=1)) return core.resize.Bicubic(sraa, clip.width*factor, clip.height*factor,
import placebo import xvs from vsutil import depth, get_y, split, join import lvsfunc as lvf import vapoursynth as vs core = vs.core X264 = 'x264_tmod' NAME = Path(sys.argv[0]).stem OUTPUT = NAME + '.264' VIDEO_FILE = 'mct.mkv' CLIP_SRC = lvf.src(VIDEO_FILE) vdf.set_ffms2_log_level('warning') AUDIO_SRC = Path(VIDEO_FILE).stem + '.eac3' X264_ARGS = dict(threads=12, ref=16, trellis=2, bframes=16, b_adapt=2, direct='auto', deblock='0:0', me='umh', subme=10, psy_rd='0.90:0.00', merange=32, keyint=240,
def filterchain() -> Union[vs.VideoNode, Tuple[vs.VideoNode, ...]]: """Main VapourSynth filterchain""" import debandshit as dbs import havsfunc as haf 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_w, get_y src = JP_BD.clip_cut src = depth(src, 16) rkt_a = rekt.rektlvls(src, [0, -1], [15, 15], [0, 1, 2, 3, -6, -4, -3, -2, -1], [13, 3, -1, 1, -1, 1, -2, 4, 11]) rkt_b = rekt.rektlvls(src, [0, 1, -2, -1], [12, -11, -11, 12], [0, 1, -2, -1], [12, -11, -11, 12]) bb_b = bbmod(rkt_b, 2, 2, 2, 2, blur=50, y=False) rkt = lvf.rfs(rkt_a, bb_b, [(2496, 2567)]) rkt = lvf.rfs(rkt, src, [(1589, 1660), (1733, 1800), (1873, 1943), (2016, 2046), (2119, 2141), (2214, 2279)]) ef = depth(rkt, 32) src_y = get_y(ef) pre_den = core.dfttest.DFTTest(src_y, sigma=3.0) l_mask = vdf.mask.FDOG().get_mask(pre_den, lthr=0.125, hthr=0.050).rgsf.RemoveGrain(4).rgsf.RemoveGrain(4) l_mask = l_mask.std.Minimum().std.Deflate().std.Median().std.Convolution([1] * 9).std.Maximum() # Descaling. descaled = lvf.kernels.Catrom().descale(src_y, get_w(720, src_y.width/src_y.height), 720) descaled = core.resize.Bicubic(descaled, format=vs.YUV444P16) # Slight AA in an attempt to forcibly fix starved lineart. baa = lvf.aa.based_aa(descaled, shader_file) sraa = lvf.aa.upscaled_sraa(descaled, rfactor=1.45) clamp_aa = lvf.aa.clamp_aa(descaled, baa, sraa, strength=1.15) clamp_aa = depth(get_y(clamp_aa), 32) # Doing a mixed reupscale using nn3/fsrcnnx, grabbing the darkest parts of each rescaled_nn3 = vdf.scale.nnedi3cl_double(clamp_aa, use_znedi=True, pscrn=1) rescaled_fsrcnnx = vdf.scale.fsrcnnx_upscale(clamp_aa, rescaled_nn3.width, rescaled_nn3.height, shader_file) rescaled = core.std.Expr([rescaled_nn3, rescaled_fsrcnnx], "x y min") downscaled = SSIM_downsample(rescaled, src_y.width, src_y.height, smooth=((3 ** 2 - 1) / 12) ** 0.5, sigmoid=True, filter_param_a=-1/2, filter_param_b=1/4) downscaled = core.std.MaskedMerge(src_y, downscaled, l_mask) scaled = depth(vdf.misc.merge_chroma(downscaled, ef), 16) # Clean frame for credit masking and/or NC creation purposes clean = lvf.src(r'assets/OP1/SW2OVABD_OP1_clean_canvas.png', ref=scaled) clean = lvf.rfs(scaled, clean, [(None, 71), (168, 239), (336, 407), (475, 546), (612, 683), (780, 851), (948, 1019), (1164, 1235), (1302, 1373), (1518, 1589), (1661, 1732), (1801, 1872), (1944, 2015), (2047, 2118), (2142, 2213), (2280, 2351), (2424, 2495), (2568, 2639), (2712, 2783)]) # Chroma warping to forcibly wrap it a bit nicer around the lineart. Also fixing slight shift. 4:2:0 was a mistake. cwarp = clean.warp.AWarpSharp2(thresh=72, blur=3, type=1, depth=6, planes=[1, 2]) # The textures and detail are very smeary, so gotta be careful not to make it even worse stab = haf.GSMC(cwarp, radius=3, planes=[0], thSAD=75) den_uv = ccd(stab, threshold=5, matrix='709') decs = vdf.noise.decsiz(den_uv, sigmaS=8.0, min_in=200 << 8, max_in=240 << 8) # Scenefiltered debanding. Not graining, since we kept most of the original grain anyway. deband_wk = dbs.debanders.dumb3kdb(decs, radius=16, threshold=[28, 0], grain=0) deband_wk = core.placebo.Deband(deband_wk, iterations=2, threshold=3.5, radius=12, grain=0, planes=2 | 4) # Strong denoising + debanding to hopefully deal with all the awful bands. Courtesy of :b:arde dft = core.dfttest.DFTTest(decs, sigma=4.0) ccd_uv = ccd(dft, threshold=10, matrix='709') f3k = dbs.debanders.dumb3kdb(ccd_uv, radius=8, threshold=[36, 24], grain=0) plac = flt.masked_placebo(f3k, rad=18, thr=5.5, itr=2, grain=3.0, mask_args={'detail_brz': 100, 'lines_brz': 450}) dft_diff = core.std.MakeDiff(decs, dft) plac_diff = core.std.MergeDiff(plac, dft_diff) deband = lvf.rfs(deband_wk, plac_diff, strong_debanding) return deband
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
def infos_bd_alt_alt(path, frame_start, frame_end) -> InfosBD: src = path + '.dgi' src_clip = lvf.src(src) src_cut = src_clip[frame_start:frame_end] return InfosBD(path, src, src_clip, frame_start, frame_end, src_cut, None, None, None, None, None, None, None)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut h = 720 w = get_w(h) edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500) out = edgesfix clip = depth(out, 32) denoise = hybrid_denoise(clip, 0.45, 1.5) out = denoise luma = get_y(out) line_mask = line_mask_func(luma) descale = core.descale.Debilinear(luma, w, h) upscale = vdf.nnedi3_upscale(descale, pscrn=1) antialias = single_rate_antialiasing(upscale, 13, alpha=0.2, beta=0.5, gamma=600, mdis=15) scaled = core.resize.Bicubic(antialias, src.width, src.height) rescale = core.std.MaskedMerge(luma, scaled, depth(line_mask, 32)) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) preden = core.knlm.KNLMeansCL(get_y(out), h=0.75, a=2, d=3, device_type='gpu', device_id=0) detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000) detail_light_mask = lvf.denoise.detail_mask(preden, 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([preden, detail_mask_grow, detail_mask], f'x {32<<8} < y z ?') custom_mask_a = lvf.src('rezeros2_01_4186-4400.png', detail_mask) custom_mask_a = core.std.Expr([custom_mask_a, detail_mask], 'x y +') deband_a = dbs.f3kpf(out, 17, 36, 42, thr=0.5, elast=2, thrc=0.2) deband_b = placebo.deband(out, 18, 5.5, 2, 0) deband = core.std.MaskedMerge(deband_a, deband_b, preden) deband = lvf.rfs(deband, deband_b, [(4920, 4961), (11027, 11055), (15377, 15596)]) deband = core.std.MaskedMerge(deband, out, detail_mask) deband = lvf.rfs(deband, core.std.MaskedMerge(deband_b, deband, custom_mask_a), [(4186, 4400)]) deband = core.neo_f3kdb.Deband(deband, preset='depth', grainy=24, grainc=24) out = deband ref = depth(denoise, 16) credit_mask = vdf.drm(ref, kernel='bilinear', mthr=65) credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask, 0), [(327, 6130), (34757, 39693), (41102, 41167)]) credit = lvf.rfs(credit, ref, [(8320, 8439), (41168, 41239)]) out = credit grain = adptvgrnMod(out, 0.3, 0.15, 1.25, luma_scaling=8, sharp=80, static=False, lo=19) out = grain return depth(out, 10)
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/05.png', src)[0]), [(2520, src.num_frames-1)]) out = cred return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut h = 720 w = get_w(h) edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500) out = edgesfix clip = depth(out, 32) denoise = hybrid_denoise(clip, 0.45, 1.5) out = denoise luma = get_y(out) line_mask = line_mask_func(luma) descale = core.descale.Debilinear(luma, w, h) upscale = vdf.nnedi3_upscale(descale, pscrn=1) antialias = single_rate_antialiasing(upscale, 13, alpha=0.4, beta=0.3, gamma=400, mdis=15).resize.Bilinear( src.width, src.height) rescale = core.std.MaskedMerge(luma, antialias, depth(line_mask, 32)) merged = vdf.merge_chroma(rescale, out) out = depth(merged, 16) preden = core.knlm.KNLMeansCL(get_y(out), h=0.75, a=2, d=3, device_type='gpu', device_id=0) detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000) detail_light_mask = lvf.denoise.detail_mask(preden, 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([preden, detail_mask_grow, detail_mask], f'x {32<<8} < y z ?') custom_mask_a = lvf.src('rezeros2_07_25374-25642.png', detail_mask) custom_mask_a = core.std.Expr([custom_mask_a, detail_mask], 'x y +') deband_a = dbs.f3kpf(out, 17, 36, 42, thr=0.5, elast=2, thrc=0.2) deband_b = placebo.deband(out, 18, 5.5, 2, 0) deband_d = core.neo_f3kdb.Deband(out, 20, 30, 30, 30, 0, 0, 4) deband_e = placebo.deband(out, 18, 8, 2, 0) deband = core.std.MaskedMerge(deband_a, deband_b, preden) deband = lvf.rfs(deband, deband_d, [(1457, 1677), (8414, 8684), (8788, 8915), (9348, 10179), (11325, 11459), (12647, 12857), (13025, 13574), (13874, 13987), (20809, 21076), (23936, 25063), (25219, 25373), (26231, 26530), (26668, 26800), (26818, 27048), (27174, 27454), (27503, 27943), (28492, 28622), (29948, 30563), (30965, 31498), (31624, 32005), (32107, 32325), (32451, 35407), (37171, 37955)]) deband = lvf.rfs(deband, deband_e, [(22116, 22173), (22454, 22459), (38028, 38035)]) deband = core.std.MaskedMerge(deband, out, detail_mask) deband = lvf.rfs(deband, core.std.MaskedMerge(deband_e, deband, custom_mask_a), [(25374, 25642), (25708, 25889)]) deband = core.neo_f3kdb.Deband(deband, preset='depth', grainy=24, grainc=24) out = deband ref, src, src_nced = [ depth(x, 16) for x in [denoise, src, JPBD_NCED.src_cut[221:]] ] credit_mask = vdf.drm(ref, kernel='bilinear', mthr=65) credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask, 0), [(113, 3315), (37171, src.num_frames - 1)]) credit = lvf.rfs(credit, ref, [(3316, 3435), (35408, 35485)]) out = credit src_c, src_nced = [ c.knlm.KNLMeansCL(a=7, h=35, d=0, device_type='gpu') for c in [src, src_nced] ] ending_mask = vdf.dcm(out, src_c[EDSTART:EDEND + 1], src_nced[:EDEND - EDSTART + 1], EDSTART, EDEND, 4, 4).std.Inflate() credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, ending_mask), [(EDSTART, EDEND)]) out = credit grain = adptvgrnMod(out, 0.3, 0.15, 1.25, luma_scaling=8, sharp=80, static=False, lo=19) out = grain return depth(out, 10)
#!/usr/bin/env python3 import acsuite import lvsfunc as lvf ac = acsuite.AC() path = r'BDMV/[BDMV]輪るピングドラム/[BDMV]輪るピングドラム 2/MAWARU PENGUINDRUM 2/BDMV/STREAM/00011.m2ts' src = lvf.src(path) if __name__ == "__main__": ac.eztrim(src, [(24, -24)], path[:-4] + "wav", "PenguindrumBD_NCED1_cut.wav")
import placebo import xvs from vsutil import depth, split, join import lvsfunc as lvf import vapoursynth as vs core = vs.core X264 = 'x264_tmod' NAME = Path(sys.argv[0]).stem OUTPUT = NAME + '.264' VIDEO_FILE = 'magia_op_2.mkv' CLIP_SRC = lvf.src(VIDEO_FILE, force_lsmas=True) # vdf.set_ffms2_log_level('warning') # AUDIO_SRC = Path(VIDEO_FILE).stem + '.eac3' X264_ARGS = dict(threads=12, ref=16, trellis=2, bframes=16, b_adapt=2, direct='auto', deblock='-1:-1', me='tesa', subme=10, psy_rd='1.0:0.00', merange=48, keyint=240,