mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-02-22 15:39:08 +00:00
2.10.0 added anime4k support
This commit is contained in:
parent
969cfe5c0d
commit
47471352ba
90
bin/anime4k.py
Normal file
90
bin/anime4k.py
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Name: Anime4K Driver
|
||||||
|
Author: K4YT3X
|
||||||
|
Date Created: August 15, 2019
|
||||||
|
Last Modified: August 15, 2019
|
||||||
|
|
||||||
|
Description: This class is a high-level wrapper
|
||||||
|
for Anime4k.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# built-in imports
|
||||||
|
import subprocess
|
||||||
|
import threading
|
||||||
|
|
||||||
|
# third-party imports
|
||||||
|
from avalon_framework import Avalon
|
||||||
|
|
||||||
|
|
||||||
|
class Anime4k:
|
||||||
|
"""This class communicates with Anime4K engine
|
||||||
|
|
||||||
|
An object will be created for this class, containing information
|
||||||
|
about the binary address and the processing method. When being called
|
||||||
|
by the main program, other detailed information will be passed to
|
||||||
|
the upscale function.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, waifu2x_settings):
|
||||||
|
self.waifu2x_settings = waifu2x_settings
|
||||||
|
self.print_lock = threading.Lock()
|
||||||
|
|
||||||
|
def upscale(self, input_directory, output_directory, scale_ratio, upscaler_exceptions, push_strength=None, push_grad_strength=None):
|
||||||
|
""" Anime4K wrapper
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
file_in {string} -- input file path
|
||||||
|
file_out {string} -- output file path
|
||||||
|
|
||||||
|
Keyword Arguments:
|
||||||
|
scale {int} -- scale ratio (default: {None})
|
||||||
|
push_strength {int} -- residual push strength (default: {None})
|
||||||
|
push_grad_strength {int} -- residual gradient push strength (default: {None})
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
subprocess.Popen.returncode -- command line return value of execution
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# return value is the sum of all execution return codes
|
||||||
|
return_value = 0
|
||||||
|
|
||||||
|
# get a list lof all image files in input_directory
|
||||||
|
extracted_frame_files = [f for f in input_directory.iterdir() if str(f).lower().endswith('.png') or str(f).lower().endswith('.jpg')]
|
||||||
|
|
||||||
|
# upscale each image in input_directory
|
||||||
|
for image in extracted_frame_files:
|
||||||
|
|
||||||
|
execute = [
|
||||||
|
self.waifu2x_settings['java_path'],
|
||||||
|
'-jar',
|
||||||
|
self.waifu2x_settings['anime4k_path'],
|
||||||
|
str(image.absolute()),
|
||||||
|
str(output_directory / image.name),
|
||||||
|
str(scale_ratio)
|
||||||
|
]
|
||||||
|
|
||||||
|
# optional arguments
|
||||||
|
kwargs = [
|
||||||
|
'push_strength',
|
||||||
|
'push_grad_strength'
|
||||||
|
]
|
||||||
|
|
||||||
|
# if optional argument specified, append value to execution list
|
||||||
|
for arg in kwargs:
|
||||||
|
if locals()[arg] is not None:
|
||||||
|
execute.extend([locals([arg])])
|
||||||
|
|
||||||
|
Avalon.debug_info(f'Executing: {execute}')
|
||||||
|
return_value += subprocess.run(execute, check=True).returncode
|
||||||
|
|
||||||
|
# print thread exiting message
|
||||||
|
self.print_lock.acquire()
|
||||||
|
Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} exiting')
|
||||||
|
self.print_lock.release()
|
||||||
|
|
||||||
|
# return command execution return code
|
||||||
|
return return_value
|
||||||
|
except Exception as e:
|
||||||
|
upscaler_exceptions.append(e)
|
@ -4,7 +4,7 @@
|
|||||||
Name: Video2X FFmpeg Controller
|
Name: Video2X FFmpeg Controller
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: Feb 24, 2018
|
Date Created: Feb 24, 2018
|
||||||
Last Modified: August 3, 2019
|
Last Modified: August 15, 2019
|
||||||
|
|
||||||
Description: This class handles all FFmpeg related operations.
|
Description: This class handles all FFmpeg related operations.
|
||||||
"""
|
"""
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
Name: Video2X Upscaler
|
Name: Video2X Upscaler
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: December 10, 2018
|
Date Created: December 10, 2018
|
||||||
Last Modified: August 3, 2019
|
Last Modified: August 15, 2019
|
||||||
|
|
||||||
Dev: SAT3LL
|
Dev: SAT3LL
|
||||||
|
|
||||||
@ -15,6 +15,7 @@ Licensed under the GNU General Public License Version 3 (GNU GPL v3),
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
|
from anime4k import Anime4k
|
||||||
from exceptions import *
|
from exceptions import *
|
||||||
from ffmpeg import Ffmpeg
|
from ffmpeg import Ffmpeg
|
||||||
from image_cleaner import ImageCleaner
|
from image_cleaner import ImageCleaner
|
||||||
@ -156,7 +157,7 @@ class Upscaler:
|
|||||||
self.upscaler_exceptions = []
|
self.upscaler_exceptions = []
|
||||||
|
|
||||||
# initialize waifu2x driver
|
# initialize waifu2x driver
|
||||||
drivers = ['waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan']
|
drivers = ['waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan', 'anime4k']
|
||||||
if self.waifu2x_driver not in drivers:
|
if self.waifu2x_driver not in drivers:
|
||||||
raise UnrecognizedDriverError(f'Unrecognized waifu2x driver: {self.waifu2x_driver}')
|
raise UnrecognizedDriverError(f'Unrecognized waifu2x driver: {self.waifu2x_driver}')
|
||||||
|
|
||||||
@ -176,6 +177,8 @@ class Upscaler:
|
|||||||
self.progress_bar_exit_signal = True
|
self.progress_bar_exit_signal = True
|
||||||
progress_bar.join()
|
progress_bar.join()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# drivers that are to be multi-threaded by video2x
|
||||||
else:
|
else:
|
||||||
# create a container for all upscaler threads
|
# create a container for all upscaler threads
|
||||||
upscaler_threads = []
|
upscaler_threads = []
|
||||||
@ -247,6 +250,15 @@ class Upscaler:
|
|||||||
self.scale_ratio,
|
self.scale_ratio,
|
||||||
self.upscaler_exceptions))
|
self.upscaler_exceptions))
|
||||||
|
|
||||||
|
# if the driver being used is anime4k
|
||||||
|
elif self.waifu2x_driver == 'anime4k':
|
||||||
|
w2 = Anime4k(copy.deepcopy(self.waifu2x_settings))
|
||||||
|
thread = threading.Thread(target=w2.upscale,
|
||||||
|
args=(thread_info[0],
|
||||||
|
self.upscaled_frames,
|
||||||
|
self.scale_ratio,
|
||||||
|
self.upscaler_exceptions))
|
||||||
|
|
||||||
# create thread
|
# create thread
|
||||||
thread.name = thread_info[1]
|
thread.name = thread_info[1]
|
||||||
|
|
||||||
|
@ -51,6 +51,10 @@
|
|||||||
"g": 0,
|
"g": 0,
|
||||||
"j": "1:2:2"
|
"j": "1:2:2"
|
||||||
},
|
},
|
||||||
|
"anime4k": {
|
||||||
|
"anime4k_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\Anime4K_Java\\Anime4K.jar",
|
||||||
|
"java_path": "C:\\Program Files\\Java\\jdk-12.0.2\\bin\\java.exe"
|
||||||
|
},
|
||||||
"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",
|
||||||
"video_to_frames": {
|
"video_to_frames": {
|
||||||
|
@ -13,7 +13,7 @@ __ __ _ _ ___ __ __
|
|||||||
Name: Video2X Controller
|
Name: Video2X Controller
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: Feb 24, 2018
|
Date Created: Feb 24, 2018
|
||||||
Last Modified: August 7, 2019
|
Last Modified: August 15, 2019
|
||||||
|
|
||||||
Dev: BrianPetkovsek
|
Dev: BrianPetkovsek
|
||||||
Dev: SAT3LL
|
Dev: SAT3LL
|
||||||
@ -64,7 +64,7 @@ from avalon_framework import Avalon
|
|||||||
import GPUtil
|
import GPUtil
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
VERSION = '2.9.0'
|
VERSION = '2.10.0'
|
||||||
|
|
||||||
LEGAL_INFO = f'''Video2X Version: {VERSION}
|
LEGAL_INFO = f'''Video2X Version: {VERSION}
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
@ -104,7 +104,7 @@ def process_arguments():
|
|||||||
# upscaler options
|
# upscaler options
|
||||||
upscaler_options = parser.add_argument_group('Upscaler Options')
|
upscaler_options = parser.add_argument_group('Upscaler Options')
|
||||||
upscaler_options.add_argument('-m', '--method', help='upscaling method', action='store', default='gpu', choices=['cpu', 'gpu', 'cudnn'])
|
upscaler_options.add_argument('-m', '--method', help='upscaling method', action='store', default='gpu', choices=['cpu', 'gpu', 'cudnn'])
|
||||||
upscaler_options.add_argument('-d', '--driver', help='waifu2x driver', action='store', default='waifu2x_caffe', choices=['waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan'])
|
upscaler_options.add_argument('-d', '--driver', help='upscaling driver', action='store', default='waifu2x_caffe', choices=['waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan', 'anime4k'])
|
||||||
upscaler_options.add_argument('-y', '--model_dir', type=pathlib.Path, help='directory containing model JSON files', action='store')
|
upscaler_options.add_argument('-y', '--model_dir', type=pathlib.Path, help='directory containing model JSON files', action='store')
|
||||||
upscaler_options.add_argument('-t', '--threads', help='number of threads to use for upscaling', action='store', type=int, default=1)
|
upscaler_options.add_argument('-t', '--threads', help='number of threads to use for upscaling', action='store', type=int, default=1)
|
||||||
upscaler_options.add_argument('-c', '--config', type=pathlib.Path, help='video2x config file location', action='store', default=pathlib.Path(sys.argv[0]).parent.absolute() / 'video2x.json')
|
upscaler_options.add_argument('-c', '--config', type=pathlib.Path, help='video2x config file location', action='store', default=pathlib.Path(sys.argv[0]).parent.absolute() / 'video2x.json')
|
||||||
@ -225,6 +225,10 @@ def absolutify_paths(config):
|
|||||||
if not re.match('^[a-z]:', config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'], re.IGNORECASE):
|
if not re.match('^[a-z]:', config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'], re.IGNORECASE):
|
||||||
config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'] = current_directory / config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path']
|
config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'] = current_directory / config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path']
|
||||||
|
|
||||||
|
# check anime4k path
|
||||||
|
if not re.match('^[a-z]:', config['anime4k']['anime4k_path'], re.IGNORECASE):
|
||||||
|
config['anime4k']['anime4k_path'] = current_directory / config['anime4k']['anime4k_path']
|
||||||
|
|
||||||
# check ffmpeg path
|
# check ffmpeg path
|
||||||
if not re.match('^[a-z]:', config['ffmpeg']['ffmpeg_path'], re.IGNORECASE):
|
if not re.match('^[a-z]:', config['ffmpeg']['ffmpeg_path'], re.IGNORECASE):
|
||||||
config['ffmpeg']['ffmpeg_path'] = current_directory / config['ffmpeg']['ffmpeg_path']
|
config['ffmpeg']['ffmpeg_path'] = current_directory / config['ffmpeg']['ffmpeg_path']
|
||||||
@ -301,6 +305,12 @@ elif args.driver == 'waifu2x_ncnn_vulkan':
|
|||||||
Avalon.error('Specified waifu2x_ncnn_vulkan directory doesn\'t exist')
|
Avalon.error('Specified waifu2x_ncnn_vulkan directory doesn\'t exist')
|
||||||
Avalon.error('Please check the configuration file settings')
|
Avalon.error('Please check the configuration file settings')
|
||||||
raise FileNotFoundError(waifu2x_settings['waifu2x_ncnn_vulkan_path'])
|
raise FileNotFoundError(waifu2x_settings['waifu2x_ncnn_vulkan_path'])
|
||||||
|
elif args.driver == 'anime4k':
|
||||||
|
waifu2x_settings = config['anime4k']
|
||||||
|
if not pathlib.Path(waifu2x_settings['anime4k_path']).is_file():
|
||||||
|
Avalon.error('Specified anime4k directory doesn\'t exist')
|
||||||
|
Avalon.error('Please check the configuration file settings')
|
||||||
|
raise FileNotFoundError(waifu2x_settings['anime4k_path'])
|
||||||
|
|
||||||
# read FFmpeg configuration
|
# read FFmpeg configuration
|
||||||
ffmpeg_settings = config['ffmpeg']
|
ffmpeg_settings = config['ffmpeg']
|
||||||
|
Loading…
Reference in New Issue
Block a user