update waifu2x_ncnn_vulkan wrapper for directory as input

add workaround for the double file extension
This commit is contained in:
sat3ll 2019-07-12 23:12:08 +01:00
parent 9429b04528
commit 40a4d3a602
3 changed files with 39 additions and 28 deletions

View File

@ -150,6 +150,14 @@ class Ffmpeg:
# read FFmpeg input options # read FFmpeg input options
execute.extend(self._read_configuration(phase='frames_to_video', section='input_options')) execute.extend(self._read_configuration(phase='frames_to_video', section='input_options'))
# WORKAROUND FOR WAIFU2X-NCNN-VULKAN
import re
import shutil
regex = re.compile(r'\.png\.png$')
for raw_frame in os.listdir(upscaled_frames):
shutil.move(os.path.join(upscaled_frames, raw_frame), os.path.join(upscaled_frames, regex.sub('.png', raw_frame)))
# END WORKAROUND
# append input frames path into command # append input frames path into command
execute.extend([ execute.extend([
'-i', '-i',

View File

@ -47,7 +47,9 @@
"scale-ratio": null, "scale-ratio": null,
"tile-size": 400, "tile-size": 400,
"model-path": null, "model-path": null,
"gpu": 0 "gpu": 0,
"load-proc-save_threads": null,
"verbose": null
}, },
"ffmpeg": { "ffmpeg": {
"ffmpeg_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\ffmpeg-latest-win64-static\\bin", "ffmpeg_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\ffmpeg-latest-win64-static\\bin",

View File

@ -67,37 +67,38 @@ class Waifu2xNcnnVulkan:
'scale-ratio': '-s', 'scale-ratio': '-s',
'tile-size': '-t', 'tile-size': '-t',
'model-path': '-m', 'model-path': '-m',
'gpu': '-g' 'gpu': '-g',
'load-proc-save_threads': '-j',
'verbose': '-v'
} }
for raw_frame in os.listdir(input_directory): execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']]
execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']] for key in self.waifu2x_settings.keys():
for key in self.waifu2x_settings.keys(): value = self.waifu2x_settings[key]
value = self.waifu2x_settings[key] if key == 'waifu2x_ncnn_vulkan_path':
if key == 'waifu2x_ncnn_vulkan_path': continue
continue elif key == 'input':
elif key == 'input': execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) execute.append(input_directory)
execute.append(os.path.join(input_directory, raw_frame)) elif key == 'output':
elif key == 'output': execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) execute.append(output_directory)
execute.append(os.path.join(output_directory, raw_frame)) elif key == 'scale-ratio':
elif key == 'scale-ratio': execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) # waifu2x_ncnn_vulkan does not accept an arbitrary scale ratio, max is 2
# waifu2x_ncnn_vulkan does not accept an arbitrary scale ratio, max is 2 if scale_ratio == 1:
if scale_ratio == 1: execute.append('1')
execute.append('1')
else:
execute.append('2')
# allow upper if cases to take precedence
elif value is None or value is False:
continue
else: else:
execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) execute.append('2')
execute.append(str(value)) # allow upper if cases to take precedence
elif value is None or value is False:
continue
else:
execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append(str(value))
Avalon.debug_info(f'Executing: {execute}') Avalon.debug_info(f'Executing: {execute}')
subprocess.run(execute, check=True, stderr=subprocess.DEVNULL) subprocess.run(execute, check=True, stderr=subprocess.DEVNULL)
# print thread exiting message # print thread exiting message
self.print_lock.acquire() self.print_lock.acquire()