completely rewrite CLI & finish plugin support

This commit is contained in:
2023-05-24 20:57:06 +02:00
parent 10fc385730
commit db32279e6c
8 changed files with 242 additions and 245 deletions

View File

@@ -0,0 +1,15 @@
{
"abbr":"FSR",
"displayName":"FidelityFX_CLI",
"lastUsedFilePath":"sc",
"fileNameBeginning":"ig",
"cliModeOptions": {
"fsr":{ "displayName": "FidelityFX Super Resolution", "default": true },
"c":{ "displayName": "Cubic", "default": false },
"hqc":{ "displayName": "High Quality Cubic", "default": false }
},
"pluginCreator": "Janis Hutz",
"pluginCreatorLink": "https://janishutz.com",
"engineLink": "",
"supports": [ "upscaling", "sharpening" ]
}

View File

@@ -4,21 +4,37 @@ import time
import subprocess
import sys
class FSRScaler:
def __init__(self):
class Scaler:
def __init__( self ):
self.os_type = sys.platform
self.command = ""
self.tmppath = ""
self.command = ''
self.tmppath = ''
self.videometa = {}
def fsrScaler ( self, tmppath, filepath, threads, fsrpath, quality_setting, sharpening, scaling, filetype, mode ):
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}'
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
if ( scalefactor == 0 or scalefactor == None ):
self.isScaling = False
# Locate Images and assemble FSR-Command
self.file_list = []
self.filelist = os.listdir(tmppath)
self.filelist = os.listdir( tmppath )
self.filelist.pop(0)
self.filelist.sort()
self.number = 0
if sharpening != '' and sharpening != None:
if sharpening != 0 and sharpening != None:
for self.file in self.filelist:
self.number += 1
if ( self.os_type == 'win32' ):
@@ -57,10 +73,10 @@ class FSRScaler:
if ( threads > multiprocessing.cpu_count() ):
self.threads = multiprocessing.cpu_count();
if ( not scaling ):
if ( self.isScaling ):
engines = { 'c': 'Cubic', 'hqc': 'High Quality Cubic', 'fsr':'FidelityFX Super Resolution' }
print( f'\n\n==> Upscaling using { self.threads } threads <==\n\n' );
print( f'\n\n==> Upscaling Engine is { engines[ mode.lower() ] } <==\n\n' );
print( f'\n\n==> Upscaling Engine is FidelityFX_CLI with algorithm { engines[ mode.lower() ] } <==\n\n' );
time.sleep( 2 );
@@ -74,20 +90,20 @@ class FSRScaler:
if ( i == self.threads - 1 ):
for element in self.file_list:
self.files += element;
self.command_list.append( ( self.files, fsrpath, quality_setting, i, self.maxlength, self.os_type, mode ) )
self.command_list.append( ( self.files, scalefactor, i, self.maxlength, self.os_type, mode ) )
self.pool = multiprocessing.Pool( self.threads )
self.pool.starmap( upscalerEngine, self.command_list );
self.pool.close();
self.pool.join();
if sharpening != '' and sharpening != None:
if sharpening != 0 and sharpening != None:
print( f'\n\n\n==> Sharpening using { self.threads } threads <==\n\n' );
time.sleep( 2 );
self.pathSharpening = tmppath
if ( not scaling ):
if ( self.isScaling ):
if ( self.os_type == 'win32' ):
self.pathSharpening += 'up\\'
elif ( self.os_type == 'linux' ):
@@ -128,7 +144,7 @@ class FSRScaler:
if ( i == self.threads - 1 ):
for element in self.file_list:
self.files += element;
self.command_list.append( ( self.files, fsrpath, i, self.maxlength, self.os_type, sharpening, not sharpening ) )
self.command_list.append( ( self.files, i, self.maxlength, self.os_type, sharpening, not sharpening ) )
self.pool = multiprocessing.Pool( self.threads )
self.pool.starmap( sharpeningEngine, self.command_list );
@@ -137,7 +153,7 @@ class FSRScaler:
# Add return values
def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type, version ):
def upscalerEngine ( files, scalefactor, number, maxlength, os_type, version ):
scaler = 'FSR'
if ( version.upper() == 'HQC' ):
scaler = 'HighQualityCubic'
@@ -191,9 +207,9 @@ def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type
while len( fileout ) > 0:
files_handle = fileout.pop(0)
if os_type == 'linux':
command_us = f'wine {fsrpath} -Mode { scaler } -Scale {quality_setting} {quality_setting} {files_handle}'
command_us = f'wine ./bin/lib/FidelityFX_CLI.exe -Mode { scaler } -Scale {scalefactor}x {scalefactor}x {files_handle}'
elif os_type == 'win32':
command_us = f'FidelityFX_CLI -Mode { scaler } -Scale {quality_setting} {quality_setting} {files_handle}'
command_us = f'FidelityFX_CLI -Mode { scaler } -Scale {scalefactor}x {scalefactor}x {files_handle}'
else:
print( 'OS CURRENTLY UNSUPPORTED!' )
return False
@@ -209,7 +225,7 @@ def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type
#
#######################
def sharpeningEngine ( files, fsrpath, number, maxlength, os_type, sharpening, didUpscale ):
def sharpeningEngine ( files, number, maxlength, os_type, sharpening, didUpscale ):
files = files;
# Refactoring of commands that are longer than 32K characters
fileout = [];
@@ -265,7 +281,7 @@ def sharpeningEngine ( files, fsrpath, number, maxlength, os_type, sharpening, d
files_handle = fileout.pop(0)
print( '\n\n\n PROCESS: ', number, '\nRunning sharpening filter\n\n\n' );
if os_type == 'linux':
command_sharpening = f'wine {fsrpath} -Mode CAS -Sharpness {sharpening} {files_handle}'
command_sharpening = f'wine ./bin/lib/FidelityFX_CLI.exe -Mode CAS -Sharpness {sharpening} {files_handle}'
elif os_type == 'win32':
command_sharpening = f'FidelityFX_CLI -Mode CAS -Sharpness {sharpening} {files_handle}'
else:

View File

@@ -1,90 +0,0 @@
import os
import subprocess
import multiprocessing
import time
import sys
class SpecialScaler:
def __init__(self):
self.os_type = sys.platform
self.command = ""
self.tmppath = ""
self.videometa = {}
def superScaler ( self, tmppath, threads, quality_setting, os_platform, model ):
print( '\n\n==> Preparing to upscale videos <==\n\n==> You will see a lot of numbers flying by showing the progress of the upscaling of each individual image.\n==> This process might take a long time, depending on the length of the video.\n\n')
time.sleep( 2 );
try:
os.mkdir( f'{tmppath}sc' )
except FileExistsError:
pass
if ( os_platform == 'win32' ):
self.command = f'realesrgan-ncnn-vulkan -i {tmppath} -o {tmppath}sc -s {quality_setting} -j {threads}:{threads}:{threads} -n {model}'
elif ( os_platform == 'linux' ):
self.command = f'wine ./bin/lib/realesrgan-ncnn-vulkan.exe -i {tmppath} -o {tmppath}sc -s {quality_setting} -j {threads}:{threads}:{threads} -n {model}'
os.system( self.command );
def specialSuperScaler ( self, tmppath, threads, quality_setting, model ):
self.fileList = os.listdir( tmppath )
self.fileList.pop( 0 )
self.fileList.sort()
if ( threads > multiprocessing.cpu_count() * 2 ):
self.threads = multiprocessing.cpu_count() * 2;
else:
self.threads = threads
self.fileCount = len( self.fileList ) // self.threads
self.spareFiles = len( self.fileList ) % self.threads
self.cmdList = [];
for t in range( threads ):
try:
os.mkdir( f'{tmppath}{t}' )
except FileExistsError:
pass
self.base = t * self.fileCount;
if ( self.os_type == 'win32' ):
for j in range( self.fileCount ):
os.rename( f'{tmppath}{self.fileList[ self.base + j ] }', f'{tmppath}{ t }\\{self.fileList[ self.base + j ] }' )
elif ( self.os_type == 'linux' ):
for j in range( self.fileCount ):
os.rename( f'{tmppath}{self.fileList[ self.base + j ] }', f'{tmppath}{ t }/{self.fileList[ self.base + j ] }' )
self.cmdList.append( ( tmppath, t, quality_setting, model, self.os_type ) )
try:
os.mkdir( f'{tmppath}{self.threads + 1}' )
except FileExistsError:
pass
if ( self.os_type == 'win32' ):
for k in range( self.spareFiles ):
os.rename( f'{tmppath}{self.fileList[ self.threads * self.fileCount + k ] }', f'{tmppath}{ t }\\{self.fileList[ self.threads * self.fileCount + k ] }' )
elif ( self.os_type == 'linux' ):
for k in range( self.spareFiles ):
os.rename( f'{tmppath}{self.fileList[ self.threads * self.fileCount + k ] }', f'{tmppath}{ self.threads + 1 }/{self.fileList[ self.threads * self.fileCount + k ] }' )
try:
os.mkdir( f'{tmppath}sc' )
except FileExistsError:
pass
self.pool_ss = multiprocessing.Pool( self.threads )
self.pool_ss.starmap( specialScalerEngine, self.cmdList );
self.pool_ss.close();
self.pool_ss.join();
specialScalerEngine( tmppath, t, quality_setting, model, self.os_type )
def specialScalerEngine ( tmppath, tNumber, quality_setting, model, os_type ):
if ( os_type == 'win32' ):
command = f'realesrgan-ncnn-vulkan -i {tmppath}{tNumber} -o {tmppath}sc -s {quality_setting} -n {model}'
elif ( os_type == 'linux' ):
command = f'wine ./bin/lib/realesrgan-ncnn-vulkan.exe -i {tmppath}{tNumber} -o {tmppath}sc -s {quality_setting} -n {model}'
sub = subprocess.Popen( command, shell=True );
sub.wait();

View File

@@ -0,0 +1,14 @@
{
"abbr":"SS",
"displayName":"Real-ESGRAN",
"lastUsedFilePath":"sc",
"fileNameBeginning":"ig",
"cliModeOptions": {
"av3":{ "displayName": "realesr-animevideov3", "default": true },
"x4plus":{ "displayName": "realesrgan-x4plus-anime", "default": false }
},
"pluginCreator": "Janis Hutz",
"pluginCreatorLink": "https://janishutz.com",
"engineLink": "",
"supports": [ "upscaling" ]
}

38
bin/engines/ss/ss.py Normal file
View File

@@ -0,0 +1,38 @@
import os
import subprocess
import multiprocessing
import time
import sys
class Scaler:
def __init__(self):
self.os_type = sys.platform
self.command = ""
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 -Scale {scalefactor} {scalefactor} {input_path} {output_path} -n { 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 }'
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 ):
print( '\n\n==> Preparing to upscale videos <==\n\n==> You will see a lot of numbers flying by showing the progress of the upscaling of each individual image.\n==> This process might take a long time, depending on the length of the video.\n\n')
time.sleep( 2 );
try:
os.mkdir( f'{tmppath}sc' )
except FileExistsError:
pass
if ( self.os_type == 'win32' ):
self.command = f'realesrgan-ncnn-vulkan -i {tmppath} -o {tmppath}sc -s {scalefactor} -j {threads}:{threads}:{threads} -n {mode}'
elif ( self.os_type == 'linux' ):
self.command = f'wine ./bin/lib/realesrgan-ncnn-vulkan.exe -i {tmppath} -o {tmppath}sc -s {scalefactor} -j {threads}:{threads}:{threads} -n {mode}'
os.system( self.command );