not working yet with new scaler

This commit is contained in:
janis
2023-05-15 17:07:13 +02:00
parent 00988c524e
commit 69c08778fc
4 changed files with 50 additions and 55 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, sharpening, scaling, filetype, threads=4 ): def handler(self, fsrpath, filepath, quality_mode, quality_setting, output_path, sharpening, scaling, filetype, scalerEngine, 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, sharpening, scaling, filetype ) self.video_scaling( fsrpath, filepath, quality_mode, quality_setting, output_path, threads, sharpening, scaling, filetype, scalerEngine )
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, sharpening, scaling, filetype ): def video_scaling( self, fsrpath, filepath, quality_mode, quality_setting, output_path, threads, sharpening, scaling, filetype, scalerEngine ):
# DO NOT CALL THIS! Use Handler().handler() instead! # DO NOT CALL THIS! Use Handler().handler() instead!
# Splitting video into frames # Splitting video into frames
@@ -107,9 +107,9 @@ class Handler:
print( '\n==> Created directory' ) print( '\n==> Created directory' )
if self.os_type == "linux": if self.os_type == "linux":
self.command = f"ffmpeg -i {str(self.filepath)} {self.tmppath}ex%08d.{ filetype }" self.command = f"ffmpeg -i {str(self.filepath)} {self.tmppath}ig%08d.{ filetype }"
elif self.os_type == "win32": elif self.os_type == "win32":
self.command = f"ffmpeg -i {str(self.filepath)} \"{self.tmppath}ex%08d.{ filetype }\"" self.command = f"ffmpeg -i {str(self.filepath)} \"{self.tmppath}ig%08d.{ filetype }\""
else: else:
print("OS CURRENTLY UNSUPPORTED!") print("OS CURRENTLY UNSUPPORTED!")
return False return False
@@ -117,10 +117,24 @@ class Handler:
os.system( self.command ) os.system( self.command )
print( '\n==> Video split ' ) print( '\n==> Video split ' )
self.fsrScaler( self.tmppath, filepath, threads, quality_mode, fsrpath, quality_setting, sharpening, scaling )
if ( scalerEngine == 'fsr' ):
self.fsrScaler( self.tmppath, filepath, threads, quality_mode, fsrpath, quality_setting, sharpening, scaling, filetype )
elif ( scalerEngine == 'SS' ):
self.superScaler( self.tmppath, threads, quality_setting, self.os_type )
else:
raise Exception( 'ERROR upscaling. scalerEngine invalid' );
# get Video's audio # get Video's audio
print( '\n\n==>Finished Upscaling individual images. \n==>Retrieving Video audio to append\n\n' ) print( '\n\n==>Finished Upscaling individual images. \n==>Retrieving Video audio to append\n\n' )
try:
self.framerate = round(float(self.frames) / float(self.duration), 1)
except TypeError:
print( '\n\n=> using fallback method to get framerate' )
self.infos = str( self.videometa.get( 'r_frame_rate' ) )
self.framerate = float( self.infos[:len(self.infos) - 2] )
time.sleep( 2 ); time.sleep( 2 );
try: try:
os.remove(f"{self.tmppath}audio.aac") os.remove(f"{self.tmppath}audio.aac")
@@ -148,7 +162,16 @@ class Handler:
os.system( self.command ) os.system( self.command )
def fsrScaler ( self, tmppath, filepath, threads, quality_mode, fsrpath, quality_setting, sharpening, scaling ): def superScaler ( self, tmppath, threads, quality_setting, os_platform ):
print( tmppath );
if ( os_platform == 'win32' ):
self.command = f'realesrgan-ncnn-vulkan -i {tmppath} -o {tmppath}\\us -s {quality_setting} -j {threads}:{threads}:{threads}'
elif ( os_platform == 'linux' ):
self.command = f'wine ./bin/lib/realesrgan-ncnn-vulkan.exe -i {tmppath} -o {tmppath}/us -s {quality_setting} -j {threads}:{threads}:{threads}'
os.system( self.command );
def fsrScaler ( self, tmppath, filepath, threads, quality_mode, fsrpath, quality_setting, sharpening, scaling, filetype ):
# Locate Images and assemble FSR-Command # Locate Images and assemble FSR-Command
self.file_list = [] self.file_list = []
self.filelist = os.listdir(tmppath) self.filelist = os.listdir(tmppath)
@@ -158,9 +181,9 @@ class Handler:
for self.file in self.filelist: for self.file in self.filelist:
self.number += 1 self.number += 1
if ( self.os_type == 'win32' ): if ( self.os_type == 'win32' ):
self.file_list.append( f"{self.tmppath}{self.file} {self.tmppath}us\\ig{str(self.number).zfill(8)}.{ filetype } " ); self.file_list.append( f"{tmppath}{self.file} {tmppath}us\\ig{str(self.number).zfill(8)}.{ filetype } " );
else: else:
self.file_list.append( f"{self.tmppath}{self.file} {self.tmppath}us/ig{str(self.number).zfill(8)}.{ filetype } " ); self.file_list.append( f"{tmppath}{self.file} {tmppath}us/ig{str(self.number).zfill(8)}.{ filetype } " );
if ( self.os_type == 'win32' ): if ( self.os_type == 'win32' ):
self.maxlength = 8000 self.maxlength = 8000
@@ -189,7 +212,7 @@ class Handler:
time.sleep( 2 ); time.sleep( 2 );
try: try:
os.mkdir( f'{self.tmppath}us' ) os.mkdir( f'{tmppath}us' )
except FileExistsError: except FileExistsError:
pass pass
@@ -228,14 +251,14 @@ class Handler:
print( f'\n\n\n==> Sharpening using { self.threads } threads <==\n\n' ); print( f'\n\n\n==> Sharpening using { self.threads } threads <==\n\n' );
time.sleep( 2 ); time.sleep( 2 );
self.pathSharpening = self.tmppath self.pathSharpening = tmppath
if ( not scaling ): if ( not scaling ):
self.pathSharpening += 'us' self.pathSharpening += 'us'
time.sleep( 2 ); time.sleep( 2 );
try: try:
os.mkdir( f'{self.tmppath}sh' ) os.mkdir( f'{tmppath}sh' )
except FileExistsError: except FileExistsError:
pass pass
# Locate Images and assemble FSR-Command # Locate Images and assemble FSR-Command
@@ -247,9 +270,9 @@ class Handler:
for self.file in self.filelist: for self.file in self.filelist:
self.number += 1 self.number += 1
if ( self.os_type == 'win32' ): if ( self.os_type == 'win32' ):
self.file_list.append( f"{self.pathSharpening}\\{self.file} {self.tmppath}sh\\ig{str(self.number).zfill(8)}.{ filetype } " ); self.file_list.append( f"{self.pathSharpening}\\{self.file} {tmppath}sh\\ig{str(self.number).zfill(8)}.{ filetype } " );
else: else:
self.file_list.append( f"{self.pathSharpening}/{self.file} {self.tmppath}sh/ig{str(self.number).zfill(8)}.{ filetype } " ); self.file_list.append( f"{self.pathSharpening}/{self.file} {tmppath}sh/ig{str(self.number).zfill(8)}.{ filetype } " );
if ( self.os_type == 'win32' ): if ( self.os_type == 'win32' ):
self.maxlength = 8000 self.maxlength = 8000
@@ -275,43 +298,6 @@ class Handler:
self.pool.close(); self.pool.close();
self.pool.join(); self.pool.join();
# get Video's audio
print( '\n\n==>Finished Upscaling individual images. \n==>Retrieving Video audio to append\n\n' )
time.sleep( 2 );
try:
os.remove(f"{self.tmppath}audio.aac")
os.remove(f"{output_path}")
except FileNotFoundError:
pass
if self.os_type == 'linux':
self.command = f'ffmpeg -i {self.filepath} -vn -acodec copy {self.tmppath}audio.aac'
elif self.os_type == 'win32':
self.command = f'ffmpeg -i {self.filepath} -vn -acodec copy {self.tmppath}audio.aac'
else:
print( 'OS CURRENTLY UNSUPPORTED!' )
return False
os.system( self.command )
# reassemble Video
self.outputPath = self.tmppath
if ( sharpening != '' ):
self.outputPath += 'sh'
else:
self.outputPath += 'us'
print( '\n\n==> Reassembling Video... with framerate @', self.framerate, ' <==\n\n' )
if self.os_type == 'linux':
self.command = f'ffmpeg -framerate {self.framerate} -i {self.outputPath}/ig%08d.{ filetype } { output_path } -i {self.tmppath}audio.aac'
elif self.os_type == 'win32':
self.command = f'ffmpeg -framerate {self.framerate} -i \"{self.outputPath}\\ig%08d.{ filetype }\" { output_path } -i {self.tmppath}audio.aac'
else:
print( 'OS CURRENTLY UNSUPPORTED!' );
return False
os.system( self.command )
def upscalerEngine ( quality_mode, files, fsrpath, quality_setting, number, maxlength, os_type ): def upscalerEngine ( quality_mode, files, fsrpath, quality_setting, number, maxlength, os_type ):

