sharpening
This commit is contained in:
Binary file not shown.
@@ -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' );
|
||||
|
||||
@@ -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' )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user