示例#1
0
    def _successful_completion(self):
        """
        This is called when Dandere2x 'finishes' successfully, and the finishing conditions (such as making sure
        subtitles get migrated, merging videos (if necessary), and deleting the workspace.
        """
        self.log.info("It seems Dandere2x has finished successfully. Starting the final steps to complete your video.")

        if self.context.resume_session:
            """
            In the event if Dandere2x is resuming a session, it'll need to merge `incomplete_video` (see yaml) with
            the current session's video, in order to make a complete video. 
            """

            self.log.info("This session is a resume session. Dandere2x will need to merge the two videos. ")
            file_to_be_concat = self.context.workspace + "file_to_be_concat.mp4"

            rename_file(self.context.nosound_file, file_to_be_concat)
            concat_two_videos(self.context, self.context.incomplete_video, file_to_be_concat, self.context.nosound_file)
            self.log.info("Merging the two videos is done. ")

        migrate_tracks(self.context, self.context.nosound_file, self.context.sound_file, self.context.output_file)
        """
        At this point, dandere2x is "done" with the video, and all there is left is to clean up the files we used
        during runtime.
        """

        # Close the file handler for log (since it's going to get deleted).
        self.log.info("Release log file... ")
        self.fh.close()
        self.log.removeHandler(self.fh)
        del self.fh

        if self.context.delete_workspace_after:
            self.log.info("Dandere2x will now delete the workspace it used.")
            force_delete_directory(self.context.workspace)
    def fix_names(self):

        list_of_names = os.listdir(self.upscaled_dir)
        for name in list_of_names:
            if '[NS-L3][x' + self.scale_factor + '.000000]' in name:
                rename_file(self.upscaled_dir + name,
                            self.upscaled_dir + name.replace('_[NS-L3][x' + self.scale_factor + '.000000]', ''))
    def __fix_waifu2x_converter_cpp_names(self):
        """
            Waifu2x-Conveter-Cpp (legacy) will output the file names in a format that needs to be fixed for
            dandere2x to work. I believe this is fixed in later versions, hence the TODO
        """

        file_names = []
        for x in range(1, self.frame_count):
            file_names.append("output_" + get_lexicon_value(6, x))

        for file in file_names:
            dirty_name = self.residual_upscaled_dir + file + '_[NS-L' + str(
                self.noise_level) + '][x' + str(
                    self.scale_factor) + '.000000]' + ".png"
            clean_name = self.residual_upscaled_dir + file + ".png"

            wait_on_either_file_controller(clean_name, dirty_name,
                                           self.controller)

            if file_exists(clean_name):
                pass

            elif file_exists(dirty_name):
                while file_exists(dirty_name):
                    try:
                        rename_file(dirty_name, clean_name)
                    except PermissionError:
                        pass
示例#4
0
    def fix_names_all(self):
        """
        Waifu2x-ncnn-vulkan will accept a file as "file.jpg" and output as "file.jpg.png".

        Unfortunately, dandere2x wouldn't recognize this, so this function renames each name to the correct naming
        convention. This function will iteratiate through every file needing to be upscaled waifu2x-ncnn-vulkan,
        and change it's name after it's done saving

        Comments:

        - There's a really complicated try / except that exists because, even though a file may exist,
          the file handle may still be used by waifu2x-ncnn-vulkan (it hasn't released it yet). As a result,
          we need to try / except it until it's released, allowing us to rename it.

        """

        file_names = []
        for x in range(1, self.frame_count):
            file_names.append("output_" + get_lexicon_value(6, x))

        for file in file_names:
            dirty_name = self.residual_upscaled_dir + file + ".jpg.png"
            clean_name = self.residual_upscaled_dir + file + ".png"

            wait_on_either_file(clean_name, dirty_name)

            if file_exists(clean_name):
                pass

            elif file_exists(dirty_name):
                while file_exists(dirty_name):
                    try:
                        rename_file(dirty_name, clean_name)
                    except PermissionError:
                        pass
    def fix_names(self):

        list_of_names = os.listdir(self.upscaled_dir)
        for name in list_of_names:
            if '.jpg.jpg' in name:
                rename_file(
                    self.upscaled_dir + name,
                    self.upscaled_dir + name.replace('.jpg.png', '.png'))
示例#6
0
    def save_image_temp(self, out_location, temp_location):
        """
        Save an image in the "temp_location" folder to prevent another program from accessing the file
        until it's done writing.

        This is done to prevent other parts from using an image until it's entirely done writing.
        """

        self.save_image(temp_location)
        wait_on_file(temp_location)
        rename_file(temp_location, out_location)
