From a0460a8113d5a1622ea2ed1a27387f158593e696 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Tue, 28 Mar 2023 17:10:45 +0200 Subject: [PATCH] sharpening --- bin/__pycache__/handler.cpython-310.pyc | Bin 7086 -> 7123 bytes bin/handler.py | 50 +++++++++++++++--------- fsrimagevideoupscaler-cli.py | 35 +++++++++++------ 3 files changed, 55 insertions(+), 30 deletions(-) diff --git a/bin/__pycache__/handler.cpython-310.pyc b/bin/__pycache__/handler.cpython-310.pyc index 991859e675bbbb84554d09ab103bf746d89e2888..51db6da3bd5b94126165d41c2be48614fadb191a 100644 GIT binary patch delta 1896 zcma)7O>7%Q6rQ(U?|Rqkwc|MPPnyxcASJZf|cge+j-x6 z?|W~@~F=2;d8zmg8!GDNNlC z@KL!3e&yqG+#fGXwrBMugypDA+5kruNRtUd$wyL>&{SEn{@nRm{uw~yA1mWA-M%?z ztrn}L>e8NSFU(cY;187>aBAnYI&oZ%filGMxUT;0L94PgGVya`r@p~dtBX&{y2joJIkK5LNaR2m^TmJ>O4 z7X#|W))QW!8)QK&5X28DCrH!sH+)pV4|)xgsv>C>G!$}T@$&yDKFhQ%XbPxf58~8p z1GLgM&XH?i*CFP2O_XD_I`2OA7H7y1b3kb!X0~jTN?!k_HzN;^&1m;PW*vJufn0HH&Pu#hUqbuX!wXvb|ZW|5wCyPjEgpXhtUCyj<=#eq3usGM1IAQXk-Ib z)3zLOC$@yUN-9mPH>KQa- z@s;Foa8xMi6!04VD%qW#5atzxOw2kh>?r}=0?r6{UBDXx6akG(5Usq5vWm4e$GXIQ zsi{}<(S_Q|%3PHe4wdI+du{$@D<}dz5dQ_%G{SGV>`lIyn#H?%H`P-&K!*gbC7%Q6rR~#@7nA2CQj1$Cr!HvX~E>DAP5Euv??hjsYE4O(WDhMc4kvMcGh8b zBNH@>4-tnRDk4TmMHN+Y;eaY6FmOVME4NBqP!N?+B`Os-aO1#%H|w7!R2CdqYd*i3 z_vU*)^LF<8?5A0?8jI-&o{P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*>-hbHkHzcMt7U;Z1h CE0Jsf diff --git a/bin/handler.py b/bin/handler.py index 05627c2..ae79cd3 100644 --- a/bin/handler.py +++ b/bin/handler.py @@ -32,7 +32,7 @@ class Handler: self.tmppath = "" self.videometa = {} - def handler(self, fsrpath, filepath, quality_mode, quality_setting, output_path, threads=4): + def handler(self, fsrpath, filepath, quality_mode, quality_setting, output_path, sharpening, scaling, threads=4 ): # Function to be called when using this class as this function automatically determines if file is video or image print( '\n\nFSRImageVideoUpscalerFrontend - V1.1.0\n\nCopyright 2023 FSRImageVideoUpscalerFrontend contributors\n\n\n\n' ); @@ -61,7 +61,7 @@ class Handler: # 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(fsrpath, filepath, quality_mode, quality_setting, output_path, threads) + self.video_scaling(fsrpath, filepath, quality_mode, quality_setting, output_path, threads, sharpening, scaling) 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(fsrpath, filepath, quality_mode, quality_setting, output_path) @@ -91,7 +91,7 @@ class Handler: 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, sharpening, scaling ): # DO NOT CALL THIS! Use Handler().handler() instead! # Splitting video into frames @@ -185,7 +185,7 @@ class Handler: if ( i == self.threads - 1 ): for element in self.file_list: self.files += element; - self.command_list.append( ( quality_mode, self.files, fsrpath, quality_setting, i, self.maxlength, self.os_type ) ) + self.command_list.append( ( quality_mode, self.files, fsrpath, quality_setting, i, self.maxlength, self.os_type, sharpening, scaling ) ) self.pool = multiprocessing.Pool( self.threads ) self.pool.starmap( upscalerEngine, self.command_list ); @@ -221,10 +221,9 @@ class Handler: return False os.system( self.command ) - print( '\n\n---------------------------------------------------------------------------------\n\nDONE \n\nFSRImageVideoUpscalerFrontend V1.1.0\n\nCopyright 2023 FSRImageVideoUpscalerFrontend contributors\nThis application comes with absolutely no warranty to the extent permitted by applicable law\n\n' ) -def upscalerEngine ( quality_mode, files, fsrpath, quality_setting, number, maxlength, os_type ): +def upscalerEngine ( quality_mode, files, fsrpath, quality_setting, number, maxlength, os_type, sharpening, scaling ): files = files; # Refactoring of commands that are longer than 32K characters fileout = []; @@ -274,23 +273,36 @@ def upscalerEngine ( quality_mode, files, fsrpath, quality_setting, number, max while len( fileout ) > 0: files_handle = fileout.pop(0) - if quality_mode == 'default': + if ( not scaling ): + if quality_mode == 'default': + if os_type == 'linux': + command_us = f'wine {fsrpath} -QualityMode {quality_setting} {files_handle}' + elif os_type == 'win32': + command_us = f'FidelityFX_CLI -QualityMode {quality_setting} {files_handle}' + else: + print( 'OS CURRENTLY UNSUPPORTED!' ) + return False + else: + if os_type == 'linux': + command_us = f'wine {fsrpath} -Scale {quality_setting} {quality_setting} {files_handle}' + elif os_type == 'win32': + command_us = f'FidelityFX_CLI -Scale {quality_setting} {quality_setting} {files_handle}' + else: + print( 'OS CURRENTLY UNSUPPORTED!' ) + return False + sub = subprocess.Popen( command_us, shell=True ); + sub.wait(); + if sharpening != '': + print( '\n\n\n PROCESS: ', number, '\nRunning sharpening filter\n\n\n' ); if os_type == 'linux': - command_us = f'wine {fsrpath} -QualityMode {quality_setting} {files_handle}' + command_sharpening = f'wine {fsrpath} -Mode CAS -Sharpness {sharpening} {files_handle}' elif os_type == 'win32': - command_us = f'FidelityFX_CLI -QualityMode {quality_setting} {files_handle}' + command_sharpening = f'FidelityFX_CLI -Mode CAS -Sharpness {sharpening} {files_handle}' else: print( 'OS CURRENTLY UNSUPPORTED!' ) return False - else: - if os_type == "linux": - command_us = f'wine {fsrpath} -Scale {quality_setting} {quality_setting} {files_handle}' - elif os_type == "win32": - command_us = f'FidelityFX_CLI -Scale {quality_setting} {quality_setting} {files_handle}' - else: - print( 'OS CURRENTLY UNSUPPORTED!' ) - return False - sub = subprocess.Popen( command_us, shell=True ); - sub.wait(); + sub2 = subprocess.Popen( command_sharpening, shell=True ); + sub2.wait() + time.sleep(3) print( '\n\nCompleted executing Job\n\n\n PROCESS: ', number, '\n\n\n' ); diff --git a/fsrimagevideoupscaler-cli.py b/fsrimagevideoupscaler-cli.py index 8d84a54..ab8153f 100644 --- a/fsrimagevideoupscaler-cli.py +++ b/fsrimagevideoupscaler-cli.py @@ -17,6 +17,8 @@ if __name__ == '__main__': ap.add_argument( 'inputfile', help='File path for the video / image to be upscaled' ) ap.add_argument( 'outputfile', help='File path for the video / image that was upscaled' ) ap.add_argument( '-s', '--scalefactor', help='Scale factor for the video / image' ) + ap.add_argument( '-S', '--sharpening', help='Sharpening factor (between 0 and 1 wheras 0 means no sharpening, 1 the most sharpening. Recommendation: Do not exceed 0.25, as it often looks bad)' ) + ap.add_argument( '-N', '--noscaling', help='Do not upscale video, instead only sharpen. Sharpening argument required!', 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)' ) args = ap.parse_args() @@ -33,17 +35,28 @@ if __name__ == '__main__': print( '\nRefusing to Upscale video. Please delete the file or specify another filepath!') go = False + if ( args.noscaling ): + if ( float( args.sharpening ) > 0 ): + go = True; + else: + go = False; + if ( go ): - if ( args.scalefactor ): - if ( args.scalefactor[ len(args.scalefactor) -1: ] == 'x' ): - if ( args.threads != None ): - handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile, threads=int( args.threads ) ); - else: - handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile ); - else: - raise NameError( 'Argument Scale does require to be of form 2x! (it has to end in x)' ) + if ( float( args.sharpening ) > 1 ): + print( 'Invalid argument for Sharpening, please specify value between 0 and 1!' ) else: - if ( args.threads != None ): - handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile, threads=int( args.threads ) ); + if ( args.scalefactor ): + if ( args.scalefactor[ len(args.scalefactor) -1: ] == 'x' ): + if ( args.threads != None ): + handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile, args.sharpening, args.noscaling, threads=int( args.threads ) ); + else: + handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile, args.sharpening, args.noscaling ); + else: + raise NameError( 'Argument Scale does require to be of form 2x! (it has to end in x)' ) else: - handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile ) + if ( args.threads != None ): + handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile, args.sharpening, args.noscaling, threads=int( args.threads ) ); + else: + handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile, args.sharpening, args.noscaling ) + print( '\n\n---------------------------------------------------------------------------------\n\nDONE \n\nFSRImageVideoUpscalerFrontend V1.1.0\n\nCopyright 2023 FSRImageVideoUpscalerFrontend contributors\nThis application comes with absolutely no warranty to the extent permitted by applicable law\n\n' ) +