Skip to content

Commit bd23734

Browse files
committed
vs: k7sfunc 更新 0.5.0
复制py12中缺失的标准库功能。 模块: - RIFE_STD RIFE_NV 改变支持的模型范围 示例脚本: MEMC_RIFE_NV 预设禁用参数 Ext_Proc
1 parent 8947a18 commit bd23734

File tree

3 files changed

+140
-20
lines changed

3 files changed

+140
-20
lines changed

k7sfunc.py

Lines changed: 137 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
### 文档: https://github.com/hooke007/MPV_lazy/wiki/3_K7sfunc
33
##################################################
44

5-
__version__ = "0.4.8"
5+
__version__ = "0.5.0"
66

77
__all__ = [
88
"FMT_CHANGE", "FMT_CTRL", "FPS_CHANGE", "FPS_CTRL",
@@ -12,17 +12,133 @@
1212
"COLOR_P3W_FIX", "CSC_RB", "DEBAND_STD", "DEINT_LQ", "DEINT_STD", "DEINT_EX", "DPIR_DBLK_NV", "EDI_AA_STD", "EDI_AA_NV", "IVTC_STD", "STAB_STD", "STAB_HQ", "UAI_DML", "UAI_NV_TRT", "UVR_MAD",
1313
]
1414

15-
from distutils.version import LooseVersion
16-
import fractions
17-
import math
18-
import os
19-
import typing
20-
import vapoursynth as vs
15+
##################################################
16+
## https://github.com/python/cpython/blob/v3.11.8/Lib/distutils/version.py
17+
##################################################
18+
19+
import re
20+
21+
class Version:
22+
def __init__ (self, vstring=None):
23+
if vstring:
24+
self.parse(vstring)
25+
def __repr__ (self):
26+
return "%s ('%s')" % (self.__class__.__name__, str(self))
27+
def __eq__(self, other):
28+
c = self._cmp(other)
29+
if c is NotImplemented:
30+
return c
31+
return c == 0
32+
def __lt__(self, other):
33+
c = self._cmp(other)
34+
if c is NotImplemented:
35+
return c
36+
return c < 0
37+
def __le__(self, other):
38+
c = self._cmp(other)
39+
if c is NotImplemented:
40+
return c
41+
return c <= 0
42+
def __gt__(self, other):
43+
c = self._cmp(other)
44+
if c is NotImplemented:
45+
return c
46+
return c > 0
47+
def __ge__(self, other):
48+
c = self._cmp(other)
49+
if c is NotImplemented:
50+
return c
51+
return c >= 0
52+
53+
class StrictVersion (Version):
54+
version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
55+
re.VERBOSE | re.ASCII)
56+
def parse (self, vstring):
57+
match = self.version_re.match(vstring)
58+
if not match:
59+
raise ValueError("invalid version number '%s'" % vstring)
60+
(major, minor, patch, prerelease, prerelease_num) = \
61+
match.group(1, 2, 4, 5, 6)
62+
if patch:
63+
self.version = tuple(map(int, [major, minor, patch]))
64+
else:
65+
self.version = tuple(map(int, [major, minor])) + (0,)
66+
if prerelease:
67+
self.prerelease = (prerelease[0], int(prerelease_num))
68+
else:
69+
self.prerelease = None
70+
def __str__ (self):
71+
if self.version[2] == 0:
72+
vstring = '.'.join(map(str, self.version[0:2]))
73+
else:
74+
vstring = '.'.join(map(str, self.version))
75+
if self.prerelease:
76+
vstring = vstring + self.prerelease[0] + str(self.prerelease[1])
77+
return vstring
78+
def _cmp (self, other):
79+
if isinstance(other, str):
80+
other = StrictVersion(other)
81+
elif not isinstance(other, StrictVersion):
82+
return NotImplemented
83+
if self.version != other.version:
84+
if self.version < other.version:
85+
return -1
86+
else:
87+
return 1
88+
if (not self.prerelease and not other.prerelease):
89+
return 0
90+
elif (self.prerelease and not other.prerelease):
91+
return -1
92+
elif (not self.prerelease and other.prerelease):
93+
return 1
94+
elif (self.prerelease and other.prerelease):
95+
if self.prerelease == other.prerelease:
96+
return 0
97+
elif self.prerelease < other.prerelease:
98+
return -1
99+
else:
100+
return 1
101+
else:
102+
assert False, "never get here"
103+
104+
class LooseVersion (Version):
105+
component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE)
106+
def __init__ (self, vstring=None):
107+
if vstring:
108+
self.parse(vstring)
109+
def parse (self, vstring):
110+
self.vstring = vstring
111+
components = [x for x in self.component_re.split(vstring)
112+
if x and x != '.']
113+
for i, obj in enumerate(components):
114+
try:
115+
components[i] = int(obj)
116+
except ValueError:
117+
pass
118+
self.version = components
119+
def __str__ (self):
120+
return self.vstring
121+
def __repr__ (self):
122+
return "LooseVersion ('%s')" % str(self)
123+
def _cmp (self, other):
124+
if isinstance(other, str):
125+
other = LooseVersion(other)
126+
elif not isinstance(other, LooseVersion):
127+
return NotImplemented
128+
if self.version == other.version:
129+
return 0
130+
if self.version < other.version:
131+
return -1
132+
if self.version > other.version:
133+
return 1
21134