示例#7
0
    def save_image_quality(self, out_location, quality_per):
        extension = os.path.splitext(os.path.basename(out_location))[1]

        if 'jpg' in extension:
            jpegsave = Image.fromarray(self.frame.astype(np.uint8))
            jpegsave.save(out_location + "temp" + extension, format='JPEG', subsampling=0, quality=quality_per)
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)
        else:
            misc.imsave(out_location + "temp" + extension, self.frame)
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)
示例#8
0
    def join(self, timeout=None):

        start = time.time()  # for printing out total runtime

        logging.info("dandere2x joined called")

        # due to a weird quirk, prevent dandere2x from being joined until nosound.mkv exists (at least).
        wait_on_file(self.context.nosound_file)

        logging.info("joining residual")
        self.residual_thread.join()

        if self.context.use_min_disk:
            logging.info("joining min disk demon")
            self.min_disk_demon.join()

        logging.info("joining merge")
        self.merge_thread.join()
        logging.info("joining waifu2x")
        self.waifu2x.join()
        logging.info("joining dandere2x")
        self.dandere2x_cpp_thread.join()
        logging.info("joining status")
        self.status_thread.join()
        logging.info("joining compress")
        self.compress_frames_thread.join()

        self.context.logger.info("All threaded processes have finished")
        print("All threaded processes have been finished")

        if self.resume_session:
            print("Session is a resume session, concatenating two videos")
            logging.info(
                "Session is a resume session, concatenating two videos")
            file_to_be_concat = self.context.workspace + "file_to_be_concat.mp4"

            rename_file(self.context.nosound_file, file_to_be_concat)
            concat_two_videos(
                self.context,
                self.context.config_yaml['resume_settings']['nosound_file'],
                file_to_be_concat, self.context.nosound_file)

        # if this became a suspended dandere2x session, kill it.
        if not self.alive:
            logging.info("Invoking suspend exit conditions")
            self.__suspend_exit_conditions()

        elif self.alive:
            logging.info("Migrating tracks")
            migrate_tracks(self.context, self.context.nosound_file,
                           self.context.sound_file, self.context.output_file)

        print("Total runtime : ", time.time() - start)
示例#9
0
    def _successful_completion(self):
        if self.context.resume_session:
            print("Session is a resume session, concatenating two videos")
            file_to_be_concat = self.context.workspace + "file_to_be_concat.mp4"

            rename_file(self.context.nosound_file, file_to_be_concat)
            concat_two_videos(self.context, self.context.incomplete_video,
                              file_to_be_concat, self.context.nosound_file)

        migrate_tracks(self.context, self.context.nosound_file,
                       self.context.sound_file, self.context.output_file)

        if self.context.delete_workspace_after:
            force_delete_directory(self.context.workspace)
示例#10
0
    def save_image_quality(self, out_location, quality_per):
        """
        Save an image with JPEG using the JPEG quality-compression ratio. 100 will be the best, while 0 will
        be the worst.
        """

        extension = os.path.splitext(os.path.basename(out_location))[1]

        if 'jpg' in extension:
            jpegsave = Image.fromarray(self.frame.astype(np.uint8))
            jpegsave.save(out_location + "temp" + extension, format='JPEG', subsampling=0, quality=quality_per)
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)
        else:
            misc.imsave(out_location + "temp" + extension, self.frame)
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)
示例#11
0
    def save_image(self, out_location):
        """
        Save an image with specific instructions depending on it's extension type.
        """
        extension = os.path.splitext(os.path.basename(out_location))[1]

        if 'jpg' in extension:
            jpegsave = self.get_pil_image()
            jpegsave.save(out_location + "temp" + extension, format='JPEG', subsampling=0, quality=100)
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)

        else:
            save_image = self.get_pil_image()
            save_image.save(out_location + "temp" + extension, format='PNG')
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)
    def fix_names_all(self):

        file_names = []
        for x in range(1, self.frame_count):
            file_names.append("output_" + get_lexicon_value(6, x))

        for file in file_names:
            dirty_name = self.upscaled_dir + file + ".jpg.png"
            clean_name = self.upscaled_dir + file + ".png"

            wait_on_either_file(clean_name, dirty_name)

            if file_exists(clean_name):
                pass

            elif file_exists(dirty_name):
                while file_exists(dirty_name):
                    try:
                        rename_file(dirty_name, clean_name)
                    except PermissionError:
                        pass
    def fix_names_all(self):

        file_names = []
        for x in range(1, self.frame_count):
            file_names.append("output_" + get_lexicon_value(6, x))

        for file in file_names:
            dirty_name = self.residual_upscaled_dir + file + '_[NS-L' + str(
                self.noise_level) + '][x' + str(
                    self.scale_factor) + '.000000]' + ".png"
            clean_name = self.residual_upscaled_dir + file + ".png"

            wait_on_either_file(clean_name, dirty_name)

            if file_exists(clean_name):
                pass

            elif file_exists(dirty_name):
                while file_exists(dirty_name):
                    try:
                        rename_file(dirty_name, clean_name)
                    except PermissionError:
                        pass
示例#14
0
    def save_image_quality(self, out_location, quality_per):
        """
        Save an image with JPEG using the JPEG quality-compression ratio. 100 will be the best, while 0 will
        be the worst.
        """

        extension = os.path.splitext(os.path.basename(out_location))[1]

        if 'jpg' in extension:
            jpegsave = Image.fromarray(self.frame.astype(np.uint8))
            jpegsave.save(out_location + "temp" + extension,
                          format='JPEG',
                          subsampling=0,
                          quality=quality_per)
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)
        else:
            # todo, fix this
            self.logger.error(
                "Aka-katto has removed this customization you added - he's going to re-add it later."
            )
            self.logger.error('Sorry about that : \\')
            raise ValueError('See Console')
示例#15
0
 def save_image_temp(self, out_location, temp_location):
     self.save_image(temp_location)
     wait_on_file(temp_location)
     rename_file(temp_location, out_location)