moved upscaler optional parameters into function definition

This commit is contained in:
k4yt3x 2020-06-08 02:36:44 -04:00
parent 3f6a3addaa
commit f5eb6514e1
4 changed files with 70 additions and 48 deletions

View File

@ -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: June 7, 2020 Last Modified: June 8, 2020
Description: This file contains the Upscaler class. Each Description: This file contains the Upscaler class. Each
instance of the Upscaler class is an upscaler on an image or instance of the Upscaler class is an upscaler on an image or
@ -50,7 +50,7 @@ language.install()
_ = language.gettext _ = language.gettext
# version information # version information
UPSCALER_VERSION = '4.2.1' UPSCALER_VERSION = '4.2.2'
# these names are consistent for # these names are consistent for
# - driver selection in command line # - driver selection in command line
@ -73,23 +73,39 @@ class Upscaler:
ArgumentError -- if argument is not valid ArgumentError -- if argument is not valid
""" """
def __init__(self, input_path, output_path, driver_settings, ffmpeg_settings, gifski_settings): def __init__(
# mandatory arguments self,
input_path: pathlib.Path or list,
output_path: pathlib.Path,
driver_settings: dict,
ffmpeg_settings: dict,
gifski_settings: dict,
driver: str = 'waifu2x_caffe',
scale_ratio: float = None,
processes: int = 1,
video2x_cache_directory: pathlib.Path = pathlib.Path(tempfile.gettempdir()) / 'video2x',
extracted_frame_format: str = 'png',
image_output_extension: str = '.png',
video_output_extension: str = '.mp4',
preserve_frames: bool = False
):
# required parameters
self.input = input_path self.input = input_path
self.output = output_path self.output = output_path
self.driver_settings = driver_settings self.driver_settings = driver_settings
self.ffmpeg_settings = ffmpeg_settings self.ffmpeg_settings = ffmpeg_settings
self.gifski_settings = gifski_settings self.gifski_settings = gifski_settings
# optional arguments # optional parameters
self.driver = 'waifu2x_caffe' self.driver = driver
self.scale_ratio = None self.scale_ratio = scale_ratio
self.processes = 1 self.processes = processes
self.video2x_cache_directory = pathlib.Path(tempfile.gettempdir()) / 'video2x' self.video2x_cache_directory = video2x_cache_directory
self.extracted_frame_format = 'png' self.extracted_frame_format = extracted_frame_format
self.image_output_extension = '.png' self.image_output_extension = image_output_extension
self.video_output_extension = '.mp4' self.video_output_extension = video_output_extension
self.preserve_frames = False self.preserve_frames = preserve_frames
# other internal members and signals # other internal members and signals
self.running = False self.running = False

View File

