def _getnative(): args = parser.parse_args() if args.use: source_filter = get_attr(core, args.use) if not source_filter: raise GetnativeException(f"{args.use} is not available.") print(f"Using {args.use} as source filter") else: source_filter = get_source_filter(core, imwri, args) src = source_filter(args.input_file) mode = [None] # default if args.mode == "bilinear": mode = [common_scaler["bilinear"][0]] elif args.mode == "bicubic": mode = [scaler for scaler in common_scaler["bicubic"]] elif args.mode == "bl-bc": mode = [scaler for scaler in common_scaler["bicubic"]] mode.append(common_scaler["bilinear"][0]) elif args.mode == "all": mode = [s for scaler in common_scaler.values() for s in scaler] for i, scaler in enumerate(mode): if scaler is not None and scaler.plugin is None: print(f"Warning: No correct descale version found for {scaler}, continuing with next scaler when available.") continue getnative(args, src, scaler, first_time=True if i == 0 else False)
def check_input(self): if self.descaler is None and self.kernel == "spline64": raise GetnativeException(f'descale: spline64 support is missing, update descale (>r3).') elif self.descaler is None: raise GetnativeException(f'descale: {self.kernel} is not a supported kernel.')
def getnative(args: Union[List, argparse.Namespace], src: vapoursynth.VideoNode, scaler: Union[_DefineScaler, None], first_time: bool = True) -> Tuple[List, pyplot.plot]: """ Process your VideoNode with the getnative algorithm and return the result and a plot object :param args: List of all arguments for argparse or Namespace object from argparse :param src: VideoNode from vapoursynth :param scaler: DefineScaler object or None :param first_time: prevents posting warnings multiple times :return: best resolutions list and plot matplotlib.pyplot """ if type(args) == list: args = parser.parse_args(args) output_dir = Path(args.dir).resolve() if not os.access(output_dir, os.W_OK): raise PermissionError(f"Missing write permissions: {output_dir}") output_dir = output_dir.joinpath("results") if (args.img or args.mask_out) and imwri is None: raise GetnativeException("imwri not found.") if scaler is None: scaler = _DefineScaler(args.kernel, b=args.b, c=args.c, taps=args.taps) else: scaler = scaler if scaler.plugin is None: if "toggaf.asi.xe" in core.get_plugins(): print("Error: descale_getnative support ended, pls use https://github.com/Irrational-Encoding-Wizardry/vapoursynth-descale") raise GetnativeException('No descale found!') if args.steps != 1 and first_time: print( "Warning for -steps/--stepping: " "If you are not completely sure what this parameter does, use the default step size.\n" ) if args.frame is None: args.frame = src.num_frames // 3 elif args.frame < 0: args.frame = src.num_frames // -args.frame elif args.frame > src.num_frames - 1: raise GetnativeException(f"Last frame is {src.num_frames - 1}, but you want {args.frame}") if args.ar == 0: args.ar = src.width / src.height if args.min_h >= src.height: raise GetnativeException(f"Input image {src.height} is smaller min_h {args.min_h}") elif args.min_h >= args.max_h: raise GetnativeException(f"min_h {args.min_h} > max_h {args.max_h}? Not processable") elif args.max_h > src.height: print(f"The image height is {src.height}, going higher is stupid! New max_h {src.height}") args.max_h = src.height getn = GetNative(src, scaler, args.ar, args.min_h, args.max_h, args.frame, args.mask_out, args.plot_scaling, args.plot_format, args.show_plot, args.no_save, args.steps, output_dir) try: loop = asyncio.get_event_loop() best_value, plot, resolutions = loop.run_until_complete(getn.run()) except ValueError as err: raise GetnativeException(f"Error in getnative: {err}") gc.collect() print( f"\n{scaler} AR: {args.ar:.2f} Steps: {args.steps}\n" f"{best_value}\n" ) return resolutions, plot
def check_input(self): if self.descaler is None: raise GetnativeException( f'descale: {self.kernel} is not a supported kernel.')