diff --git a/bin/__pycache__/handler.cpython-311.pyc b/bin/__pycache__/handler.cpython-311.pyc index 3f4be44..4ba92ed 100644 Binary files a/bin/__pycache__/handler.cpython-311.pyc and b/bin/__pycache__/handler.cpython-311.pyc differ diff --git a/bin/handler.py b/bin/handler.py index 1ca88b9..682ea74 100644 --- a/bin/handler.py +++ b/bin/handler.py @@ -132,8 +132,8 @@ class Handler: time.sleep( 2 ); - if ( scalerEngine == 'fsr' ): - self.fsrScaler( self.tmppath, filepath, threads, fsrpath, quality_setting + 'x', sharpening, scaling, filetype ) + if ( scalerEngine == 'fsr' or scalerEngine == 'NN' ): + self.fsrScaler( self.tmppath, filepath, threads, fsrpath, quality_setting + 'x', sharpening, scaling, filetype, scalerEngine ) elif ( scalerEngine == 'SS' ): if ( not useSpecialModeSS ): self.superScaler( self.tmppath, threads, quality_setting, self.os_type, model ) @@ -248,7 +248,7 @@ class Handler: specialScalerEngine( tmppath, t, quality_setting, model, self.os_type ) - def fsrScaler ( self, tmppath, filepath, threads, fsrpath, quality_setting, sharpening, scaling, filetype ): + def fsrScaler ( self, tmppath, filepath, threads, fsrpath, quality_setting, sharpening, scaling, filetype, mode ): # Locate Images and assemble FSR-Command self.file_list = [] self.filelist = os.listdir(tmppath) @@ -295,7 +295,9 @@ class Handler: self.threads = multiprocessing.cpu_count(); if ( not scaling ): + engines = { 'NN': 'NearestNeighbor', 'fsr':'FidelityFX Super Resolution' } print( f'\n\n==> Upscaling using { self.threads } threads <==\n\n' ); + print( f'\n\n==> Upscaling Engine is { engines[ mode ] } <==\n\n' ); time.sleep( 2 ); @@ -312,7 +314,10 @@ class Handler: self.command_list.append( ( self.files, fsrpath, quality_setting, i, self.maxlength, self.os_type ) ) self.pool = multiprocessing.Pool( self.threads ) - self.pool.starmap( upscalerEngine, self.command_list ); + if ( mode == 'NN' ): + self.pool.starmap( bilinearEngine, self.command_list ); + elif ( mode == 'fsr' ): + self.pool.starmap( upscalerEngine, self.command_list ); self.pool.close(); self.pool.join(); @@ -444,6 +449,68 @@ def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type print( '\n\nCompleted executing Job\n\n\n PROCESS: ', number, '\n\n\n' ); +def bilinearEngine ( files, fsrpath, quality_setting, number, maxlength, os_type ): + files = files; + # Refactoring of commands that are longer than 32K characters + fileout = []; + pos = 0; + if len( files ) > maxlength: + while files[maxlength - pos:maxlength - pos + 1] != ' ': + pos += 1 + file_processing = files[:maxlength - pos] + if file_processing[len(file_processing) - 14:len(file_processing) - 12] == 'ig': + pos += 5 + else: + pass + while files[maxlength - pos:maxlength - pos + 1] != ' ': + pos += 1 + fileout.append(files[:maxlength - pos]) + filesopt = files[maxlength - pos:] + posx = 0 + posy = maxlength + + # Command refactoring for commands that are longer than 64K characters + if len(filesopt) > maxlength: + while len(filesopt) > maxlength: + posx += maxlength - pos + posy += maxlength - pos + pos = 1 + while files[posy - pos:posy - pos + 1] != ' ': + pos += 1 + file_processing = files[posx:posy - pos] + if file_processing[len(file_processing) - 14:len(file_processing) - 12] == 'ig': + pos += 5 + else: + pass + while files[posy - pos:posy - pos + 1] != ' ': + pos += 1 + + file_processing = files[posx:posy - pos] + fileout.append(file_processing) + filesopt = files[posy - pos:] + fileout.append(filesopt) + else: + fileout.append(files[maxlength - pos:]) + else: + fileout.append(files) + + # Upscaling images + print( '\n\n\nUpscaling images... \n\n\n\n\n\n PROCESS: ', number, '\n\n\n' ) + + while len( fileout ) > 0: + files_handle = fileout.pop(0) + if os_type == 'linux': + command_us = f'wine {fsrpath} -Mode NearestNeighbor -Scale {quality_setting} {quality_setting} {files_handle}' + elif os_type == 'win32': + command_us = f'FidelityFX_CLI -Mode NearestNeighbor -Scale {quality_setting} {quality_setting} {files_handle}' + else: + print( 'OS CURRENTLY UNSUPPORTED!' ) + return False + sub = subprocess.Popen( command_us, shell=True ); + sub.wait(); + time.sleep(3) + print( '\n\nCompleted executing Job\n\n\n PROCESS: ', number, '\n\n\n' ); + ######################## # # Sharpening diff --git a/imagevideoupscaler-cli.py b/imagevideoupscaler-cli.py index e579b2d..8631a9d 100644 --- a/imagevideoupscaler-cli.py +++ b/imagevideoupscaler-cli.py @@ -24,7 +24,7 @@ if __name__ == '__main__': ap.add_argument( '-N', '--noscaling', help='Do not upscale video, instead only sharpen. Sharpening argument required!', action='store_true' ) ap.add_argument( '-t', '--threading', help='Use special threading mode with SS scaler (spawns 16 threads upscaling at one time)', action='store_true' ) ap.add_argument( '-T', '--threads', help='Thread count to use. Cannot exceed CPU thread count. Scaling non-linear (using 2 threads is not exactly 2x the speed of 1 thread). Scales well with FSR, barely with Real-ESRGAN, as it uses mostly the GPU to upscale' ) - ap.add_argument( '-E', '--engine', help='Upscaling engine. Can be fsr or SS (for Real-ESRGAN). FSR tends to be lower quality, but faster, Real-ESRGAN is meant for anime. Defaults to fsr' ) + ap.add_argument( '-E', '--engine', help='Upscaling engine. Can be fsr, NN (for NearestNeighbor) or SS (for Real-ESRGAN). FSR tends to be lower quality, but faster, NeirestNeighbour is super fast but very ugly, Real-ESRGAN is meant for anime and is super slow. Defaults to fsr' ) ap.add_argument( '-M', '--model', help='Only available if using Real-ESRGAN. Change the ML-Model used to upsample video, can be: realesr-animevideov3 | realesrgan-x4plus-anime , defaults to realesr-animevideov3' ) args = ap.parse_args() @@ -49,7 +49,7 @@ if __name__ == '__main__': go = False if ( args.engine != None ): - if ( args.engine == 'fsr' or args.engine == 'SS' ): + if ( args.engine == 'fsr' or args.engine == 'SS' or args.engine == 'NN' ): engine = args.engine; else: print( 'Invalid argument for engine' )