mirror of
				https://github.com/k4yt3x/video2x.git
				synced 2025-11-03 22:21:37 +01:00 
			
		
		
		
	added a file clearer
added a file clearer for finished downscaled images that take up space.
This commit is contained in:
		
							parent
							
								
									1364ed507a
								
							
						
					
					
						commit
						5e61268a7b
					
				
							
								
								
									
										54
									
								
								bin/clear_image.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								bin/clear_image.py
									
									
									
									
									
										Normal file
									
								
							@ -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)
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
							
 | 
				
			||||||
@ -19,6 +19,7 @@ from fractions import Fraction
 | 
				
			|||||||
from tqdm import tqdm
 | 
					from tqdm import tqdm
 | 
				
			||||||
from waifu2x_caffe import Waifu2xCaffe
 | 
					from waifu2x_caffe import Waifu2xCaffe
 | 
				
			||||||
from waifu2x_converter import Waifu2xConverter
 | 
					from waifu2x_converter import Waifu2xConverter
 | 
				
			||||||
 | 
					from clear_image import ClearImage
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
@ -209,6 +210,11 @@ class Upscaler:
 | 
				
			|||||||
        progress_bar = threading.Thread(target=self._progress_bar, args=(thread_folders,))
 | 
					        progress_bar = threading.Thread(target=self._progress_bar, args=(thread_folders,))
 | 
				
			||||||
        progress_bar.start()
 | 
					        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
 | 
					        # start all threads
 | 
				
			||||||
        for thread in upscaler_threads:
 | 
					        for thread in upscaler_threads:
 | 
				
			||||||
            thread.start()
 | 
					            thread.start()
 | 
				
			||||||
@ -217,6 +223,10 @@ class Upscaler:
 | 
				
			|||||||
        for thread in upscaler_threads:
 | 
					        for thread in upscaler_threads:
 | 
				
			||||||
            thread.join()
 | 
					            thread.join()
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
					        #upscaling done... kill the clearer
 | 
				
			||||||
 | 
					        Avalon.debug_info('Stoping image clearer...')
 | 
				
			||||||
 | 
					        image_clear.stop()
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        self.progress_bar_exit_signal = True
 | 
					        self.progress_bar_exit_signal = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def run(self):
 | 
					    def run(self):
 | 
				
			||||||
@ -291,3 +301,5 @@ class Upscaler:
 | 
				
			|||||||
        # migrate audio tracks and subtitles
 | 
					        # migrate audio tracks and subtitles
 | 
				
			||||||
        Avalon.info('Migrating audio tracks and subtitles to upscaled video')
 | 
					        Avalon.info('Migrating audio tracks and subtitles to upscaled video')
 | 
				
			||||||
        fm.migrate_audio_tracks_subtitles(self.input_video, self.output_video, self.upscaled_frames)
 | 
					        fm.migrate_audio_tracks_subtitles(self.input_video, self.output_video, self.upscaled_frames)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user