From e3d1ff12285f46e5e47d69cffa0ea06ea7af9df9 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Sun, 4 Jun 2023 10:05:17 +0200 Subject: [PATCH] fix image upscaling --- bin/__pycache__/handler.cpython-311.pyc | Bin 10502 -> 10706 bytes bin/engines/fsr/fsr.py | 43 +++++++++++++++++++----- bin/engines/ss/ss.py | 7 ++-- bin/handler.py | 43 ++++++++++++------------ 4 files changed, 60 insertions(+), 33 deletions(-) diff --git a/bin/__pycache__/handler.cpython-311.pyc b/bin/__pycache__/handler.cpython-311.pyc index 49010b6a096f7b9247deab08d2a0ac163c7e3e2a..654578320f5f8eaf839fdcfe48a8cddcbe5f48a5 100644 GIT binary patch delta 3502 zcmds3O-vg{6rS<#+N|*(82`mKh8PS4=cg#NCeWb#0Qo5@YEsfD4q+W)0=BbWl!$EQ zMrx}Z+s+}CA|#|rlq#20T&ngGrAZaFRl7t;NjX&NA;+pzZKWz|rM_8v7cV$8Qg0o> z^X!{9Z@&5F&71e`s}DzPAKPqJ1T8sqmHX*aTf(68o0fVFQJuqr1UnrmwMmAYGDb<> zYsM~e#T%r<^~xYZlQnes5JuTZ6B4}Z1I>tcVV8_#GMqo{b1ZG+#?D zx!mN2Ifj+>k1_%MwJp~7me=13qi+L7f0ca%${0H|7=u+X+9}4vNW`LE)QJX>5ly0b z!3=D|f2m<$X++ESwvC=B+wl;&Zjs0a! zZP}aaIbKL}aR>R@y31}VT$m9uQ>!L^THw=Z^5eDyd1_t6KQDb$6T-SR1DOoJ zjjc;xvPNC8ZJF&@VLK$Y<1y=a#D*TSp?PMp{r1&6L(=d`X*4B`rI*=>6?Q^W{+_VT z_Y%u&bcKydZ1l0)`(9U}88&y%={wMl?zLMFbnEZ!#Z>nA4tmgikMH0f{r%k-m?9aMBuv73sWMJjiJ zD9}Ab%8jR2kZ%VuTR$+C<-l!c{z6X3rOGEow^n!o#9QbI)9|5Zg=u`mbUtJ{Z(Bb* z@*p6cI4hmYNEdU`rJ0pWZ!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}HDuob8SXe-FSKy5F zijj6k;ATS-WBx!0I{F=6PqdN8Jkjo`a8SjetXD`?EKy`9DQ^CeCq7$dGfHyC4UeP; z0}_iU-cmUcSM%U*KRIopb2oJFVj(61AR3$|#78>WOUoPa^GGBC_>Fb7#1QZs)#mgm>6e^dRpE z4=%hLenx2vSE6zEvbk`6TFp!@o7n}GrPB-#0=LRt9u|Qf!*?fZLV-nu+4<+uKHAOy zhz`1z>oONgub`t-%JgKqz+Z_4W>Z$}NwRFqq76j~1w2$r zPnH5c6tu@m<-w8!)r@;^ET>GSS?9%!lAb!V`W71jQ{gJyhRfvFaQw5;FO9cycP=h< z9=Ol%#oW@0g;U3S)Uxm-_KWHCNdSN4@3)Y<7F)mDaJP}7^!xj}$=z=MfYb1O9R+zW z(mNO=_k;a=5Bm)dd=%u5$=+je@>9Hj@A0T%F+x%9+A)+OODWsXPQy|U9ootNZt3ah zfF&5-XNII%7Yh6|mtJ1@WMU{1@GqR?L#>g%q{+WR^x_DWOtmYdEG#3`lvp7fNd9%J ze;kVrvw&E(p3USs^K9yDdf5P7Hi(wj(ISse<<4a$@?)%!W^9iJE^XRm<}BNXxFHn7 zC=Q_6md;INa_J+Pg31o@_O=1q#dB>wdT!x^Hks}}EK#7evHVNZ|ML>7mXCh{h}jMX 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' )