Binary file not shown.

View File

@@ -23,6 +23,7 @@ if __name__ == '__main__':
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( '-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( '-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)' )
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 higher quality, but slower. Defaults to Real-ESRGAN' )
args = ap.parse_args() args = ap.parse_args()
handler = bin.handler.Handler() handler = bin.handler.Handler()
@@ -30,6 +31,7 @@ if __name__ == '__main__':
go = True; go = True;
go2 = True; go2 = True;
go3 = True; go3 = True;
engine = 'SS';
multiprocessing.freeze_support(); multiprocessing.freeze_support();
if ( os.path.exists( args.outputfile ) ): if ( os.path.exists( args.outputfile ) ):
@@ -40,6 +42,13 @@ 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.engine != None ):
if ( args.engine == 'fsr' or args.engine == 'SS' ):
engine = args.engine;
else:
print( 'Invalid argument for engine' )
go2 = False;
if ( args.noscaling ): if ( args.noscaling ):
if ( args.sharpening != None ): if ( args.sharpening != None ):
if ( float( args.sharpening ) > 0 ): if ( float( args.sharpening ) > 0 ):
@@ -69,15 +78,15 @@ if __name__ == '__main__':
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, args.sharpening, args.noscaling, filetype, threads=int( args.threads ) ); handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile, args.sharpening, args.noscaling, filetype, engine, threads=int( args.threads ) );
else: else:
handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile, args.sharpening, args.noscaling, filetype ); handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', args.scalefactor, args.outputfile, args.sharpening, args.noscaling, filetype, engine );
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, args.sharpening, args.noscaling, filetype, threads=int( args.threads ) ); handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile, args.sharpening, args.noscaling, filetype, engine, threads=int( args.threads ) );
else: else:
handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile, args.sharpening, args.noscaling, filetype ) handler.handler( 'bin/lib/FidelityFX_CLI.exe', args.inputfile, 'custom', '2x', args.outputfile, args.sharpening, args.noscaling, filetype, engine )
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' ) 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' )