def run(self): logger = logging.getLogger(__name__) exec = [ self.dandere2x_cpp_dir, self.workspace, str(self.frame_count), str(self.block_size), str(self.step_size), "n", str(1), self.extension_type ] logger.info(exec) # On linux, we can't use subprocess.create_new_console, so we just write # The dandere2x_cpp output to a text file. if get_operating_system() == 'win32': return_val = subprocess.run( exec, creationflags=subprocess.CREATE_NEW_CONSOLE).returncode elif get_operating_system() == 'linux': console_output = open(self.log_dir + "dandere2x_cpp.txt", "w") console_output.write(str(exec)) return_val = subprocess.run(exec, shell=False, stderr=console_output, stdout=console_output).returncode if return_val == 0: logger.info("d2xcpp finished correctly") else: logger.info("d2xcpp ended unexpectedly")
def press_upscale_button(self): self.ui.upscale_status_label.setFont( QtGui.QFont("Yu Gothic UI Semibold", 11, QtGui.QFont.Bold)) self.ui.upscale_status_label.setText("Upscaling in Progress") self.ui.upscale_status_label.setStyleSheet('color: #fad201') self.parse_gui_inputs() print(os.getcwd()) if get_operating_system() == 'win32': with open(os.path.join(self.this_folder, "dandere2x_win32.json"), "r") as read_file: config_json = json.load(read_file) elif get_operating_system() == 'linux': with open(os.path.join(self.this_folder, "dandere2x_linux.json"), "r") as read_file: config_json = json.load(read_file) config_json['dandere2x']['usersettings'][ 'output_file'] = self.output_file config_json['dandere2x']['usersettings'][ 'input_file'] = self.input_file config_json['dandere2x']['usersettings'][ 'block_size'] = self.block_size config_json['dandere2x']['usersettings'][ 'image_quality'] = self.image_quality config_json['dandere2x']['usersettings'][ 'waifu2x_type'] = self.waifu2x_type config_json['dandere2x']['usersettings'][ 'scale_factor'] = self.scale_factor print("output_file = " + self.output_file) print("input_file = " + self.input_file) print("block_size = " + str(self.block_size)) print("image_quality = " + str(self.image_quality)) print("waifu2x_type = " + self.waifu2x_type) self.thread = QtDandere2xThread(self, config_json) self.thread.finished.connect(self.update) self.disable_buttons() try: self.thread.start() except: print("Oops!", sys.exc_info()[0], "occured.") self.ui.upscale_status_label.setFont( QtGui.QFont("Yu Gothic UI Semibold", 11, QtGui.QFont.Bold)) self.ui.upscale_status_label.setText("Upscale Failed. See log")
def cli_start(args): """ Start Dandere2x using command line :param args: args loaded from load_parser() :return: none """ # get config based on OS configfile = "dandere2x_%s.yaml" % get_operating_system() # load yaml with open(configfile, "r") as read_file: config = yaml.safe_load(read_file) config['dandere2x']['usersettings']['output_file'] = args.output_file config['dandere2x']['usersettings']['input_file'] = args.input_file config['dandere2x']['usersettings']['block_size'] = args.block_size config['dandere2x']['usersettings']['quality_minimum'] = args.image_quality config['dandere2x']['usersettings']['waifu2x_type'] = args.waifu2x_type config['dandere2x']['usersettings']['scale_factor'] = args.scale_factor config['dandere2x']['usersettings']['denoise_level'] = args.noise_level print("arg input file: " + args.input_file) if os.path.isdir(args.input_file): print("is not dir") if not os.path.isdir(args.output_file): print( "input is type 'directory' but output is not type 'directory'. Dandere2x exiting" ) sys.exit(1) config['dandere2x']['usersettings']['input_folder'] = args.input_file config['dandere2x']['usersettings']['output_folder'] = args.output_file d2x = Dandere2xUpscaleFolder(config) d2x.start() else: context = Context(config) if dir_exists(context.workspace): print("Deleted Folder") # This is a recurring bug that seems to be popping up on other people's operating systems. # I'm unsure if this will fix it, but it could provide a solution for people who can't even get d2x to work. try: shutil.rmtree(context.workspace) except PermissionError: print( "Trying to delete workspace via RM tree threw PermissionError - Dandere2x may not work." ) while (file_exists(context.workspace)): time.sleep(1) d2x = Dandere2x(context) d2x.start() d2x.join()
def parse_gui_inputs(self): # f**k windows and it's file management system if get_operating_system() == 'win32': self.output_file = self.output_file.replace("/", "\\") self.input_file = self.input_file.replace("/", "\\") # Scale Factors if self.ui.scale_1_radio_button.isChecked(): self.scale_factor = 1 if self.ui.scale_2_radio_button.isChecked(): self.scale_factor = 2 if self.ui.scale_3_radio_button.isChecked(): self.scale_factor = 3 if self.ui.scale_4_radio_button.isChecked(): self.scale_factor = 4 # Noise factors if self.ui.noise_0_radio_button.isChecked(): self.noise_level = 0 if self.ui.noise_1_radio_button.isChecked(): self.noise_level = 1 if self.ui.noise_2_radio_button.isChecked(): self.noise_level = 2 if self.ui.noise_3_radio_button.isChecked(): self.noise_level = 3 # Dandere2x Settings self.image_quality = int(self.ui.image_quality_box.currentText()) self.block_size = int(self.ui.block_size_combo_box.currentText()) self.config_file = self.ui.config_select_box.currentText() print("config file: " + self.config_file) # Waifu2x Type if self.ui.waifu2x_type_combo_box.currentText() == 'Waifu2x-Caffe': self.waifu2x_type = 'caffe' if self.ui.waifu2x_type_combo_box.currentText() == 'Waifu2x-Vulkan': self.waifu2x_type = 'vulkan' if self.ui.waifu2x_type_combo_box.currentText() == 'RealSR': self.waifu2x_type = 'realsr_ncnn_vulkan' if self.ui.waifu2x_type_combo_box.currentText( ) == 'Waifu2x-Converter-Cpp': self.waifu2x_type = "converter_cpp"
def __init__(self): super().__init__() config_names = [] os.chdir(os.getcwd()) for file in glob.glob("*.yaml"): config_names.append(file) self.ui = Ui_Dandere2xGUI() self.ui.setupUi(self, config_names) _translate = QtCore.QCoreApplication.translate self.ui.config_select_box.setCurrentText( _translate("Dandere2xGUI", "Waifu2x-Caffe")) # load 'this folder' in a pyinstaller friendly way self.this_folder = os.getcwd() self.ui.suspend_button.setEnabled(True) # Note: At the moment running d2x from venv on windows 10 is having issues with this # segment of code. I've left it commented for the time being since I'm unsure if pyinstaller # requires this part, but it may be removed all together once tested properly. # # if getattr(sys, 'frozen', False): # self.this_folder = os.path.dirname(sys.executable) + os.path.sep # elif __file__: # self.this_folder = os.path.dirname(__file__) + os.path.sep # lazy hack_around for linux build (im not sure why the previous statement doesnt work on venv linux) if get_operating_system() == "linux": self.this_folder = os.getcwd() self.input_file = '' self.output_file = '' self.config_file = '' self.scale_factor = None self.noise_level = None self.image_quality = None self.block_size = '' self.waifu2x_type = '' self.use_default_name = True # theres a bug with qt designer and '80' for default quality needs to be set elsewhere _translate = QtCore.QCoreApplication.translate self.ui.image_quality_box.setCurrentText( _translate("Dandere2xGUI", "95")) self.ui.block_size_combo_box.setCurrentText( _translate("Dandere2xGUI", "20")) self.ui.waifu2x_type_combo_box.setCurrentText( _translate("Dandere2xGUI", "Waifu2x-Vulkan")) # self.ui.video_icon.setPixmap(QtGui.QPixmap("assets\\aka.png")) self.config_buttons() self.refresh_scale_factor() self.show()
def run(self): logger = logging.getLogger(__name__) logger.info(self.exec_command) # On linux, we can't use subprocess.create_new_console, so we just write # The dandere2x_cpp output to a text file. if get_operating_system() == 'win32': self.dandere2x_cpp_subprocess = subprocess.Popen(self.exec_command, creationflags=subprocess.CREATE_NEW_CONSOLE) elif get_operating_system() == 'linux': console_output = open(self.log_dir + "dandere2x_cpp.txt", "w") console_output.write(str(self.exec_command)) self.dandere2x_cpp_subprocess = subprocess.Popen(self.exec_command, shell=False, stderr=console_output, stdout=console_output) if self.dandere2x_cpp_subprocess.returncode == 0: logger.info("d2xcpp finished correctly") else: logger.info("d2xcpp ended unexpectedly")
def main(): start = time.time() # get config based on OS configfile = "dandere2x_%s.yaml" % get_operating_system() # load yaml with open(configfile, "r") as read_file: config = yaml.safe_load(read_file) # continue d2x d2x = Dandere2x_Gui_Wrapper(config) d2x.start() print("\n Total runtime duration:", time.time() - start)
def run(self): self.log.info("Run called.") last_10 = [0] path, name = os.path.split( self.context.input_file) # get file name only for x in range(self.start_frame, self.frame_count - 1): if not self.context.controller.is_alive(): break percent = int(((x + 1) / (self.frame_count - 1)) * 100) average = 0 for time_count in last_10: average = average + time_count average = round(average / len(last_10), 2) # sys.stdout.write('\r') # sys.stdout.write("[File: %s][Frame: [%s] %i%%] Average of Last 10 Frames: %s sec / frame" % (name,x, percent, average)) if get_operating_system() == 'win32': ctypes.windll.kernel32.SetConsoleTitleW( "[File: %s][Frame: [%s] %i%%] Average of Last 10 Frames: %s sec / frame" % (name, x, percent, average)) else: sys.stdout.write('\r') sys.stdout.write( "[File: %s][Frame: [%s] %i%%] Average of Last 10 Frames: %s sec / frame" % (name, x, percent, average)) if len(last_10) == 10: last_10.pop(0) now = time.time() while x >= self.context.controller.get_current_frame( ) and self.context.controller.is_alive(): time.sleep(.00001) later = time.time() difference = float(later - now) last_10.append(difference)
def debug_start(): """ Debug function meant for dandere2x development. Starts dandere2x with minimal exterior function calls and will only work based off what's in the yaml. """ # get config based on OS configfile = "dandere2x_%s.yaml" % get_operating_system() # load yaml with open(configfile, "r") as read_file: config = yaml.safe_load(read_file) # load the context with yaml stuff context = Context(config) # continue d2x d2x = Dandere2x(context) d2x.run_concurrent()
def main(): start = time.time() # get config based on OS configfile = "dandere2x_%s.yaml" % get_operating_system() # load yaml with open(configfile, "r") as read_file: config = yaml.safe_load(read_file) # load the context with yaml stuff context = Context(config) # continue d2x d2x = Dandere2x(context) d2x.run_concurrent() print("\n Total runtime duration:", time.time() - start)
def __init__(self): super().__init__() self.ui = Ui_Dandere2xGUI() self.ui.setupUi(self) # load 'this folder' in a pyinstaller friendly way self.this_folder = os.getcwd() if getattr(sys, 'frozen', False): self.this_folder = os.path.dirname(sys.executable) + os.path.sep elif __file__: self.this_folder = os.path.dirname(__file__) + os.path.sep # lazy hack_around for linux build (im not sure why the previous statement doesnt work on venv linux) if get_operating_system() == "linux": self.this_folder = os.getcwd() self.input_file = '' self.output_file = '' self.scale_factor = None self.noise_level = None self.image_quality = None self.block_size = '' self.waifu2x_type = '' self.use_default_name = True # theres a bug with qt designer and '80' for default quality needs to be set elsewhere _translate = QtCore.QCoreApplication.translate self.ui.image_quality_box.setCurrentText( _translate("Dandere2xGUI", "85")) self.ui.block_size_combo_box.setCurrentText( _translate("Dandere2xGUI", "20")) self.ui.waifu2x_type_combo_box.setCurrentText( _translate("Dandere2xGUI", "Waifu2x-Vulkan")) # self.ui.video_icon.setPixmap(QtGui.QPixmap("assets\\aka.png")) self.config_buttons() self.refresh_scale_factor() self.show()
def press_upscale_button(self): self.ui.upscale_status_label.setFont( QtGui.QFont("Yu Gothic UI Semibold", 11, QtGui.QFont.Bold)) self.ui.upscale_status_label.setText("Upscaling in Progress") self.ui.upscale_status_label.setStyleSheet('color: #fad201') self.parse_gui_inputs() print(os.getcwd()) if get_operating_system() == 'win32': with open(os.path.join(self.this_folder, self.config_file), "r") as read_file: config_yaml = yaml.safe_load(read_file) if self.is_suspend_file(self.input_file): print("is suspend file") print("input file: " + str(self.input_file)) with open(self.input_file, "r") as read_file: config_yaml = yaml.safe_load(read_file) else: print("is not suspend file") # if user selected video file config_yaml['dandere2x']['usersettings'][ 'output_file'] = self.output_file config_yaml['dandere2x']['usersettings'][ 'input_file'] = self.input_file config_yaml['dandere2x']['usersettings'][ 'block_size'] = self.block_size config_yaml['dandere2x']['usersettings'][ 'quality_minimum'] = self.image_quality config_yaml['dandere2x']['usersettings'][ 'waifu2x_type'] = self.waifu2x_type config_yaml['dandere2x']['usersettings'][ 'scale_factor'] = self.scale_factor config_yaml['dandere2x']['usersettings'][ 'denoise_level'] = self.noise_level print("output_file = " + config_yaml['dandere2x']['usersettings']['output_file']) print("input_file = " + config_yaml['dandere2x']['usersettings']['input_file']) print("block_size = " + str(config_yaml['dandere2x']['usersettings']['block_size'])) print("block_size = " + str(config_yaml['dandere2x']['usersettings']['block_size'])) print("image_quality = " + str(config_yaml['dandere2x']['usersettings']['quality_minimum'])) print("waifu2x_type = " + config_yaml['dandere2x']['usersettings']['waifu2x_type']) print("workspace = " + config_yaml['dandere2x']['developer_settings']['workspace']) self.thread = QtDandere2xThread(self, config_yaml) self.thread.finished.connect(self.update) self.disable_buttons() try: self.thread.start() except: print("Oops!", sys.exc_info()[0], "occured.") self.ui.upscale_status_label.setFont( QtGui.QFont("Yu Gothic UI Semibold", 11, QtGui.QFont.Bold)) self.ui.upscale_status_label.setText("Upscale Failed. See log")
) print( "This program will attempt to fix your video by manually completing the dandere2x process, what it should of done at 99%." ) print( "I've been unable to replicate this bug on any of my window's versions (i've gone through 3 different versions of windows over the past year)." ) print( "What we're going to do is manually try to migrate the audio tracks using what I know (I being the developer)" ) print("Be sure to be run this program as administrator by the way. ") print( "----------------------------------------------------------------------------------------------------------------------------" ) dandere2x_config_file = "dandere2x_%s.yaml" % get_operating_system() print(" > Attempting to read %s" % dandere2x_config_file) config = None try: with open(dandere2x_config_file, "r") as read_file: config = yaml.safe_load(read_file) print("File read!") except: print("Couldn't open %s, exiting" % dandere2x_config_file) exit(1) print(" > Attempting to load context / dandere2x with this file...") import logging