debug code + nicer look

This commit is contained in:
2023-03-28 15:12:15 +02:00
parent be74be1bf7
commit e43a4f6546
2 changed files with 21 additions and 17 deletions

View File

@@ -60,10 +60,10 @@ class Handler:
# Determining filetype # Determining filetype
if str(filepath)[len(filepath) - 4:] == ".mp4" or str(filepath)[len(filepath) - 4:] == ".mkv" or str(filepath)[len(filepath) - 4:] == ".MP4": if str(filepath)[len(filepath) - 4:] == ".mp4" or str(filepath)[len(filepath) - 4:] == ".mkv" or str(filepath)[len(filepath) - 4:] == ".MP4":
print("upscaling video") print( '\n\n==> Upscaling video' )
self.video_scaling(fsrpath, filepath, quality_mode, quality_setting, output_path, threads) self.video_scaling(fsrpath, filepath, quality_mode, quality_setting, output_path, threads)
elif str(filepath)[len(filepath) - 4:] == ".JPG" or str(filepath)[len(filepath) - 4:] == ".png" or str(filepath)[len(filepath) - 4:] == ".jpg" or str(filepath)[len(filepath) - 5:] == ".jpeg": elif str(filepath)[len(filepath) - 4:] == ".JPG" or str(filepath)[len(filepath) - 4:] == ".png" or str(filepath)[len(filepath) - 4:] == ".jpg" or str(filepath)[len(filepath) - 5:] == ".jpeg":
print("upscaling image") print( '\n==>upscaling image' )
self.photo_scaling(fsrpath, filepath, quality_mode, quality_setting, output_path) self.photo_scaling(fsrpath, filepath, quality_mode, quality_setting, output_path)
else: else:
print("not supported") print("not supported")
@@ -79,8 +79,6 @@ class Handler:
else: else:
print("OS CURRENTLY UNSUPPORTED!") print("OS CURRENTLY UNSUPPORTED!")
return False return False
os.system(self.command)
print("photo upscaled")
else: else:
if self.os_type == "linux": if self.os_type == "linux":
self.command = f"wine {fsrpath} -Scale {quality_setting} {quality_setting} {self.filepath} {output_path}" self.command = f"wine {fsrpath} -Scale {quality_setting} {quality_setting} {self.filepath} {output_path}"
@@ -89,24 +87,30 @@ class Handler:
else: else:
print("OS CURRENTLY UNSUPPORTED!") print("OS CURRENTLY UNSUPPORTED!")
return False return False
os.system(self.command)
print("photo upscaled") os.system(self.command)
print( '\n\n==>Photo upscaled' );
def video_scaling(self, fsrpath, filepath, quality_mode, quality_setting, output_path, threads): def video_scaling(self, fsrpath, filepath, quality_mode, quality_setting, output_path, threads):
# DO NOT CALL THIS! Use Handler().handler() instead! # DO NOT CALL THIS! Use Handler().handler() instead!
self.videometa = ffmpeg.probe(str(filepath))["streams"].pop(0) self.videometa = ffmpeg.probe(str(filepath))["streams"].pop(0)
# Retrieving Video metadata # Retrieving Video metadata
self.duration = self.videometa.get("duration") self.duration = self.videometa.get( 'duration' )
self.frames = self.videometa.get("nb_frames") self.frames = self.videometa.get( 'nb_frames' )
try: try:
self.framerate = round(float(self.frames) / float(self.duration), 1) self.framerate = round(float(self.frames) / float(self.duration), 1)
except TypeError: except TypeError:
self.infos = str(self.videometa.get("r_frame_rate")) self.infos = str( self.videometa.get("r_frame_rate") )
print( '\n\n=> using fallback method to get framerate' )
self.framerate = float(self.infos[:len(self.infos) - 2]) self.framerate = float(self.infos[:len(self.infos) - 2])
print( '\n\nframe rate is: ', self.framerate, '\n\n' ) print( '==> Video duration is: ', self.duration, 's' )
print( '\n\nRunning with ', threads, ' threads\n\n' ) print( '==> Framecount is: ', self.duration, ' frames' )
print( '==> Frame rate is: ', self.framerate, ' FPS' )
print( '==> Running with ', threads, ' threads\n\n' )
time.sleep( 2 );
# Splitting video into frames # Splitting video into frames
try: try:
@@ -118,7 +122,7 @@ class Handler:
except FileExistsError: except FileExistsError:
pass pass
print("created dir") print( '\n==> Created directory' )
if self.os_type == "linux": if self.os_type == "linux":
self.command = f"ffmpeg -i {str(self.filepath)} {self.tmppath}ex%08d.png" self.command = f"ffmpeg -i {str(self.filepath)} {self.tmppath}ex%08d.png"
@@ -129,7 +133,7 @@ class Handler:
return False return False
os.system( self.command ) os.system( self.command )
print( 'video split' ) print( '\n==> Video split ' )
# Locate Images and assemble FSR-Command # Locate Images and assemble FSR-Command
self.file_list = [] self.file_list = []
@@ -165,7 +169,7 @@ class Handler:
if ( threads > multiprocessing.cpu_count() ): if ( threads > multiprocessing.cpu_count() ):
self.threads = multiprocessing.cpu_count(); self.threads = multiprocessing.cpu_count();
print( f'\n\nUsing { self.threads } threads\n\n' ); print( f'\n\n==>Using { self.threads } threads <==\n\n' );
time.sleep( 2 ); time.sleep( 2 );
@@ -188,7 +192,7 @@ class Handler:
# get Video's audio # get Video's audio
print( 'Finished Upscaling individual images. \n\n\nRetrieving Video audio to append' ) print( '\n\n==>Finished Upscaling individual images. \n==>Retrieving Video audio to append\n\n' )
time.sleep( 2 ); time.sleep( 2 );
try: try:
os.remove(f"{self.tmppath}audio.aac") os.remove(f"{self.tmppath}audio.aac")
@@ -205,7 +209,7 @@ class Handler:
os.system( self.command ) os.system( self.command )
# reassemble Video # reassemble Video
print( 'Reassembling Video... with framerate @', self.framerate ) print( '\n\n==>Reassembling Video... with framerate @', self.framerate, '\n\n' )
if self.os_type == 'linux': if self.os_type == 'linux':
self.command = f'ffmpeg -framerate {self.framerate} -i {self.tmppath}sc/ig%08d.png {output_path} -i {self.tmppath}audio.aac' self.command = f'ffmpeg -framerate {self.framerate} -i {self.tmppath}sc/ig%08d.png {output_path} -i {self.tmppath}audio.aac'
elif self.os_type == 'win32': elif self.os_type == 'win32':