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

View File

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

View File

@@ -68,26 +68,6 @@ class Handler:
else:
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:
shutil.rmtree(self.tmppath)
except FileNotFoundError:
@@ -98,6 +78,27 @@ class Handler:
print( '==> ERROR: Temp path does not exist! <==' )
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' )
if self.os_type == 'linux':