22135
##################################################
23136
## 初始设置
24137
##################################################
25138

139+
import os
140+
import vapoursynth as vs
141+
26142
vs_thd_init = os.cpu_count()
27143
if vs_thd_init > 8 and vs_thd_init <= 16 :
28144
vs_thd_dft = 8
@@ -46,6 +162,10 @@
46162
qtgmc = None
47163
vsmlrt = None
48164

165+
import typing
166+
import math
167+
import fractions
168+
49169
##################################################
50170
## 格式转换 # TODO
51171
##################################################
@@ -1193,7 +1313,7 @@ def MVT_MQ(
11931313

11941314
def RIFE_STD(
11951315
input : vs.VideoNode,
1196-
model : typing.Literal[23, 41, 43, 45] = 23,
1316+
model : typing.Literal[23, 47, 49] = 23,
11971317
t_tta : bool = False,
11981318
fps_num : int = 2,
11991319
fps_den : int = 1,
@@ -1208,7 +1328,7 @@ def RIFE_STD(
12081328
func_name = "RIFE_STD"
12091329
if not isinstance(input, vs.VideoNode) :
12101330
raise vs.Error(f"模块 {func_name} 的子参数 input 的值无效")
1211-
if model not in [23, 41, 43, 45] :
1331+
if model not in [23, 47, 49] :
12121332
raise vs.Error(f"模块 {func_name} 的子参数 model 的值无效")
12131333
if not isinstance(t_tta, bool) :
12141334
raise vs.Error(f"模块 {func_name} 的子参数 t_tta 的值无效")
@@ -1267,7 +1387,7 @@ def RIFE_STD(
12671387
def RIFE_NV(
12681388
input : vs.VideoNode,
12691389
lt_d2k : bool = False,
1270-
model : typing.Literal[46, 4131, 414, 4141] = 46,
1390+
model : typing.Literal[46, 415, 4151] = 46,
12711391
ext_proc : bool = True,
12721392
t_tta : bool = False,
12731393
fps_in : float = 23.976,
@@ -1286,7 +1406,7 @@ def RIFE_NV(
12861406
raise vs.Error(f"模块 {func_name} 的子参数 input 的值无效")
12871407
if not isinstance(lt_d2k, bool) :
12881408
raise vs.Error(f"模块 {func_name} 的子参数 lt_d2k 的值无效")
1289-
if model not in [46, 4131, 414, 4141] :
1409+
if model not in [46, 415, 4151] :
12901410
raise vs.Error(f"模块 {func_name} 的子参数 model 的值无效")
12911411
if not isinstance(ext_proc, bool) :
12921412
raise vs.Error(f"模块 {func_name} 的子参数 ext_proc 的值无效")
@@ -1326,9 +1446,9 @@ def RIFE_NV(
13261446
plg_dir = os.path.dirname(core.trt.Version()["path"]).decode()
13271447
mdl_pname = "rife/" if ext_proc else "rife_v2/"
13281448
if t_tta :
1329-
mdl_fname = ["rife_v4.6_ensemble", "rife_v4.13_lite_ensemble", "rife_v4.14_ensemble", "rife_v4.14_lite_ensemble"][[46, 4131, 414, 4141].index(model)]
1449+
mdl_fname = ["rife_v4.6_ensemble", "rife_v4.15_ensemble", "rife_v4.15_lite_ensemble"][[46, 415, 4151].index(model)]
13301450
else :
1331-
mdl_fname = ["rife_v4.6", "rife_v4.13_lite", "rife_v4.14", "rife_v4.14_lite"][[46, 4131, 414, 4141].index(model)]
1451+
mdl_fname = ["rife_v4.6", "rife_v4.15", "rife_v4.15_lite"][[46, 415, 4151].index(model)]
13321452
mdl_pth = plg_dir + "/models/" + mdl_pname + mdl_fname + ".onnx"
13331453
if not os.path.exists(mdl_pth) :
13341454
raise vs.Error(f"模块 {func_name} 所请求的模型缺失")
@@ -1339,8 +1459,8 @@ def RIFE_NV(
13391459
import vsmlrt
13401460
except ImportError :
13411461
raise ImportError(f"模块 {func_name} 依赖错误:缺失脚本 vsmlrt")
1342-
if LooseVersion(vsmlrt.__version__) < LooseVersion("3.18.22") :
1343-
raise ImportError(f"模块 {func_name} 依赖错误:缺失脚本 vsmlrt 的版本号过低,至少 3.18.22")
1462+
if LooseVersion(vsmlrt.__version__) < LooseVersion("3.20.4") :
1463+
raise ImportError(f"模块 {func_name} 依赖错误:缺失脚本 vsmlrt 的版本号过低,至少 3.20.4")
13441464

13451465
core.num_threads = vs_t
13461466
w_in, h_in = input.width, input.height
@@ -1359,9 +1479,9 @@ def RIFE_NV(
13591479
scale_model = 1
13601480
if lt_d2k and st_eng and (size_in > 2048 * 1088) :
13611481
scale_model = 0.5
1362-
if not ext_proc : # https://github.com/AmusementClub/vs-mlrt/blob/57cfe194fa8c21d221bdfaffebe4fee1af43d40c/scripts/vsmlrt.py#L903
1482+
if not ext_proc : # https://github.com/AmusementClub/vs-mlrt/blob/27d417572ba4359c4eb0f45da691f75275842d98/scripts/vsmlrt.py#L945
13631483
scale_model = 1
1364-
if model >= 47 : # https://github.com/AmusementClub/vs-mlrt/blob/57cfe194fa8c21d221bdfaffebe4fee1af43d40c/scripts/vsmlrt.py#L895
1484+
if model >= 47 : # https://github.com/AmusementClub/vs-mlrt/blob/27d417572ba4359c4eb0f45da691f75275842d98/scripts/vsmlrt.py#L937
13651485
scale_model = 1
13661486

13671487
tile_size = 32 / scale_model

portable_config/vs/MEMC_RIFE_NV.vpy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ clip = video_in
1414
H_Pre = 1440
1515
Lt_D2k = False
1616
Model = 46
17-
Ext_Proc = True
17+
Ext_Proc = False
1818
T_Tta = False
1919
Fps_Num = 2
2020
Fps_Den = 1
@@ -26,7 +26,7 @@ Ws_Size = 0
2626
Lk_Fmt = False
2727
## 整数,预降低处理源高度(填你的显示器高度)
2828
## <True|False> 是否对超过DCI2K分辨率的源进行补帧
29-
## <46|4131|414|4141> 使用的模型
29+
## <46|415|4151> 使用的模型
3030
## <True|False> 是否使用外部的填充裁切处理
3131
## <True|False> 是否使用ensemble版模型
3232
## 整数,Fps_Num/Fps_Den 的值即帧率倍数

portable_config/vs/MEMC_RIFE_STD.vpy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Gpu = 0
2323
Gpu_T = 2
2424
Lk_Fmt = False
2525
## 整数,预降低处理源高度(填你的显示器高度)
26-
## <23|41|43|45> 使用的模型
26+
## <23|47|49> 使用的模型
2727
## <True|False> 是否使用ensemble版模型
2828
## 整数,Fps_Num/Fps_Den 的值即帧率倍数
2929
## 整数

0 commit comments

Comments
 (0)