diff --git a/bin/__pycache__/handler.cpython-311.pyc b/bin/__pycache__/handler.cpython-311.pyc index 49010b6..6545783 100644 Binary files a/bin/__pycache__/handler.cpython-311.pyc and b/bin/__pycache__/handler.cpython-311.pyc differ diff --git a/bin/engines/fsr/fsr.py b/bin/engines/fsr/fsr.py index c18f648..f7fc068 100644 --- a/bin/engines/fsr/fsr.py +++ b/bin/engines/fsr/fsr.py @@ -11,17 +11,42 @@ class Scaler: self.tmppath = '' self.videometa = {} - def singleScaler ( self, input_path, output_path, scalefactor, threads, mode ): - if self.os_type == 'linux': - self.command = f'wine ./bin/lib/FidelityFX_CLI.exe -Mode { mode } -Scale {scalefactor} {scalefactor} {input_path} {output_path}' - elif self.os_type == 'win32': - self.command = f'FidelityFX_CLI -Mode { mode } -Scale {scalefactor} {scalefactor} {input_path} {output_path}' + def singleScaler ( self, input_path, output_path, scalefactor, sharpening, threads, mode, tmppath ): + scaler = 'FSR' + if ( mode.upper() == 'HQC' ): + scaler = 'HighQualityCubic' + elif ( mode.upper() == 'C' ): + scaler = 'Cubic' + if ( sharpening == 0 ): + output = output_path + elif ( scalefactor != 0 and sharpening != 0 ): + output = tmppath + 'tmpImage.' + output_path.split( '.' )[ 1 ] else: - print( 'OS CURRENTLY UNSUPPORTED!' ) - return False + output = input_path + + if ( scalefactor != 0 ): + if self.os_type == 'linux': + self.command = f'wine ./bin/lib/FidelityFX_CLI.exe -Mode { scaler } -Scale {scalefactor}x {scalefactor}x {input_path} {output}' + elif self.os_type == 'win32': + self.command = f'FidelityFX_CLI -Mode { scaler } -Scale {scalefactor}x {scalefactor}x {input_path} {output}' + else: + print( 'OS CURRENTLY UNSUPPORTED!' ) + return False + + os.system( self.command ) + + if ( sharpening != 0 ): + if self.os_type == 'linux': + self.command = f'wine ./bin/lib/FidelityFX_CLI.exe -Mode CAS -Sharpness {sharpening} {output} {output_path}' + elif self.os_type == 'win32': + self.command = f'FidelityFX_CLI -Mode CAS -Sharpness {sharpening} {output} {output_path}' + else: + print( 'OS CURRENTLY UNSUPPORTED!' ) + return False + + os.system( self.command ) - os.system( self.command ) - print( '\n\n==>Photo upscaled' ); + print( '\n\n==> Photo upscaled' ); def videoScaler ( self, tmppath, threads, scalefactor, sharpening, filetype, mode ): self.isScaling = True diff --git a/bin/engines/ss/ss.py b/bin/engines/ss/ss.py index fe5d7f3..bf7db91 100644 --- a/bin/engines/ss/ss.py +++ b/bin/engines/ss/ss.py @@ -11,11 +11,12 @@ class Scaler: self.tmppath = "" self.videometa = {} - def singleScaler ( self, input_path, output_path, scalefactor, threads, mode ): + def singleScaler ( self, input_path, output_path, scalefactor, sharpening, threads, mode, tmppath ): + modes = { 'av3':'realesr-animevideov3', 'x4plus': 'realesrgan-x4plus-anime' } if self.os_type == 'linux': - self.command = f'wine ./bin/lib/FidelityFX_CLI.exe -Scale {scalefactor} {scalefactor} {input_path} {output_path} -n { mode }' + self.command = f'wine ./bin/lib/realesrgan-ncnn-vulkan.exe -i {input_path} -o {output_path} -s {scalefactor} -j {threads}:{threads}:{threads} -n { modes[ mode ] }' elif self.os_type == 'win32': - self.command = f'realesrgan-ncnn-vulkan -i {input_path} -o {output_path} -s {scalefactor} -j {threads}:{threads}:{threads} -n { mode }' + self.command = f'realesrgan-ncnn-vulkan -i {input_path} -o {output_path} -s {scalefactor} -j {threads}:{threads}:{threads} -n { modes[ mode ] }' else: print( 'OS CURRENTLY UNSUPPORTED!' ) return False diff --git a/bin/handler.py b/bin/handler.py index f2099f1..2b7c2f9 100755 --- a/bin/handler.py +++ b/bin/handler.py @@ -67,27 +67,7 @@ class Handler: self.filepath += '\ ' else: self.filepath += self.letter - - # Determining filetype - if str(filepath)[len(filepath) - 4:] == '.mp4' or str(filepath)[len(filepath) - 4:] == '.mkv' or str(filepath)[len(filepath) - 4:] == '.MP4': - print( '\n\n==> Upscaling video' ) - self.video_scaling( filepath, output_path, scalefactor, threads, sharpening, filetype, mode, engine ) - 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( '\n==>upscaling image' ) - self.photo_scaling( scalefactor, output_path, engine ) - else: - print('not supported') - return False - - def photo_scaling(self, scalefactor, output_path, engine, mode): - # DO NOT CALL THIS! Use Handler().handler() instead! - pass - - def video_scaling( self, input_path, output_path, scalefactor, threads, sharpening, filetype, mode, engine ): - self.engineSetting = json.load( open( 'bin/engines/' + engine + '/config.json' ) ) - # DO NOT CALL THIS! Use Handler().handler() instead! - - # Splitting video into frames + try: shutil.rmtree(self.tmppath) except FileNotFoundError: @@ -97,6 +77,27 @@ class Handler: except FileExistsError: print( '==> ERROR: Temp path does not exist! <==' ) return False + + # Determining filetype + if str(filepath)[len(filepath) - 4:] == '.mp4' or str(filepath)[len(filepath) - 4:] == '.mkv' or str(filepath)[len(filepath) - 4:] == '.MP4': + print( '\n\n==> Upscaling video' ) + self.video_scaling( filepath, output_path, scalefactor, threads, sharpening, filetype, mode, engine ) + 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( '\n==> Upscaling Image' ) + self.photo_scaling( filepath, output_path, scalefactor, sharpening, threads, engine, mode ) + else: + print('not supported') + return False + + def photo_scaling(self, input_path, output_path, scalefactor, sharpening, threads, engine, mode ): + # DO NOT CALL THIS! Use Handler().handler() instead! + importedModules[ engine ].singleScaler( input_path, output_path, scalefactor, sharpening, threads, mode, self.tmppath ); + + def video_scaling( self, input_path, output_path, scalefactor, threads, sharpening, filetype, mode, engine ): + self.engineSetting = json.load( open( 'bin/engines/' + engine + '/config.json' ) ) + # DO NOT CALL THIS! Use Handler().handler() instead! + + # Splitting video into frames print( '\n==> Created directory' )