From 7f7611d3d3321cd6381160694cd9559696dcce36 Mon Sep 17 00:00:00 2001 From: louis Date: Tue, 27 Apr 2021 15:11:02 -0400 Subject: [PATCH] vivy: tv: 05 --- Vivy/05/05.vpy | 76 +++++++++++++++++++++++++++++++ Vivy/vivy_common/final-settings | 2 +- yt_common/yt_common/automation.py | 6 ++- 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 Vivy/05/05.vpy diff --git a/Vivy/05/05.vpy b/Vivy/05/05.vpy new file mode 100644 index 0000000..6ccdbe0 --- /dev/null +++ b/Vivy/05/05.vpy @@ -0,0 +1,76 @@ +import vapoursynth as vs + +from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, + finalize, fsrcnnx_rescale, letterbox_edgefix) + +from yt_common.automation import SelfRunner +from yt_common.source import waka_replace + +from lvsfunc.types import Range +from lvsfunc.dehardsub import HardsubLineFade, HardsubSign, HardsubSignFade, HardsubMask, bounded_dehardsub + +from typing import List + +import os + +core = vs.core + + +EPNUM: int = int(os.path.basename(os.path.splitext(__file__)[0])) +CONFIG: VivyConfig = VivyConfig(EPNUM) +SOURCE: VivySource = VivySource(CONFIG) + +WAKA_REPLACE: List[List[Range]] = [ + [(31528, 32331)], + [], +] +SIGNS_RU: List[HardsubMask] = [ + HardsubLineFade([ + (5632, 5679), + (10588, 10671), + (24934, 25005), + ]), + HardsubSignFade([ + (4016, 4135), + (19061, 19186), + ]), + HardsubSignFade([ + (33950, 34045), + ], expand=10, thresh=0.03), + HardsubSignFade([ + (18989, 19060), + ], expand=15, thresh=0.02), + HardsubSign([ + (18923, 18988), + ]), +] +NOSCALE: List[Range] = [] +NOAA: List[Range] = [] +LETTERBOX: List[Range] = [(0, 1153)] + + +def filter_basic() -> vs.VideoNode: + wakas, ref = SOURCE.source() + waka = wakas[0] + waka, wakas = waka_replace(waka, wakas[1:], WAKA_REPLACE) + src = bounded_dehardsub(waka, ref, SIGNS_RU, wakas) + src.set_output(1) + return src + + +def filter() -> vs.VideoNode: + src = filter_basic() + rescale = fsrcnnx_rescale(src, NOSCALE) + den = denoise(rescale) + deb = deband(den) + aa = antialias(deb, NOAA) + edgefix = letterbox_edgefix(aa, LETTERBOX) + final = finalize(edgefix) + final.set_output() + return final + + +if __name__ == "__main__": + SelfRunner(CONFIG, filter, filter_basic) +else: + filter() diff --git a/Vivy/vivy_common/final-settings b/Vivy/vivy_common/final-settings index b05f935..957b876 100644 --- a/Vivy/vivy_common/final-settings +++ b/Vivy/vivy_common/final-settings @@ -1 +1 @@ -x265 --input - --y4m --input-depth 10 --output-depth 10 --input-csp i420 --profile main10 --colormatrix bt709 --colorprim bt709 --transfer bt709 --preset slower --rc-lookahead 72 --keyint 360 --min-keyint 23 --subme 5 --qcomp 0.7 --crf 15 --aq-mode 3 --aq-strength 0.9 --bframes 16 --psy-rd 2.0 --psy-rdoq 1.8 --rdoq-level 1 --deblock -2:-2 --no-sao --no-open-gop --no-wpp --frames {frames:d} --output {filename:s}.h265 +x265 --input - --y4m --input-depth 10 --output-depth 10 --input-csp i420 --profile main10 --colormatrix bt709 --colorprim bt709 --transfer bt709 --preset slower --rc-lookahead 72 --keyint 360 --min-keyint 23 --subme 5 --qcomp 0.7 --crf 15 --aq-mode 3 --aq-strength 0.9 --bframes 16 --psy-rd 2.0 --psy-rdoq 1.8 --rdoq-level 1 --deblock -2:-2 --no-sao --no-open-gop --no-strong-intra-smoothing --frames {frames:d} --output {filename:s}.h265 diff --git a/yt_common/yt_common/automation.py b/yt_common/yt_common/automation.py index 48ab050..748da57 100644 --- a/yt_common/yt_common/automation.py +++ b/yt_common/yt_common/automation.py @@ -323,12 +323,14 @@ class SelfRunner(): return subprocess.call(mkvtoolnix_args) -def gencomp(num: int = 10, path: str = "comp", matrix: str = "709", **clips: vs.VideoNode) -> None: +def gencomp(num: int = 10, path: str = "comp", matrix: str = "709", + firstnum: int = 1, **clips: vs.VideoNode) -> None: lens = set(c.num_frames for c in clips.values()) if len(lens) != 1: raise ValueError("gencomp: 'Clips must be equal length!'") frames = sorted(random.sample(range(lens.pop()), num)) + print("Sample frames: " + str(frames)) if os.path.exists(path): shutil.rmtree(path) @@ -341,5 +343,5 @@ def gencomp(num: int = 10, path: str = "comp", matrix: str = "709", **clips: vs. for f in frames[1:]: splice += clip[f] splice = splice.resize.Bicubic(format=vs.RGB24, matrix_in_s=matrix) \ - .imwri.Write("PNG", os.path.join(path, f"{name}%0{len(str(num))}d.png")) + .imwri.Write("PNG", os.path.join(path, f"{name}%0{len(str(num))}d.png"), firstnum=firstnum) [splice.get_frame(f) for f in range(splice.num_frames)]