Skip to content

Commit 5de07e5

Browse files
committed
- Update to VS 71+
- Switch all prints to stderr
1 parent 720c395 commit 5de07e5

4 files changed

Lines changed: 20 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To run this script you will need:
2828

2929
* Python 3.6
3030
* [matplotlib](http://matplotlib.org/users/installing.html)
31-
* [Vapoursynth](http://www.vapoursynth.com) R45+
31+
* [Vapoursynth](http://www.vapoursynth.com) R71+
3232
* [descale](https://github.com/Irrational-Encoding-Wizardry/vapoursynth-descale)
3333
* [ffms2](https://github.com/FFMS/ffms2) **or** [lsmash](https://github.com/VFR-maniac/L-SMASH-Works) **or** [imwri](https://forum.doom9.org/showthread.php?t=170981)
3434
\*imwri: ImageMagick7 is required for macOS and Linux

getnative/app.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gc
22
import os
3+
import sys
34
import time
45
import asyncio
56
import argparse
@@ -23,8 +24,6 @@
2324
"""
2425

2526
core = vapoursynth.core
26-
if core.version_number() < 55:
27-
core.add_cache = False
2827
imwri = getattr(core, "imwri", getattr(core, "imwrif", None))
2928
_modes = ["bilinear", "bicubic", "bl-bc", "all"]
3029

@@ -111,8 +110,7 @@ def __repr__(self):
111110

112111

113112
class GetNative:
114-
def __init__(self, src, scaler, ar, min_h, max_h, frame, mask_out, plot_scaling, plot_format, show_plot, no_save,
115-
steps, output_dir):
113+
def __init__(self, src, scaler, ar, min_h, max_h, frame, mask_out, plot_scaling, plot_format, show_plot, no_save, steps, output_dir):
116114
self.plot_format = plot_format
117115
self.plot_scaling = plot_scaling
118116
self.src = src
@@ -136,10 +134,9 @@ async def run(self):
136134
matrix_s = '709' if src.format.color_family == vapoursynth.RGB else None
137135
src_luma32 = core.resize.Point(src, format=vapoursynth.YUV444PS, matrix_s=matrix_s)
138136
src_luma32 = core.std.ShufflePlanes(src_luma32, 0, vapoursynth.GRAY)
139-
src_luma32 = core.std.Cache(src_luma32)
140137

141138
# descale each individual frame
142-
clip_list = [self.scaler.descaler(src_luma32, self.getw(h, not src.width&1), h) # allow odd resolutions for odd input
139+
clip_list = [self.scaler.descaler(src_luma32, self.getw(h, not src.width & 1), h) # allow odd resolutions for odd input
143140
for h in range(self.min_h, self.max_h + 1, self.steps)]
144141
full_clip = core.std.Splice(clip_list, mismatch=True)
145142
full_clip = self.scaler.upscaler(full_clip, src.width, src.height)
@@ -148,14 +145,13 @@ async def run(self):
148145
expr_full = core.std.Expr([src_luma32 * full_clip.num_frames, full_clip], 'x y - abs dup 0.015 > swap 0 ?')
149146
full_clip = core.std.CropRel(expr_full, 5, 5, 5, 5)
150147
full_clip = core.std.PlaneStats(full_clip)
151-
full_clip = core.std.Cache(full_clip)
152148

153149
tasks_pending = set()
154150
futures = {}
155151
vals = []
156152
full_clip_len = len(full_clip)
157153
for frame_index in range(len(full_clip)):
158-
print(f"\r{frame_index}/{full_clip_len-1}", end="")
154+
print(f"\r{frame_index}/{full_clip_len-1}", end="", file=sys.stderr)
159155
fut = asyncio.ensure_future(asyncio.wrap_future(full_clip.get_frame_async(frame_index)))
160156
tasks_pending.add(fut)
161157
futures[fut] = frame_index
@@ -167,7 +163,7 @@ async def run(self):
167163
vals += [(futures.pop(task), task.result().props.PlaneStatsAverage) for task in tasks_done]
168164
vals = [v for _, v in sorted(vals)]
169165
ratios, vals, best_value = self.analyze_results(vals)
170-
print("\n") # move the cursor, so that you not start at the end of the progress bar
166+
print("\n", file=sys.stderr) # move the cursor, so that you not start at the end of the progress bar
171167

172168
self.txt_output += 'Raw data:\nResolution\t | Relative Error\t | Relative difference from last\n'
173169
self.txt_output += '\n'.join([
@@ -180,7 +176,7 @@ async def run(self):
180176
if not os.path.isdir(self.output_dir):
181177
os.mkdir(self.output_dir)
182178

183-
print(f"Output Path: {self.output_dir}")
179+
print(f"Output Path: {self.output_dir}", file=sys.stderr)
184180
for fmt in self.plot_format.replace(" ", "").split(','):
185181
fig.savefig(f'{self.output_dir}/{self.filename}.{fmt}')
186182

@@ -314,7 +310,8 @@ async def getnative(args: Union[List, argparse.Namespace], src: vapoursynth.Vide
314310
if args.steps != 1 and first_time:
315311
print(
316312
"Warning for -steps/--stepping: "
317-
"If you are not completely sure what this parameter does, use the default step size.\n"
313+
"If you are not completely sure what this parameter does, use the default step size.\n",
314+
file=sys.stderr
318315
)
319316

320317
if args.frame is None:
@@ -332,7 +329,7 @@ async def getnative(args: Union[List, argparse.Namespace], src: vapoursynth.Vide
332329
elif args.min_h >= args.max_h:
333330
raise GetnativeException(f"min_h {args.min_h} > max_h {args.max_h}? Not processable")
334331
elif args.max_h > src.height:
335-
print(f"The image height is {src.height}, going higher is stupid! New max_h {src.height}")
332+
print(f"The image height is {src.height}, going higher is stupid! New max_h {src.height}", file=sys.stderr)
336333
args.max_h = src.height
337334

338335
getn = GetNative(src, scaler, args.ar, args.min_h, args.max_h, args.frame, args.mask_out, args.plot_scaling,
@@ -345,7 +342,8 @@ async def getnative(args: Union[List, argparse.Namespace], src: vapoursynth.Vide
345342
gc.collect()
346343
print(
347344
f"\n{scaler} AR: {args.ar:.2f} Steps: {args.steps}\n"
348-
f"{best_value}\n"
345+
f"{best_value}\n",
346+
file=sys.stderr
349347
)
350348

351349
return best_value, plot, getn
@@ -358,7 +356,7 @@ def _getnative():
358356
source_filter = get_attr(core, args.use)
359357
if not source_filter:
360358
raise GetnativeException(f"{args.use} is not available.")
361-
print(f"Using {args.use} as source filter")
359+
print(f"Using {args.use} as source filter", file=sys.stderr)
362360
else:
363361
source_filter = get_source_filter(core, imwri, args)
364362

@@ -378,11 +376,9 @@ def _getnative():
378376
loop = asyncio.get_event_loop()
379377
for i, scaler in enumerate(mode):
380378
if scaler is not None and scaler.plugin is None:
381-
print(f"Warning: No correct descale version found for {scaler}, continuing with next scaler when available.")
379+
print(f"Warning: No correct descale version found for {scaler}, continuing with next scaler when available.", file=sys.stderr)
382380
continue
383-
loop.run_until_complete(
384-
getnative(args, src, scaler, first_time=True if i == 0 else False)
385-
)
381+
loop.run_until_complete(getnative(args, src, scaler, first_time=True if i == 0 else False))
386382

387383

388384
parser = argparse.ArgumentParser(description='Find the native resolution(s) of upscaled material (mostly anime)')
@@ -406,6 +402,7 @@ def main():
406402
parser.add_argument(dest='input_file', type=str, help='Absolute or relative path to the input file')
407403
parser.add_argument('--use', '-u', default=None, help='Use specified source filter e.g. (lsmas.LWLibavSource)')
408404
parser.add_argument('--mode', '-m', dest='mode', type=str, choices=_modes, default=None, help='Choose a predefined mode ["bilinear", "bicubic", "bl-bc", "all"]')
409-
starttime = time.time()
405+
406+
start = time.time()
410407
_getnative()
411-
print(f'done in {time.time() - starttime:.2f}s')
408+
print(f'done in {time.time() - start:.2f}s', file=sys.stderr)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
matplotlib>=2.0.0
2-
VapourSynth>=55
2+
VapourSynth>=71

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name="getnative",
13-
version='3.2.1',
13+
version='3.3.0',
1414
description='Find the native resolution(s) of upscaled material (mostly anime)',
1515
long_description=long_description,
1616
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)