Exemple #1
0
    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.context.frame_count):
            file_names.append("output_" + get_lexicon_value(6, x))

        for file in file_names:
            dirty_name = self.context.residual_upscaled_dir + file + '_[NS-L' + str(
                self.context.service_request.denoise_level) + '][x' + str(
                    self.context.service_request.scale_factor
                ) + '.000000]' + ".png"
            clean_name = self.context.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
Exemple #2
0
    def __fix_waifu2x_ncnn_vulkan_names(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.context.frame_count):
            file_names.append("output_" + get_lexicon_value(6, x))

        for file in file_names:
            dirty_name = self.context.residual_upscaled_dir + file + ".png.png"
            clean_name = self.context.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
Exemple #3
0
    def __upscale_first_frame(self):
        """
        The first frame of any dandere2x session needs to be upscaled fully, and this is done as it's own
        process. Ensuring the first frame can get upscaled also provides a source of error checking for the user.
        """

        # measure the time to upscale a single frame for printing purposes
        one_frame_time = time.time()
        self.waifu2x.upscale_file(input_image=self.context.input_frames_dir +
                                  "frame" + str(1) + ".png",
                                  output_image=self.context.merged_dir +
                                  "merged_" + str(1) + ".png")

        if not file_exists(self.context.merged_dir + "merged_" + str(1) +
                           ".png"):
            """ 
            Ensure the first file was able to get upscaled. We literally cannot continue if it doesn't. 
            """
            self.log.error(
                "Could not upscale first file. Dandere2x CANNOT continue.")
            self.log.error("Have you tried making sure your waifu2x works?")

            raise Exception(
                "Could not upscale first file.. check logs file to see what's wrong"
            )

        self.log.info("Time to upscale a single frame: %s ",
                      str(round(time.time() - one_frame_time, 2)))
Exemple #4
0
    def verify_upscaling_works(self) -> None:
        """
        Verify the upscaler works by upscaling a very small frame, and throws a descriptive error if it doesn't.
        """
        test_file = self.context.service_request.workspace + "test_frame.jpg"
        test_file_upscaled = self.context.service_request.workspace + "test_frame_upscaled.jpg"

        test_frame = Frame()
        test_frame.create_new(2, 2)
        test_frame.save_image(test_file)

        self.log.info(
            "Attempting to upscale file %s into %s to ensure waifu2x is working..."
            % (test_file, test_file_upscaled))

        self.upscale_file(test_file, test_file_upscaled)

        if not file_exists(test_file_upscaled):
            self.log.error(
                "Your computer could not upscale a test image, which is required for dandere2x to work."
            )
            self.log.error(
                "This may be a hardware issue or a software issue - verify your computer is capable of upscaling "
                "images using the selected upscaler.")

            raise Exception("Your computer could not upscale the test file.")

        self.log.info(
            "Upscaling *seems* successful. Deleting files and continuing forward. "
        )

        os.remove(test_file)
        os.remove(test_file_upscaled)
Exemple #5
0
if nosound_file == "":
    log.error("Could not find `nosound` in %s! I cannot continue" % dandere2x.context.workspace)
    input("Press Enter to continue...")
    exit(1)

log.info("Found your nosound_file at %s" % nosound_file)
time.sleep(0.1)

print("-------------------------------------------------")
log.warning("Please verify that %s is your complete upscaled video, just has no audio" % nosound_file)
time.sleep(0.1)
input("Press Enter to continue...")

output_extension = os.path.splitext(nosound_file)[1]
output_file = dandere2x.context.workspace + "outputfile" + output_extension
log.info("We will now begin to try to manually migrate the tracks... standby")
log.info("Output video will be at %s " % output_file)

migrate_tracks(context=dandere2x.context, no_audio=nosound_file, file_dir=pre_processed_file, output_file=output_file)

if file_exists(output_file):
    log.info("It seems migration succeeded? Check %s to see if it finished." % output_file)
else:
    log.warning("It seems the file is not there.. this is indicative of a migration failure somewhere")
    log.warning("You can try migrating yourself (above you should see an output called 'Migrate Command:' or something")
    log.warning("From ffmmpeg.py, and you can try changing the flags until it migrates correctly, but tbh beyond that")
    log.warning("You may need to goto forums to answer this problem. ")

time.sleep(0.1)
input("Press Enter to continue...")