Beispiel #1
0
    def run(self):
        for count in range(1, self.frame_count + 1):
            extracted_image = self.extracted_frames_dir + "frame%s.png" % count

            wait_on_file(extracted_image)

            noise_sub_thread = threading.Thread(target=self._noise_image_sub_thread, args=(count,))
            noise_sub_thread.start()
Beispiel #2
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)
Beispiel #3
0
    def run(self) -> None:

        for x in range(len(self.list_of_names)):
            name = self.list_of_names[x]
            residual_file = self.context.residual_images_dir + name
            residual_upscaled_file = self.context.residual_upscaled_dir + name

            wait_on_file(residual_upscaled_file)

            if os.path.exists(residual_file):
                os.remove(residual_file)
            else:
                pass
Beispiel #4
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)
Beispiel #5
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')
Beispiel #6
0
    def run(self):
        self.log.info("Started")
        self.pipe.start()

        # Load the genesis image + the first upscaled image.
        frame_previous = Frame()
        frame_previous.load_from_string_controller(
            self.context.merged_dir + "merged_" + str(1) + ".jpg",
            self.controller)

        # Load and pipe the 'first' image before we start the for loop procedure, since all the other images will
        # inductively build off this first frame.
        frame_previous = Frame()
        frame_previous.load_from_string_controller(
            self.context.merged_dir + "merged_" + str(1) + ".jpg",
            self.controller)
        self.pipe.save(frame_previous)

        current_upscaled_residuals = Frame()
        current_upscaled_residuals.load_from_string_controller(
            self.context.residual_upscaled_dir + "output_" +
            get_lexicon_value(6, 1) + ".png", self.controller)

        last_frame = False
        for x in range(1, self.context.frame_count):
            ########################################
            # Pre-loop logic checks and conditions #
            ########################################

            # Check if we're at the last image, which affects the behaviour of the loop.
            if x == self.context.frame_count - 1:
                last_frame = True

            # Pre-load the next iteration of the loop image ahead of time, if we're not on the last frame.
            if not last_frame:
                """ 
                By asynchronously loading frames ahead of time, this provides a small but meaningful
                boost in performance when spanned over N frames. There's some code over head but 
                it's well worth it. 
                """
                background_frame_load = AsyncFrameRead(
                    self.context.residual_upscaled_dir + "output_" +
                    get_lexicon_value(6, x + 1) + ".png", self.controller)
                background_frame_load.start()

            ######################
            # Core Logic of Loop #
            ######################

            # Load the needed vectors to create the merged image.

            prediction_data_list = get_list_from_file_and_wait(
                self.context.pframe_data_dir + "pframe_" + str(x) + ".txt")
            residual_data_list = get_list_from_file_and_wait(
                self.context.residual_data_dir + "residual_" + str(x) + ".txt")
            correction_data_list = get_list_from_file_and_wait(
                self.context.correction_data_dir + "correction_" + str(x) +
                ".txt")
            fade_data_list = get_list_from_file_and_wait(
                self.context.fade_data_dir + "fade_" + str(x) + ".txt")

            # Create the actual image itself.
            current_frame = self.make_merge_image(
                self.context, current_upscaled_residuals, frame_previous,
                prediction_data_list, residual_data_list, correction_data_list,
                fade_data_list)
            ###############
            # Saving Area #
            ###############
            # Directly write the image to the ffmpeg pipe line.
            self.pipe.save(current_frame)

            # Manually write the image if we're preserving frames (this is for enthusiasts / debugging).
            # if self.preserve_frames:
            # if True:
            #     output_file = self.context.merged_dir + "merged_" + str(x + 1) + ".jpg"
            #     background_frame_write = AsyncFrameWrite(current_frame, output_file)
            #     background_frame_write.start()

            #######################################
            # Assign variables for next iteration #
            #######################################
            if not last_frame:
                # We need to wait until the next upscaled image exists before we move on.
                while not background_frame_load.load_complete:
                    wait_on_file(self.context.residual_upscaled_dir +
                                 "output_" + get_lexicon_value(6, x + 1) +
                                 ".png")
            """
            Now that we're all done with the current frame, the current `current_frame` is now the frame_previous
            (with respect to the next iteration). We could obviously manually load frame_previous = Frame(n-1) each
            time, but this is an optimization that makes a substantial difference over N frames.
            """
            frame_previous = current_frame
            current_upscaled_residuals = background_frame_load.loaded_image
            self.controller.update_frame_count(x)

        self.pipe.kill()