diff --git a/Vivy/06/06.vpy b/Vivy/06/06.vpy new file mode 100644 index 0000000..3cd12d0 --- /dev/null +++ b/Vivy/06/06.vpy @@ -0,0 +1,139 @@ +import vapoursynth as vs + +from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, + finalize, fsrcnnx_rescale, letterbox_edgefix, regrain) + +from yt_common.automation import SelfRunner +from yt_common.source import waka_replace + +from lvsfunc.types import Range +from lvsfunc.dehardsub import HardsubLineFade, HardsubLine, HardsubSignFade, HardsubMask, bounded_dehardsub +from vsutil import Range as CRange + +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]] = [ + [], + [], +] +SIGNS_RU: List[HardsubMask] = [ + HardsubLine([ + (1878, 2034), + (2045, 2230), + (2342, 2493), + (2716, 2840), + (3102, 3220), + (3225, 3360), + (3366, 3483), + (3487, 3634), + (3673, 3716), + (3740, 3890), + (3899, 3943), + (3947, 4090), + (4094, 4206), + (4211, 4348), + (4359, 4468), + (4480, 4599), + (4605, 4709), + (4713, 4830), + (8722, 8825), + (8831, 9017), + (9036, 9087), + (18822, 18885), + (19935, 19992), + (21046, 21138), + (21801, 21867), + (25730, 25847), + (25851, 25994), + (25999, 26124), + (26128, 26243), + (26249, 26290), + (26314, 26358), + (26379, 26539), + (26544, 26596), + (26605, 26741), + (26747, 26865), + (26870, 27010), + (27016, 27143), + (27147, 27262), + (27268, 27380), + (27385, 27492), + (28681, 28802), + (28806, 28974), + (28978, 29067), + (29076, 29219), + (29223, 29371), + (29376, 29523), + (29527, 29652), + (29656, 29774), + (29779, 29891), + (29896, 30018), + ], ((300, 840), (1313, 185))), + HardsubLineFade([ + (30519, 30541), + (30541, 30589), + (30590, 30637), + (30638, 30685), + (30686, 30733), + (30734, 30781), + (30782, 30829), + (30830, 30901), + (30902, 30973), + (30974, 31045), + ], ((333, 50), (1361, 167))), + HardsubLineFade([ + (31046, 31117), + (31118, 31189), + ], ((9, 70), (1239, 149))), + HardsubSignFade([ + (4890, 5010), + (15951, 16054), + (16055, 16120), + (16121, 16202), + (29617, 29628), + (33949, 34045), + ]), +] +NOSCALE: List[Range] = [] +AA_NONE: List[Range] = [(33870, 33873)] + +LETTERBOX: List[Range] = [(0, 2150), (8791, 10693), (13427, 15153), (27878, 28006)] + + +def filter_basic() -> vs.VideoNode: + wakas, ref = SOURCE.source() + wakas = [w[:33669] + w.std.BlankClip(length=17) + w[33669:] for w in wakas] + ref = ref.resize.Point(range_in=CRange.FULL, range=CRange.LIMITED) if SOURCE.ref_is_funi else ref + 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=AA_NONE) + grain = regrain(aa) + edgefix = letterbox_edgefix(grain, 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/filter.py b/Vivy/vivy_common/filter.py index 8b3ed32..08fd861 100644 --- a/Vivy/vivy_common/filter.py +++ b/Vivy/vivy_common/filter.py @@ -43,7 +43,7 @@ def letterbox_edgefix(clip: vs.VideoNode, ranges: List[Range]) -> vs.VideoNode: return lvf.misc.replace_ranges(clip, edgefix, ranges) -def denoise(clip: vs.VideoNode, sigma: Union[float, List[float]] = 0.75) -> vs.VideoNode: +def denoise(clip: vs.VideoNode, sigma: Union[float, List[float]] = 1.5) -> vs.VideoNode: return bm3d(clip, sigma=sigma) @@ -51,11 +51,11 @@ def deband(clip: vs.VideoNode) -> vs.VideoNode: grad_mask, yrangebig = morpho_mask(clip.dfttest.DFTTest(sigma=14, sigma2=10, sbsize=1, sosize=0) .rgvs.RemoveGrain(3)) y = vsutil.get_y(clip) - mask = lvf.mask.detail_mask(clip) - deband_dumb: vs.VideoNode = vdf.dumb3kdb(clip) + mask = lvf.mask.detail_mask(clip, brz_b=0.03) + deband_dumb: vs.VideoNode = vdf.dumb3kdb(clip, radius=16, threshold=24) deband_weak: vs.VideoNode = core.std.MaskedMerge(vsutil.get_y(deband_dumb), y, mask) - deband_norm: vs.VideoNode = f3kbilateral(y, y=36) - deband_strong: vs.VideoNode = f3kbilateral(y, y=65) + deband_norm: vs.VideoNode = vsutil.get_y(vdf.dumb3kdb(clip, radius=16, threshold=30)) + deband_strong: vs.VideoNode = f3kbilateral(y, range=12, y=50) deband = core.std.MaskedMerge(deband_strong, deband_norm, grad_mask) deband = core.std.MaskedMerge(deband, deband_weak, yrangebig) deband = core.std.ShufflePlanes([deband, deband_dumb], planes=[0, 1, 2], colorfamily=vs.YUV) @@ -63,11 +63,13 @@ def deband(clip: vs.VideoNode) -> vs.VideoNode: def antialias(clip: vs.VideoNode, weak: Optional[List[Range]] = None, strong: Optional[List[Range]] = None, - noaa: Optional[List[Range]] = None) -> vs.VideoNode: + stronger: Optional[List[Range]] = None, noaa: Optional[List[Range]] = None) -> vs.VideoNode: mask = antialiasing.combine_mask(clip, weak or []) clamp = antialiasing.sraa_clamp(clip, mask=mask) sraa = core.std.MaskedMerge(clip, upscaled_sraa(clip, rfactor=2, downscaler=Bicubic(b=0, c=1/2).scale), mask) - return replace_ranges(replace_ranges(clamp, clip, noaa or []), sraa, strong or []) + sraa_13 = core.std.MaskedMerge(clip, upscaled_sraa(clip, rfactor=1.3, downscaler=Bicubic(b=0, c=1/2).scale), mask) + return replace_ranges(replace_ranges(replace_ranges(clamp, clip, noaa or []), sraa, strong or []), sraa_13, + stronger or []) def regrain(clip: vs.VideoNode) -> vs.VideoNode: diff --git a/yt_common/yt_common/source.py b/yt_common/yt_common/source.py index 05ff283..b0318b6 100644 --- a/yt_common/yt_common/source.py +++ b/yt_common/yt_common/source.py @@ -9,7 +9,7 @@ import glob import os from abc import ABC, abstractmethod -from typing import List, Tuple +from typing import Any, List, Tuple from .config import Config from .logging import log @@ -26,8 +26,6 @@ def waka_replace(src: vs.VideoNode, wakas: List[vs.VideoNode], ranges: List[List ) -> Tuple[vs.VideoNode, List[vs.VideoNode]]: if len(wakas) == 0: return src, wakas - if len(ranges) != len(wakas): - raise ValueError("waka_replace: 'Different number of range sets and wakas supplied'!") new_wakas = [] for waka, r in zip(wakas, ranges): tmp = src @@ -59,13 +57,23 @@ class DehardsubFileFinder(ABC): pass def source(self) -> Tuple[List[vs.VideoNode], vs.VideoNode]: - wakas = [vsutil.depth(core.ffms2.Source(self.config.format_filename(f)), 16) - for f in self.get_waka_filenames()] + wakas: List[vs.VideoNode] = [] + for f in [self.config.format_filename(f) for f in self.get_waka_filenames()]: + if not os.path.isfile(f): + log.warn("Missing a waka!") + continue + wakas.append(vsutil.depth(core.ffms2.Source(f), 16)) ref = vsutil.depth(self.get_ref(), 16) return wakas, ref class FunimationSource(DehardsubFileFinder): + ref_is_funi: bool + + def __init__(self, *args: Any, **kwargs: Any) -> None: + self.ref_is_funi = False + super().__init__(*args, **kwargs) + def get_amazon(self) -> vs.VideoNode: if not os.path.isfile(self.config.format_filename(AMAZON_FILENAME)): log.warn("Amazon not found, falling back to Funimation") @@ -92,4 +100,5 @@ class FunimationSource(DehardsubFileFinder): try: return self.get_amazon() except FileNotFoundError: + self.ref_is_funi = True return self.get_funi()