@ -13,7 +13,7 @@ __ __ _ _ ___ __ __
Name: Video2X Controller Name: Video2X Controller
Creator: K4YT3X Creator: K4YT3X
Date Created: Feb 24, 2018 Date Created: Feb 24, 2018
Last Modified: June 7, 2020 Last Modified: June 8, 2020
Editor: BrianPetkovsek Editor: BrianPetkovsek
Last Modified: June 17, 2019 Last Modified: June 17, 2019
@ -81,7 +81,7 @@ language = gettext.translation(DOMAIN, LOCALE_DIRECTORY, [default_locale], fallb
language.install() language.install()
_ = language.gettext _ = language.gettext
CLI_VERSION = '4.1.0' CLI_VERSION = '4.1.1'
LEGAL_INFO = _('''Video2X CLI Version: {} LEGAL_INFO = _('''Video2X CLI Version: {}
Upscaler Version: {} Upscaler Version: {}
@ -236,21 +236,24 @@ try:
begin_time = time.time() begin_time = time.time()
# initialize upscaler object # initialize upscaler object
upscaler = Upscaler(input_path=video2x_args.input, upscaler = Upscaler(
# required parameters
input_path=video2x_args.input,
output_path=video2x_args.output, output_path=video2x_args.output,
driver_settings=driver_settings, driver_settings=driver_settings,
ffmpeg_settings=ffmpeg_settings, ffmpeg_settings=ffmpeg_settings,
gifski_settings=gifski_settings) gifski_settings=gifski_settings,
# set upscaler optional options # optional parameters
upscaler.driver = video2x_args.driver driver=video2x_args.driver,
upscaler.scale_ratio = video2x_args.ratio scale_ratio=video2x_args.ratio,
upscaler.processes = video2x_args.processes processes=video2x_args.processes,
upscaler.video2x_cache_directory = video2x_cache_directory video2x_cache_directory=video2x_cache_directory,
upscaler.extracted_frame_format = extracted_frame_format extracted_frame_format=extracted_frame_format,
upscaler.image_output_extension = image_output_extension image_output_extension=image_output_extension,
upscaler.video_output_extension = video_output_extension video_output_extension=video_output_extension,
upscaler.preserve_frames = preserve_frames preserve_frames=preserve_frames
)
# run upscaler # run upscaler
upscaler.run() upscaler.run()

View File

@ -4,7 +4,7 @@
Creator: Video2X GUI Creator: Video2X GUI
Author: K4YT3X Author: K4YT3X
Date Created: May 5, 2020 Date Created: May 5, 2020
Last Modified: June 7, 2020 Last Modified: June 8, 2020
""" """
# local imports # local imports
@ -34,7 +34,7 @@ from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
import magic import magic
GUI_VERSION = '2.7.0' GUI_VERSION = '2.7.1'
LEGAL_INFO = f'''Video2X GUI Version: {GUI_VERSION}\\ LEGAL_INFO = f'''Video2X GUI Version: {GUI_VERSION}\\
Upscaler Version: {UPSCALER_VERSION}\\ Upscaler Version: {UPSCALER_VERSION}\\
@ -1173,21 +1173,24 @@ It\'s also highly recommended for you to attach the [log file]({}) under the pro
# load driver settings for the current driver # load driver settings for the current driver
self.driver_settings = self.config[AVAILABLE_DRIVERS[self.driver_combo_box.currentText()]] self.driver_settings = self.config[AVAILABLE_DRIVERS[self.driver_combo_box.currentText()]]
self.upscaler = Upscaler(input_path=input_directory, self.upscaler = Upscaler(
# required parameters
input_path=input_directory,
output_path=output_directory, output_path=output_directory,
driver_settings=self.driver_settings, driver_settings=self.driver_settings,
ffmpeg_settings=self.ffmpeg_settings, ffmpeg_settings=self.ffmpeg_settings,
gifski_settings=self.gifski_settings) gifski_settings=self.gifski_settings,
# set optional options # optional parameters
self.upscaler.driver = AVAILABLE_DRIVERS[self.driver_combo_box.currentText()] driver=AVAILABLE_DRIVERS[self.driver_combo_box.currentText()],
self.upscaler.scale_ratio = self.scale_ratio_double_spin_box.value() scale_ratio=self.scale_ratio_double_spin_box.value(),
self.upscaler.processes = self.processes_spin_box.value() processes=self.processes_spin_box.value(),
self.upscaler.video2x_cache_directory = pathlib.Path(os.path.expandvars(self.cache_line_edit.text())) video2x_cache_directory=pathlib.Path(os.path.expandvars(self.cache_line_edit.text())),
self.upscaler.extracted_frame_format = self.config['video2x']['extracted_frame_format'].lower() extracted_frame_format=self.config['video2x']['extracted_frame_format'].lower(),
self.upscaler.image_output_extension = self.image_output_extension_line_edit.text() image_output_extension=self.image_output_extension_line_edit.text(),
self.upscaler.video_output_extension = self.video_output_extension_line_edit.text() video_output_extension=self.video_output_extension_line_edit.text(),
self.upscaler.preserve_frames = bool(self.preserve_frames_check_box.isChecked()) preserve_frames=bool(self.preserve_frames_check_box.isChecked())
)
# run upscaler # run upscaler
worker = UpscalerWorker(self.upscaler.run) worker = UpscalerWorker(self.upscaler.run)

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>673</width> <width>727</width>
<height>910</height> <height>908</height>
</rect> </rect>
</property> </property>
<property name="acceptDrops"> <property name="acceptDrops">
@ -2835,7 +2835,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>673</width> <width>727</width>
<height>21</height> <height>21</height>
</rect> </rect>
</property> </property>