# start execution try: # start timer begin_time = time.time() # initialize upscaler object upscaler = Upscaler( # required parameters input_path=video2x_args.input, output_path=video2x_args.output, driver_settings=driver_settings, ffmpeg_settings=ffmpeg_settings, gifski_settings=gifski_settings, # optional parameters driver=video2x_args.driver, scale_ratio=video2x_args.ratio, scale_width=video2x_args.width, scale_height=video2x_args.height, processes=video2x_args.processes, video2x_cache_directory=video2x_cache_directory, extracted_frame_format=extracted_frame_format, output_file_name_format_string=output_file_name_format_string, image_output_extension=image_output_extension, video_output_extension=video_output_extension, preserve_frames=preserve_frames, ) # run upscaler upscaler.run() Avalon.info( _("Program completed, taking {} seconds").format(
# overwrite driver_settings with driver_args if driver_args is not None: driver_args_dict = vars(driver_args) for key in driver_args_dict: if driver_args_dict[key] is not None: driver_settings[key] = driver_args_dict[key] # start execution try: # start timer begin_time = time.time() # initialize upscaler object upscaler = Upscaler(input_path=video2x_args.input, output_path=video2x_args.output, driver_settings=driver_settings, ffmpeg_settings=ffmpeg_settings, gifski_settings=gifski_settings) # set upscaler optional options upscaler.driver = video2x_args.driver upscaler.scale_ratio = video2x_args.ratio upscaler.processes = video2x_args.processes upscaler.video2x_cache_directory = video2x_cache_directory upscaler.image_format = image_format upscaler.preserve_frames = preserve_frames # run upscaler upscaler.run() Avalon.info(
if args.input.is_file(): # upscale single video file Avalon.info(f'Upscaling single video file: {args.input}') # check for input output format mismatch if args.output.is_dir(): Avalon.error('Input and output path type mismatch') Avalon.error('Input is single file but output is directory') raise Exception('input output path type mismatch') if not re.search(r'.*\..*$', str(args.output)): Avalon.error('No suffix found in output file path') Avalon.error('Suffix must be specified for FFmpeg') raise Exception('No suffix specified') upscaler = Upscaler(input_video=args.input, output_video=args.output, method=args.method, waifu2x_settings=waifu2x_settings, ffmpeg_settings=ffmpeg_settings) # set optional options upscaler.waifu2x_driver = args.driver upscaler.scale_width = args.width upscaler.scale_height = args.height upscaler.scale_ratio = args.ratio upscaler.model_dir = args.model_dir upscaler.threads = args.threads upscaler.video2x_cache_directory = video2x_cache_directory upscaler.image_format = image_format upscaler.preserve_frames = preserve_frames # run upscaler upscaler.create_temp_directories() upscaler.run()
def load(self): debug_prefix = "[Dandere2x.load]" # Create Utils self.utils = Utils() # Set the log file, here's why loglevel 0 isn't literally 0 self.utils.clean_set_log() self.utils.log(colors["phases"], 3, debug_prefix, "# # [Load phase] # #") self.utils.log(color, 3, debug_prefix, "Created Utils()") # Check a few things and make sure the settings are compatible self.utils.log(color, 3, debug_prefix, "Creating FailSafe()") self.failsafe = FailSafe(self.utils) # Communication between files, static self.utils.log(color, 3, debug_prefix, "Creating Context()") self.context = Context(self.utils, self.config, self.failsafe) # Communication between files, depends on runtime self.utils.log(color, 3, debug_prefix, "Creating Controller()") self.controller = Controller(self.utils, self.context) # Let Utils access Controller self.utils.log(color, 3, debug_prefix, "Giving Utils, Controller") self.utils.set_controller(self.controller) # Let Utils access Context self.utils.log(color, 3, debug_prefix, "Giving Utils, Context") self.utils.set_context(self.context) # Stats self.utils.log(color, 3, debug_prefix, "Creating Dandere2xStats()") self.stats = Dandere2xStats(self.context, self.utils, self.controller) # Deals with Video related stuff self.utils.log(color, 3, debug_prefix, "Creating Video()") self.video = Video(self.context, self.utils, self.controller) # Deals with images, mostly numpy wrapper and special functions like block substitution self.utils.log(color, 3, debug_prefix, "Creating Frame()") self.frame = Frame # Our upscale wrapper, on which the default is upscaler self.utils.log(color, 3, debug_prefix, "Creating Upscaler()") self.upscaler = Upscaler(self.context, self.utils, self.controller, self.frame) # Math utils, specific cases for Dandere2x self.utils.log(color, 3, debug_prefix, "Creating Dandere2xMath()") self.d2xmath = Dandere2xMath(self.context, self.utils) # Dandere2x C++ wrapper self.utils.log(color, 3, debug_prefix, "Creating Dandere2xCPPWraper()") self.d2xcpp = Dandere2xCPPWraper(self.context, self.utils, self.controller, self.video, self.stats) # "Layers" of processing before the actual upscale from upscaler self.utils.log(color, 3, debug_prefix, "Creating Processing()") self.processing = Processing(self.context, self.utils, self.controller, self.frame, self.video, self.upscaler) # On where everything is controlled and starts self.utils.log(color, 3, debug_prefix, "Creating Core()") self.core = Core(self.context, self.utils, self.controller, self.upscaler, self.d2xcpp, self.processing, self.stats, self.video) # Vapoursynth wrapper self.utils.log(color, 3, debug_prefix, "Creating VapourSynthWrapper()") self.vapoursynth_wrapper = VapourSynthWrapper(self.context, self.utils, self.controller)
# upscale single video file Avalon.info(f'Upscaling single video file: {args.input}') # check for input output format mismatch if args.output.is_dir(): Avalon.error('Input and output path type mismatch') Avalon.error('Input is single file but output is directory') raise Exception('input output path type mismatch') if not re.search(r'.*\..*$', str(args.output)): Avalon.error('No suffix found in output file path') Avalon.error('Suffix must be specified for FFmpeg') raise Exception('No suffix specified') upscaler = Upscaler(input_video=args.input, output_video=args.output, method=args.method, driver_settings=driver_settings, ffmpeg_settings=ffmpeg_settings) # set optional options upscaler.waifu2x_driver = args.driver upscaler.scale_width = args.width upscaler.scale_height = args.height upscaler.scale_ratio = args.ratio upscaler.model_dir = args.model_dir upscaler.processes = args.processes upscaler.video2x_cache_directory = video2x_cache_directory upscaler.image_format = image_format upscaler.preserve_frames = preserve_frames # run upscaler
exit(1) # start execution try: # start timer begin_time = time.time() if os.path.isfile(args.input): """ Upscale single video file """ Avalon.info('Upscaling single video file: {}'.format(args.input)) upscaler = Upscaler(input_video=args.input, output_video=args.output, method=args.method, waifu2x_settings=waifu2x_settings, ffmpeg_settings=ffmpeg_settings, waifu2x_driver=args.driver, scale_width=args.width, scale_height=args.height, scale_ratio=args.ratio, model_dir=args.model_dir, threads=args.threads, video2x_cache_folder=video2x_cache_folder) upscaler.run() upscaler.cleanup() elif os.path.isdir(args.input): """ Upscale videos in a folder/directory """ Avalon.info('Upscaling videos in folder/directory: {}'.format( args.input)) for input_video in [ f for f in os.listdir(args.input) if os.path.isfile(os.path.join(args.input, f)) ]:
# if input specified is a single file if os.path.isfile(args.input): """ Upscale single video file """ Avalon.info('Upscaling single video file: {}'.format(args.input)) # check for input output format mismatch if os.path.isdir(args.output): Avalon.error('Input and output path type mismatch') Avalon.error('Input is single file but output is folder') raise Exception('input output path type mismatch') if not re.search('.*\..*$', args.output): Avalon.error('No suffix found in output file path') Avalon.error('Suffix must be specified for FFmpeg') raise Exception('No suffix specified') upscaler = Upscaler(input_video=args.input, output_video=args.output, method=args.method, waifu2x_settings=waifu2x_settings, ffmpeg_settings=ffmpeg_settings) # set optional options upscaler.waifu2x_driver = args.driver upscaler.scale_width = args.width upscaler.scale_height = args.height upscaler.scale_ratio = args.ratio upscaler.model_dir = args.model_dir upscaler.threads = args.threads upscaler.video2x_cache_folder = video2x_cache_folder upscaler.image_format = image_format upscaler.preserve_frames = preserve_frames # run upscaler- upscaler.run() upscaler.cleanup()
def _upscale(self): # start timer begin_time = time.time() # read configuration file config = read_config('video2x.json') config = absolutify_paths(config) input_file = pathlib.Path(self.input_file.get()) output_file = pathlib.Path(self.output_file.get()) driver = AVAILABLE_DRIVERS[self.driver.get()] if driver == 'waifu2x_caffe': waifu2x_settings = config['waifu2x_caffe'] if not pathlib.Path( waifu2x_settings['waifu2x_caffe_path']).is_file(): messagebox.showerror( 'Error', 'Specified waifu2x-caffe directory doesn\'t exist\nPlease check the configuration file settings' ) raise FileNotFoundError(waifu2x_settings['waifu2x_caffe_path']) elif driver == 'waifu2x_converter': waifu2x_settings = config['waifu2x_converter'] if not pathlib.Path( waifu2x_settings['waifu2x_converter_path']).is_dir(): messagebox.showerror( 'Error', 'Specified waifu2x-converter-cpp directory doesn\'t exist\nPlease check the configuration file settings' ) raise FileNotFoundError( waifu2x_settings['waifu2x_converter_path']) elif driver == 'waifu2x_ncnn_vulkan': waifu2x_settings = config['waifu2x_ncnn_vulkan'] if not pathlib.Path( waifu2x_settings['waifu2x_ncnn_vulkan_path']).is_file(): messagebox.showerror( 'Error', 'Specified waifu2x_ncnn_vulkan directory doesn\'t exist\nPlease check the configuration file settings' ) raise FileNotFoundError( waifu2x_settings['waifu2x_ncnn_vulkan_path']) elif driver == 'anime4k': waifu2x_settings = config['anime4k'] if not pathlib.Path(waifu2x_settings['anime4k_path']).is_file(): messagebox.showerror( 'Error', 'Specified Anime4K directory doesn\'t exist\nPlease check the configuration file settings' ) raise FileNotFoundError(waifu2x_settings['anime4k_path']) # read FFmpeg configuration ffmpeg_settings = config['ffmpeg'] # load video2x settings image_format = config['video2x']['image_format'].lower() preserve_frames = config['video2x']['preserve_frames'] # load cache directory if isinstance(config['video2x']['video2x_cache_directory'], str): video2x_cache_directory = pathlib.Path( config['video2x']['video2x_cache_directory']) else: video2x_cache_directory = pathlib.Path( tempfile.gettempdir()) / 'video2x' if video2x_cache_directory.exists( ) and not video2x_cache_directory.is_dir(): messagebox.showerror('Error', 'Specified cache directory is a file/link') raise FileExistsError('Specified cache directory is a file/link') elif not video2x_cache_directory.exists(): # try creating the cache directory if messagebox.askyesno( 'Question', f'Specified cache directory {video2x_cache_directory} does not exist\nCreate directory?' ): try: video2x_cache_directory.mkdir(parents=True, exist_ok=True) # there can be a number of exceptions here # PermissionError, FileExistsError, etc. # therefore, we put a catch-them-all here except Exception as e: messagebox.showerror( 'Error', f'Unable to create {video2x_cache_directory}\nAborting...' ) raise e else: raise FileNotFoundError('Could not create cache directory') # load more settings from gui width = self.width.get() height = self.height.get() scale_ratio = self.scale_ratio.get() image_format = self.image_format.get() threads = self.threads.get() method = AVAILABLE_METHODS[self.method.get()] preserve_frames = self.preserve_frames.get() self.upscaler = Upscaler(input_video=input_file, output_video=output_file, method=method, waifu2x_settings=waifu2x_settings, ffmpeg_settings=ffmpeg_settings) # set optional options self.upscaler.waifu2x_driver = driver self.upscaler.scale_width = width self.upscaler.scale_height = height self.upscaler.scale_ratio = scale_ratio self.upscaler.model_dir = None self.upscaler.threads = threads self.upscaler.video2x_cache_directory = video2x_cache_directory self.upscaler.image_format = image_format self.upscaler.preserve_frames = preserve_frames # run upscaler self.upscaler.create_temp_directories() # start progress bar progress_bar = threading.Thread(target=self._progress_bar) progress_bar.start() # start upscaling self.upscaler.run() self.upscaler.cleanup_temp_directories() # show message when upscaling completes messagebox.showinfo( 'Info', f'Upscaling Completed\nTime Taken: {round((time.time() - begin_time), 5)} seconds' ) self.progress_bar['value'] = 100 self.running = False self.start_button_text.set('Start')
# Start execution try: # Start timer begin_time = time.time() if os.path.isfile(args.input): """ Upscale single video file """ Avalon.info('Upscaling single video file: {}'.format(args.input)) upscaler = Upscaler(input_video=args.input, output_video=args.output, method=args.method, waifu2x_path=waifu2x_path, ffmpeg_path=ffmpeg_path, waifu2x_driver=args.driver, ffmpeg_arguments=ffmpeg_arguments, ffmpeg_hwaccel=ffmpeg_hwaccel, output_width=args.width, output_height=args.height, ratio=args.ratio, model_type=args.model_type, threads=args.threads, extracted_frames=extracted_frames, upscaled_frames=upscaled_frames) upscaler.run() elif os.path.isdir(args.input): """ Upscale videos in a folder/directory """ Avalon.info('Upscaling videos in folder: {}'.format(args.input)) for input_video in [ f for f in os.listdir(args.input) if os.path.isfile(os.path.join(args.input, f)) ]:
# Start execution try: # Start timer begin_time = time.time() if os.path.isfile(args.input): """ Upscale single video file """ Avalon.info('Upscaling single video file: {}'.format(args.input)) upscaler = Upscaler(input_video=args.input, output_video=args.output, method=args.method, waifu2x_path=waifu2x_path, ffmpeg_path=ffmpeg_path, waifu2x_driver=args.driver, ffmpeg_arguments=ffmpeg_arguments, ffmpeg_hwaccel=ffmpeg_hwaccel, output_width=args.width, output_height=args.height, ratio=args.ratio, model_type=args.model_type, threads=args.threads, video2x_cache_folder=video2x_cache_folder) upscaler.run() upscaler.cleanup() elif os.path.isdir(args.input): """ Upscale videos in a folder/directory """ Avalon.info('Upscaling videos in folder/directory: {}'.format( args.input)) for input_video in [ f for f in os.listdir(args.input) if os.path.isfile(os.path.join(args.input, f))
# upscale single video file Avalon.info( _('Upscaling single video file: {}').format(video2x_args.input)) # check for input output format mismatch if video2x_args.output.is_dir(): Avalon.error(_('Input and output path type mismatch')) Avalon.error(_('Input is single file but output is directory')) raise Exception('input output path type mismatch') if not re.search(r'.*\..*$', str(video2x_args.output)): Avalon.error(_('No suffix found in output file path')) Avalon.error(_('Suffix must be specified for FFmpeg')) raise Exception('No suffix specified') upscaler = Upscaler(input_video=video2x_args.input, output_video=video2x_args.output, driver_settings=driver_settings, ffmpeg_settings=ffmpeg_settings) # set optional options upscaler.driver = video2x_args.driver upscaler.scale_width = video2x_args.width upscaler.scale_height = video2x_args.height upscaler.scale_ratio = video2x_args.ratio upscaler.processes = video2x_args.processes upscaler.video2x_cache_directory = video2x_cache_directory upscaler.image_format = image_format upscaler.preserve_frames = preserve_frames # run upscaler upscaler.run()