-
Notifications
You must be signed in to change notification settings - Fork 0
/
RpcTemplate.vpy
46 lines (35 loc) · 1.49 KB
/
RpcTemplate.vpy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import vapoursynth as vs
import types
import sys
from vapoursynth import core
from importlib.machinery import SourceFileLoader
# Load the source clip by loading another vs script.
sourceScript = r"OKE:SOURCE_SCRIPT"
videoFile = r"OKE:VIDEO_FILE"
loader = SourceFileLoader('source', sourceScript)
mod = types.ModuleType(loader.name)
OKE:VSPIPE_ARGS
loader.exec_module(mod)
src = vs.get_output(index = 1)
# Load the ripped file.
rip = core.lsmas.LWLibavSource(videoFile)
assert rip.format.color_family in [vs.YUV, vs.GRAY], "only support YUV or Gray input"
def force8bit(clip):
if clip.format.bits_per_sample == 8:
return clip
return clip.resize.Spline64(format=clip.format.replace(bits_per_sample=8).id, dither_type='none')
src = force8bit(src)
rip = force8bit(rip)
# Get the clips in same dimention.
if src.width != rip.width or src.height != rip.height:
src = src.resize.Bicubic(rip.width, rip.height)
src_planes = [ src.std.ShufflePlanes(i, vs.GRAY) for i in range(src.format.num_planes) ]
rip_planes = [ rip.std.ShufflePlanes(i, vs.GRAY) for i in range(rip.format.num_planes) ]
# runtime function to print psnr value to console.
def callback(n, f):
print("RPCOUT:", n, ' '.join([ '%f' % p.props.PlanePSNR for p in f ]), flush=True, file=sys.stderr)
return rip
# Compare. Run it using 'vspipe "00009.m2ts_rpc.vpy" NUL'.
cmp_planes = [ core.complane.PSNR(a, b) for (a, b) in zip(rip_planes, src_planes) ]
cmp = core.std.FrameEval(rip, callback, prop_src=cmp_planes)
cmp.set_output()