Compare commits
2 Commits
eefc597138
...
e2a47f8716
Author | SHA1 | Date | |
---|---|---|---|
e2a47f8716 | |||
4f5a6d9044 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@ ffmpeg2pass*.log
|
||||
**/.vspreview/
|
||||
**/results/
|
||||
**/__pycache__/
|
||||
**/*.egg-info/
|
||||
|
@ -1,5 +1,8 @@
|
||||
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
|
||||
|
||||
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubSign, HardsubMask, bounded_dehardsub
|
||||
from typing import List
|
||||
|
||||
import os
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
|
||||
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402
|
||||
finalize, fsrcnnx_rescale, letterbox_edgefix)
|
||||
|
||||
core = vs.core
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
import vapoursynth as vs
|
||||
|
||||
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, finalize,
|
||||
fsrcnnx_rescale)
|
||||
|
||||
from yt_common.automation import SelfRunner
|
||||
from yt_common.source import waka_replace
|
||||
|
||||
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubMask, HardsubSign, bounded_dehardsub
|
||||
from typing import List
|
||||
|
||||
import os
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
|
||||
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, finalize, # noqa: E402
|
||||
fsrcnnx_rescale)
|
||||
|
||||
core = vs.core
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
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
|
||||
|
||||
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubMask, HardsubLine, HardsubSign, bounded_deh
|
||||
from typing import List
|
||||
|
||||
import os
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
|
||||
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402
|
||||
finalize, fsrcnnx_rescale, letterbox_edgefix)
|
||||
|
||||
core = vs.core
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
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
|
||||
|
||||
@ -9,11 +12,6 @@ from lvsfunc.dehardsub import HardsubLine, HardsubSign, HardsubMask, bounded_deh
|
||||
from typing import List
|
||||
|
||||
import os
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
|
||||
from vivy_common import (VivyConfig, VivySource, antialias, deband, denoise, # noqa: E402
|
||||
finalize, fsrcnnx_rescale, letterbox_edgefix)
|
||||
|
||||
core = vs.core
|
||||
|
||||
|
25
Vivy/setup.py
Executable file
25
Vivy/setup.py
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import setuptools
|
||||
|
||||
name = "vivy_common"
|
||||
version = "0.0.0"
|
||||
release = "0.0.0"
|
||||
|
||||
setuptools.setup(
|
||||
name=name,
|
||||
version=release,
|
||||
author="louis",
|
||||
author_email="louis@poweris.moe",
|
||||
description="yametetomete vivy common module",
|
||||
packages=["vivy_common"],
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
],
|
||||
package_data={
|
||||
'vivy_common': ['py.typed', 'workraw-settings', 'final-settings', 'shaders/FSRCNNX_x2_56-16-4-1.glsl'],
|
||||
},
|
||||
python_requires='>=3.8',
|
||||
)
|
@ -49,7 +49,7 @@ def deband(clip: vs.VideoNode) -> vs.VideoNode:
|
||||
|
||||
|
||||
def antialias(clip: vs.VideoNode, noaa: Optional[List[Range]] = None) -> vs.VideoNode:
|
||||
clamp = antialiasing.sraa_clamp(clip, mask=antialiasing.aa_mask_strong(clip))
|
||||
clamp = antialiasing.sraa_clamp(clip, mask=antialiasing.mask_strong(clip))
|
||||
return lvf.misc.replace_ranges(clamp, clip, noaa) if noaa else clamp
|
||||
|
||||
|
||||
|
@ -2,34 +2,19 @@ import vapoursynth as vs
|
||||
|
||||
import vsutil
|
||||
|
||||
from kagefunc import kirsch
|
||||
from lvsfunc.aa import clamp_aa, upscaled_sraa
|
||||
from havsfunc import SMDegrain
|
||||
from lvsfunc.aa import nnedi3, clamp_aa, upscaled_sraa
|
||||
from lvsfunc.kernels import Bicubic
|
||||
from lvsfunc.misc import replace_ranges, scale_thresh
|
||||
from lvsfunc.types import Range
|
||||
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
from typing import Callable, List, Optional, Union
|
||||
|
||||
|
||||
core = vs.core
|
||||
|
||||
|
||||
def nnedi3(clip: vs.VideoNode, opencl: bool = False) -> vs.VideoNode:
|
||||
nnedi3_args: Dict[str, Any] = dict(field=0, dh=True, nsize=3, nns=3, qual=1)
|
||||
|
||||
y = vsutil.get_y(clip)
|
||||
|
||||
def _nnedi3(clip: vs.VideoNode) -> vs.VideoNode:
|
||||
return clip.nnedi3cl.NNEDI3CL(**nnedi3_args) if opencl \
|
||||
else clip.nnedi3.nnedi3(**nnedi3_args)
|
||||
|
||||
aa = _nnedi3(y.std.Transpose())
|
||||
aa = aa.resize.Spline36(height=clip.width, src_top=0.5).std.Transpose()
|
||||
aa = _nnedi3(aa)
|
||||
aa = aa.resize.Spline36(height=clip.height, src_top=0.5)
|
||||
return aa
|
||||
|
||||
|
||||
def aa_mask_weak(clip: vs.VideoNode) -> vs.VideoNode:
|
||||
def mask_weak(clip: vs.VideoNode) -> vs.VideoNode:
|
||||
# use bilateral to smear the noise as much as possible without destroying lines
|
||||
pre = vsutil.get_y(clip).bilateral.Bilateral(sigmaS=5, sigmaR=0.75)
|
||||
# frei-chen edge detection
|
||||
@ -39,20 +24,20 @@ def aa_mask_weak(clip: vs.VideoNode) -> vs.VideoNode:
|
||||
.std.Maximum().std.Convolution([1]*9)
|
||||
|
||||
|
||||
def aa_mask_strong(clip: vs.VideoNode) -> vs.VideoNode:
|
||||
mask: vs.VideoNode = kirsch(vsutil.get_y(clip)).std.Binarize(scale_thresh(0.25, clip)) \
|
||||
.std.Maximum().std.Convolution([1]*9)
|
||||
def mask_strong(clip: vs.VideoNode) -> vs.VideoNode:
|
||||
mask: vs.VideoNode = SMDegrain(vsutil.get_y(clip), tr=3, thSAD=500, RefineMotion=True, prefilter=4) \
|
||||
.std.Prewitt().std.Binarize(scale_thresh(0.25, clip)).std.Maximum().std.Convolution([1]*9)
|
||||
return mask
|
||||
|
||||
|
||||
def aa_mask(clip: vs.VideoNode, weak: Union[Range, List[Range], None] = None) -> vs.VideoNode:
|
||||
weak = weak or []
|
||||
return replace_ranges(aa_mask_strong(clip), aa_mask_weak(clip), weak)
|
||||
def combine_mask(clip: vs.VideoNode, weak: Union[Range, List[Range], None] = None) -> vs.VideoNode:
|
||||
return replace_ranges(mask_strong(clip), mask_weak(clip), weak or [])
|
||||
|
||||
|
||||
def sraa_clamp(clip: vs.VideoNode, mask: Optional[vs.VideoNode] = None,
|
||||
strength: float = 3, opencl: bool = False) -> vs.VideoNode:
|
||||
sraa = upscaled_sraa(clip, rfactor=1.3, opencl=opencl,
|
||||
downscaler=lambda c, w, h: c.resize.Bicubic(w, h, filter_param_a=0, filter_param_b=1/2))
|
||||
strength: float = 2, opencl: bool = False,
|
||||
postprocess: Optional[Callable[[vs.VideoNode], vs.VideoNode]] = None) -> vs.VideoNode:
|
||||
sraa = upscaled_sraa(clip, rfactor=1.3, opencl=opencl, downscaler=Bicubic(b=0, c=1/2).scale)
|
||||
sraa = postprocess(sraa) if postprocess else sraa
|
||||
clamp = clamp_aa(clip, nnedi3(clip, opencl=opencl), sraa, strength=strength)
|
||||
return core.std.MaskedMerge(clip, clamp, mask, planes=0) if mask else clamp
|
||||
|
@ -3,6 +3,8 @@ import vapoursynth as vs
|
||||
import acsuite
|
||||
import argparse
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
import string
|
||||
import subprocess
|
||||
|
||||
@ -217,9 +219,16 @@ class SelfRunner():
|
||||
parser.add_argument("-f", "--force", help="Overwrite existing intermediaries", action="store_true")
|
||||
parser.add_argument("-a", "--audio", type=str, help="Force audio file")
|
||||
parser.add_argument("-x", "--suffix", type=str, help="Change the suffix of the mux")
|
||||
parser.add_argument("-c", "--no-chapters", help="No chapters in premux", action="store_true")
|
||||
parser.add_argument("-c", "--comparison", help="Output a comparison between workraw and final",
|
||||
action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.comparison and workraw_filter:
|
||||
log.status("Generating comparison...")
|
||||
gencomp(10, "comp", src=workraw_filter(), final=final_filter())
|
||||
log.status("Comparison generated.")
|
||||
return
|
||||
|
||||
self.workraw = args.workraw if workraw_filter else False
|
||||
self.suffix = args.suffix if args.suffix is not None else "workraw" if self.workraw else "premux"
|
||||
|
||||
@ -263,7 +272,7 @@ class SelfRunner():
|
||||
try:
|
||||
log.status("--- MUXING FILE ---")
|
||||
if self._mux(f"{self.config.title.lower()}_{self.config.epnum:02d}_{self.suffix}.mkv",
|
||||
not args.no_chapters and start == 0 and end == self.clip.num_frames) != 0:
|
||||
start == 0 and end == self.clip.num_frames) != 0:
|
||||
raise Exception("mkvmerge failed")
|
||||
except Exception:
|
||||
log.error("--- MUXING FAILED ---")
|
||||
@ -300,3 +309,25 @@ class SelfRunner():
|
||||
|
||||
print("+ " + " ".join(mkvtoolnix_args))
|
||||
return subprocess.call(mkvtoolnix_args)
|
||||
|
||||
|
||||
def gencomp(num: int = 10, path: str = "comp", matrix: str = "709", **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 = random.sample(range(lens.pop()), num)
|
||||
|
||||
if os.path.exists(path):
|
||||
shutil.rmtree(path)
|
||||
|
||||
os.makedirs(path)
|
||||
|
||||
for name, clip in clips.items():
|
||||
log.status(f"Rendering clip {name}")
|
||||
splice = clip[frames[0]]
|
||||
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"))
|
||||
[splice.get_frame(f) for f in range(splice.num_frames)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user