From b194c73963ecd8c17e19cbc75a27dbacdaf074f4 Mon Sep 17 00:00:00 2001 From: janis Date: Mon, 22 May 2023 16:43:50 +0200 Subject: [PATCH] add nearestneighbour upscaling --- bin/__pycache__/handler.cpython-311.pyc | Bin 29257 -> 32788 bytes bin/handler.py | 75 ++++++++++++++++++++++-- imagevideoupscaler-cli.py | 4 +- 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/bin/__pycache__/handler.cpython-311.pyc b/bin/__pycache__/handler.cpython-311.pyc index 3f4be44e17552db27f167fa4abc6c89fa01dbfd7..4ba92ede3778a707c7a838a735a9c0a0b8d363ef 100644 GIT binary patch delta 2832 zcmb7_YfK#16@c%ZWf%4Zi`iv)Ev(r9#^w=<9a_Wk2$;u$G3I6LLNI2=cwpJZvy1Jn z$99{S994}U2RXDg4RLG7Zc^3JdO)mXytJOr&x%i+fCnwVV4~B~vk3qmuB<>O5a*=&dHdu5PLCtJFm+C}T`tbFhxY>P-D9y10(^ zrzm{cL(b99K87@a*o|mI?1RHQ+v$+9yz_6yf+I{*o~v2gnVd{JF8YNYF%*`3pzJ9bBPWs%X=2|PPIgsD;^eh>DcvGVpF>71-&`R+xSd=+jZ`o3I5RPswY(gR>)-brSzn+Ig%5Y-|23X*(wEac-WfOj-J#H9t8u zR0mhKIYu(o)YtWVe#FX}j(g%6$Y=4>*2eJ#t2x^?jdN`p2M?Qb*q3{$?KSFwllj^3 zC!GbV_q{}8;A(84BQW0RF_Y=_7sHhXCp5H=T=j0Fku8nQP17`vIYXdh@&8{Awp2}B z-=UrVoP0Ej9y_v5<=l#L7X~qEGR|t+eKdRi{Wpy zkGKcs=LE^!FNA{r`LGxalyg!e8!mYXyzkrjY$VTQ@_HNHLvx|Y3BMSaa_!aYt3Ad1nbk1(x&we3)0oSiu17Xnk^6G`1%FeFu>>v6bz#c9+t0 zu=Z5drOXC-A(_f@V8cR5DkkYTd-MylLLeMUXYTH&4hdD#AWZb+)3|c3$D!-aH5RTE zR!8dwquImkyx8%;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ym2OFg2J>V}R= z=Eq7yeP_8SR7Q}S)>_su;WaYLMp3wdST+hLEAFz{7J5sr3$YH-gfPL;s%FwH+^%{g zE$E{jeO^3jrgl^^=yE&TU4bCC1^!sqoBDW(dHpfcBivp;BhHc1w8T(QLqwkkD>8(s zdZ)PPNU$OiV;F~uwm_Ab)5c{&qd^aUW@o^t!9%3*yJ3LHpw(!l_MEXgGo5Ef$*%mw z3O*g8Ml+3Rn_O_cRR>=+Rlu-GL9|e;R)gQB!Wk5`mBXw_o?+rs9n5Y#4s%?@ZH9$L z4O!Z;mM}cwnSR|;@w5Ov9^G!qr`x7q`}w6IYbWu*#ELc+<~mkSIwCcO1%_GGN}b57-Pih(=ON4Xga96^f{Qz~>!w z4f*X{fa*MU*G3G+n&5=F3Ed0Wwb%`~!)P5ts1T^~za 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' )