From 1364ed507a25532379044dcb6589bd6d1230b40e Mon Sep 17 00:00:00 2001 From: BrianPetkovsek <16124109+BrianPetkovsek@users.noreply.github.com> Date: Sun, 24 Mar 2019 05:25:21 -0400 Subject: [PATCH 1/2] Fixed execution problem Fixed an execution problem where the 2x executable path is not as the first argument resulting in an error. --- bin/waifu2x_caffe.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bin/waifu2x_caffe.py b/bin/waifu2x_caffe.py index e20274b..8403c02 100644 --- a/bin/waifu2x_caffe.py +++ b/bin/waifu2x_caffe.py @@ -61,18 +61,14 @@ class Waifu2xCaffe: # list to be executed execute = [] + execute.append(self.waifu2x_settings['waifu2x_caffe_path']) for key in self.waifu2x_settings.keys(): value = self.waifu2x_settings[key] - # the key doesn't need to be passed in this case - if key == 'waifu2x_caffe_path': - execute.append(str(value)) - - # null or None means that leave this option out (keep default) - elif value is None or value is False: + #is executable key or null or None means that leave this option out (keep default) + if key == 'waifu2x_caffe_path' or value is None or value is False: continue - else: if len(key) == 1: execute.append('-{}'.format(key)) From 5e61268a7b74f9ee917ed9909dd130f99328488a Mon Sep 17 00:00:00 2001 From: BrianPetkovsek <16124109+BrianPetkovsek@users.noreply.github.com> Date: Sun, 24 Mar 2019 05:31:18 -0400 Subject: [PATCH 2/2] added a file clearer added a file clearer for finished downscaled images that take up space. --- bin/clear_image.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++ bin/upscaler.py | 12 +++++++++++ 2 files changed, 66 insertions(+) create mode 100644 bin/clear_image.py diff --git a/bin/clear_image.py b/bin/clear_image.py new file mode 100644 index 0000000..17dfaa9 --- /dev/null +++ b/bin/clear_image.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Name: Waifu2x Image clearer +Author: BrianPetkovsek +Date Created: March 24, 2019 +Last Modified: March 25, 2019 + +Description: This class is to remove the +downscaled image files when upscale is finished +from waifu2x-caffe. +""" + +from threading import Thread +from time import sleep +import os + +class ClearImage(Thread): + def __init__(self, input_folder, output_folder,num_threads): + Thread.__init__(self) + self.input_folder = input_folder + self.output_folder = output_folder + self.num_threads = num_threads + self.running = False + + def run(self): + self.running = True + while(self.running): + self.removeFrames() + #delay in 1 second intrvals for stop trigger + i=0 + while self.running and i<20: + i+=1 + sleep(1) + + + def stop(self): + self.running = False + self.join() + + def removeFrames(self): + # list all images in the extracted frames + output_frames = [f for f in os.listdir(self.output_folder) if os.path.isfile(os.path.join(self.output_folder, f))] + + # compare and remove frames downscaled images that finished being upscaled + for i in range(self.num_threads): + dir_path = os.path.join(self.input_folder,str(i)) + for f in os.listdir(dir_path): + file_path = os.path.join(dir_path, f) + if os.path.isfile(file_path) and f in output_frames: + os.remove(file_path) + output_frames.remove(f) + + diff --git a/bin/upscaler.py b/bin/upscaler.py index 03d4aaf..f26ae9d 100644 --- a/bin/upscaler.py +++ b/bin/upscaler.py @@ -19,6 +19,7 @@ from fractions import Fraction from tqdm import tqdm from waifu2x_caffe import Waifu2xCaffe from waifu2x_converter import Waifu2xConverter +from clear_image import ClearImage import os import re import shutil @@ -209,6 +210,11 @@ class Upscaler: progress_bar = threading.Thread(target=self._progress_bar, args=(thread_folders,)) progress_bar.start() + #Create the clearer and start it + Avalon.debug_info('Starting image clearer...') + image_clear = ClearImage(self.extracted_frames,self.upscaled_frames,len(upscaler_threads)) + image_clear.start() + # start all threads for thread in upscaler_threads: thread.start() @@ -217,6 +223,10 @@ class Upscaler: for thread in upscaler_threads: thread.join() + #upscaling done... kill the clearer + Avalon.debug_info('Stoping image clearer...') + image_clear.stop() + self.progress_bar_exit_signal = True def run(self): @@ -291,3 +301,5 @@ class Upscaler: # migrate audio tracks and subtitles Avalon.info('Migrating audio tracks and subtitles to upscaled video') fm.migrate_audio_tracks_subtitles(self.input_video, self.output_video, self.upscaled_frames) + +