fix image upscaling
This commit is contained in:
Binary file not shown.
@@ -11,16 +11,41 @@ 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 ):
|
||||||
|
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:
|
||||||
|
output = input_path
|
||||||
|
|
||||||
|
if ( scalefactor != 0 ):
|
||||||
if self.os_type == 'linux':
|
if self.os_type == 'linux':
|
||||||
self.command = f'wine ./bin/lib/FidelityFX_CLI.exe -Mode { mode } -Scale {scalefactor} {scalefactor} {input_path} {output_path}'
|
self.command = f'wine ./bin/lib/FidelityFX_CLI.exe -Mode { scaler } -Scale {scalefactor}x {scalefactor}x {input_path} {output}'
|
||||||
elif self.os_type == 'win32':
|
elif self.os_type == 'win32':
|
||||||
self.command = f'FidelityFX_CLI -Mode { mode } -Scale {scalefactor} {scalefactor} {input_path} {output_path}'
|
self.command = f'FidelityFX_CLI -Mode { scaler } -Scale {scalefactor}x {scalefactor}x {input_path} {output}'
|
||||||
else:
|
else:
|
||||||
print( 'OS CURRENTLY UNSUPPORTED!' )
|
print( 'OS CURRENTLY UNSUPPORTED!' )
|
||||||
return False
|
return False
|
||||||
|
|
||||||
os.system( self.command )
|
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' );
|
print( '\n\n==> Photo upscaled' );
|
||||||
|
|
||||||
def videoScaler ( self, tmppath, threads, scalefactor, sharpening, filetype, mode ):
|
def videoScaler ( self, tmppath, threads, scalefactor, sharpening, filetype, mode ):
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -68,26 +68,6 @@ class Handler:
|
|||||||
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:
|
||||||
@@ -98,6 +78,27 @@ class Handler:
|
|||||||
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' )
|
||||||
|
|
||||||
if self.os_type == 'linux':
|
if self.os_type == 'linux':
|
||||||
|
|||||||
Reference in New Issue
Block a user