sharpening

This commit is contained in:
2023-03-28 17:10:45 +02:00
parent 182e3698b7
commit a0460a8113
3 changed files with 55 additions and 30 deletions

View File

@@ -32,7 +32,7 @@ class Handler:
self.tmppath = "" self.tmppath = ""
self.videometa = {} 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 # 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' ); print( '\n\nFSRImageVideoUpscalerFrontend - V1.1.0\n\nCopyright 2023 FSRImageVideoUpscalerFrontend contributors\n\n\n\n' );
@@ -61,7 +61,7 @@ class Handler:
# Determining filetype # Determining filetype
if str(filepath)[len(filepath) - 4:] == ".mp4" or str(filepath)[len(filepath) - 4:] == ".mkv" or str(filepath)[len(filepath) - 4:] == ".MP4": 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' ) 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": 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' ) print( '\n==>upscaling image' )
self.photo_scaling(fsrpath, filepath, quality_mode, quality_setting, output_path) self.photo_scaling(fsrpath, filepath, quality_mode, quality_setting, output_path)
@@ -91,7 +91,7 @@ class Handler:
os.system(self.command) os.system(self.command)
print( '\n\n==>Photo upscaled' ); 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! # DO NOT CALL THIS! Use Handler().handler() instead!
# Splitting video into frames # Splitting video into frames
@@ -185,7 +185,7 @@ class Handler:
if ( i == self.threads - 1 ): if ( i == self.threads - 1 ):
for element in self.file_list: for element in self.file_list:
self.files += element; 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 = multiprocessing.Pool( self.threads )
self.pool.starmap( upscalerEngine, self.command_list ); self.pool.starmap( upscalerEngine, self.command_list );
@@ -221,10 +221,9 @@ class Handler:
return False return False
os.system( self.command ) 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; files = files;
# Refactoring of commands that are longer than 32K characters # Refactoring of commands that are longer than 32K characters
fileout = []; fileout = [];
@@ -274,6 +273,7 @@ def upscalerEngine ( quality_mode, files, fsrpath, quality_setting, number, max
while len( fileout ) > 0: while len( fileout ) > 0:
files_handle = fileout.pop(0) files_handle = fileout.pop(0)
if ( not scaling ):
if quality_mode == 'default': if quality_mode == 'default':
if os_type == 'linux': if os_type == 'linux':
command_us = f'wine {fsrpath} -QualityMode {quality_setting} {files_handle}' command_us = f'wine {fsrpath} -QualityMode {quality_setting} {files_handle}'
@@ -283,14 +283,26 @@ def upscalerEngine ( quality_mode, files, fsrpath, quality_setting, number, max
print( 'OS CURRENTLY UNSUPPORTED!' ) print( 'OS CURRENTLY UNSUPPORTED!' )
return False return False
else: else:
if os_type == "linux": if os_type == 'linux':
command_us = f'wine {fsrpath} -Scale {quality_setting} {quality_setting} {files_handle}' command_us = f'wine {fsrpath} -Scale {quality_setting} {quality_setting} {files_handle}'
elif os_type == "win32": elif os_type == 'win32':
command_us = f'FidelityFX_CLI -Scale {quality_setting} {quality_setting} {files_handle}' command_us = f'FidelityFX_CLI -Scale {quality_setting} {quality_setting} {files_handle}'
else: else:
print( 'OS CURRENTLY UNSUPPORTED!' ) print( 'OS CURRENTLY UNSUPPORTED!' )
return False return False
sub = subprocess.Popen( command_us, shell=True ); sub = subprocess.Popen( command_us, shell=True );
sub.wait(); sub.wait();
if sharpening != '':
print( '\n\n\n PROCESS: ', number, '\nRunning sharpening filter\n\n\n' );
if os_type == 'linux':
command_sharpening = f'wine {fsrpath} -Mode CAS -Sharpness {sharpening} {files_handle}'
elif os_type == 'win32':
command_sharpening = f'FidelityFX_CLI -Mode CAS -Sharpness {sharpening} {files_handle}'
else:
print( 'OS CURRENTLY UNSUPPORTED!' )
return False
sub2 = subprocess.Popen( command_sharpening, shell=True );
sub2.wait()
time.sleep(3) time.sleep(3)
print( '\n\nCompleted executing Job\n\n\n PROCESS: ', number, '\n\n\n' ); print( '\n\nCompleted executing Job\n\n\n PROCESS: ', number, '\n\n\n' );

View File

@@ -17,6 +17,8 @@ if __name__ == '__main__':
ap.add_argument( 'inputfile', help='File path for the video / image to be upscaled' ) 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( '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', '--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)' ) 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() args = ap.parse_args()
@@ -33,17 +35,28 @@ if __name__ == '__main__':
print( '\nRefusing to Upscale video. Please delete the file or specify another filepath!') print( '\nRefusing to Upscale video. Please delete the file or specify another filepath!')
go = False go = False
if ( args.noscaling ):
if ( float( args.sharpening ) > 0 ):
go = True;
else:
go = False;
if ( go ): if ( go ):
if ( float( args.sharpening ) > 1 ):
print( 'Invalid argument for Sharpening, please specify value between 0 and 1!' )
else:
if ( args.scalefactor ): if ( args.scalefactor ):
if ( args.scalefactor[ len(args.scalefactor) -1: ] == 'x' ): if ( args.scalefactor[ len(args.scalefactor) -1: ] == 'x' ):
if ( args.threads != None ): if ( args.threads != None ):
handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile, threads=int( args.threads ) ); handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile, args.sharpening, args.noscaling, threads=int( args.threads ) );
else: else:
handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile ); handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile, args.sharpening, args.noscaling );
else: else:
raise NameError( 'Argument Scale does require to be of form 2x! (it has to end in x)' ) raise NameError( 'Argument Scale does require to be of form 2x! (it has to end in x)' )
else: else:
if ( args.threads != None ): if ( args.threads != None ):
handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile, threads=int( args.threads ) ); handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile, args.sharpening, args.noscaling, threads=int( args.threads ) );
else: else:
handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile ) 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' )