fix image upscaling

This commit is contained in:
2023-06-04 10:05:17 +02:00
parent bf2931085f
commit e3d1ff1228
4 changed files with 60 additions and 33 deletions

View File

@@ -11,17 +11,42 @@ class Scaler:
self.tmppath = '' self.tmppath = ''
self.videometa = {} self.videometa = {}
def singleScaler ( self, input_path, output_path, scalefactor, threads, mode ): def singleScaler ( self, input_path, output_path, scalefactor, sharpening, threads, mode, tmppath ):
if self.os_type == 'linux': scaler = 'FSR'
self.command = f'wine ./bin/lib/FidelityFX_CLI.exe -Mode { mode } -Scale {scalefactor} {scalefactor} {input_path} {output_path}' if ( mode.upper() == 'HQC' ):
elif self.os_type == 'win32': scaler = 'HighQualityCubic'
self.command = f'FidelityFX_CLI -Mode { mode } -Scale {scalefactor} {scalefactor} {input_path} {output_path}' 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: else:
print( 'OS CURRENTLY UNSUPPORTED!' ) output = input_path
return False
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 ): def videoScaler ( self, tmppath, threads, scalefactor, sharpening, filetype, mode ):
self.isScaling = True self.isScaling = True

View File

@@ -11,11 +11,12 @@ class Scaler:
self.tmppath = "" self.tmppath = ""
self.videometa = {} 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': 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': 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: else:
print( 'OS CURRENTLY UNSUPPORTED!' ) print( 'OS CURRENTLY UNSUPPORTED!' )
return False return False

View File

@@ -67,27 +67,7 @@ class Handler:
self.filepath += '\ ' self.filepath += '\ '
else: else:
self.filepath += self.letter 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: try:
shutil.rmtree(self.tmppath) shutil.rmtree(self.tmppath)
except FileNotFoundError: except FileNotFoundError:
@@ -97,6 +77,27 @@ class Handler:
except FileExistsError: except FileExistsError:
print( '==> ERROR: Temp path does not exist! <==' ) print( '==> ERROR: Temp path does not exist! <==' )
return False 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' ) print( '\n==> Created directory' )