Skip to content

Commit f5eb651

Browse files
committed
moved upscaler optional parameters into function definition
1 parent 3f6a3ad commit f5eb651

4 files changed

Lines changed: 72 additions & 50 deletions

File tree

src/upscaler.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Name: Video2X Upscaler
55
Author: K4YT3X
66
Date Created: December 10, 2018
7-
Last Modified: June 7, 2020
7+
Last Modified: June 8, 2020
88
99
Description: This file contains the Upscaler class. Each
1010
instance of the Upscaler class is an upscaler on an image or
@@ -50,7 +50,7 @@
5050
_ = language.gettext
5151

5252
# version information
53-
UPSCALER_VERSION = '4.2.1'
53+
UPSCALER_VERSION = '4.2.2'
5454

5555
# these names are consistent for
5656
# - driver selection in command line
@@ -73,23 +73,39 @@ class Upscaler:
7373
ArgumentError -- if argument is not valid
7474
"""
7575

76-
def __init__(self, input_path, output_path, driver_settings, ffmpeg_settings, gifski_settings):
77-
# mandatory arguments
76+
def __init__(
77+
self,
78+
input_path: pathlib.Path or list,
79+
output_path: pathlib.Path,
80+
driver_settings: dict,
81+
ffmpeg_settings: dict,
82+
gifski_settings: dict,
83+
driver: str = 'waifu2x_caffe',
84+
scale_ratio: float = None,
85+
processes: int = 1,
86+
video2x_cache_directory: pathlib.Path = pathlib.Path(tempfile.gettempdir()) / 'video2x',
87+
extracted_frame_format: str = 'png',
88+
image_output_extension: str = '.png',
89+
video_output_extension: str = '.mp4',
90+
preserve_frames: bool = False
91+
):
92+
93+
# required parameters
7894
self.input = input_path
7995
self.output = output_path
8096
self.driver_settings = driver_settings
8197
self.ffmpeg_settings = ffmpeg_settings
8298
self.gifski_settings = gifski_settings
8399

84-
# optional arguments
85-
self.driver = 'waifu2x_caffe'
86-
self.scale_ratio = None
87-
self.processes = 1
88-
self.video2x_cache_directory = pathlib.Path(tempfile.gettempdir()) / 'video2x'
89-
self.extracted_frame_format = 'png'
90-
self.image_output_extension = '.png'
91-
self.video_output_extension = '.mp4'
92-
self.preserve_frames = False
100+
# optional parameters
101+
self.driver = driver
102+
self.scale_ratio = scale_ratio
103+
self.processes = processes
104+
self.video2x_cache_directory = video2x_cache_directory
105+
self.extracted_frame_format = extracted_frame_format
106+
self.image_output_extension = image_output_extension
107+
self.video_output_extension = video_output_extension
108+
self.preserve_frames = preserve_frames
93109

94110
# other internal members and signals
95111
self.running = False

src/video2x.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Name: Video2X Controller
1414
Creator: K4YT3X
1515
Date Created: Feb 24, 2018
16-
Last Modified: June 7, 2020
16+
Last Modified: June 8, 2020
1717
1818
Editor: BrianPetkovsek
1919
Last Modified: June 17, 2019
@@ -81,7 +81,7 @@
8181
language.install()
8282
_ = language.gettext
8383

84-
CLI_VERSION = '4.1.0'
84+
CLI_VERSION = '4.1.1'
8585

8686
LEGAL_INFO = _('''Video2X CLI Version: {}
8787
Upscaler Version: {}
@@ -236,21 +236,24 @@ def read_config(config_file: pathlib.Path) -> dict:
236236
begin_time = time.time()
237237

238238
# initialize upscaler object
239-
upscaler = Upscaler(input_path=video2x_args.input,
240-
output_path=video2x_args.output,
241-
driver_settings=driver_settings,
242-
ffmpeg_settings=ffmpeg_settings,
243-
gifski_settings=gifski_settings)
244-
245-
# set upscaler optional options
246-
upscaler.driver = video2x_args.driver
247-
upscaler.scale_ratio = video2x_args.ratio
248-
upscaler.processes = video2x_args.processes
249-
upscaler.video2x_cache_directory = video2x_cache_directory
250-
upscaler.extracted_frame_format = extracted_frame_format
251-
upscaler.image_output_extension = image_output_extension
252-
upscaler.video_output_extension = video_output_extension
253-
upscaler.preserve_frames = preserve_frames
239+
upscaler = Upscaler(
240+
# required parameters
241+
input_path=video2x_args.input,
242+
output_path=video2x_args.output,
243+
driver_settings=driver_settings,
244+
ffmpeg_settings=ffmpeg_settings,
245+
gifski_settings=gifski_settings,
246+
247+
# optional parameters
248+
driver=video2x_args.driver,
249+
scale_ratio=video2x_args.ratio,
250+
processes=video2x_args.processes,
251+
video2x_cache_directory=video2x_cache_directory,
252+
extracted_frame_format=extracted_frame_format,
253+
image_output_extension=image_output_extension,
254+
video_output_extension=video_output_extension,
255+
preserve_frames=preserve_frames
256+
)
254257

255258
# run upscaler
256259
upscaler.run()

src/video2x_gui.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Creator: Video2X GUI
55
Author: K4YT3X
66
Date Created: May 5, 2020
7-
Last Modified: June 7, 2020
7+
Last Modified: June 8, 2020
88
"""
99

1010
# local imports
@@ -34,7 +34,7 @@
3434
from PyQt5.QtWidgets import *
3535
import magic
3636

37-
GUI_VERSION = '2.7.0'
37+
GUI_VERSION = '2.7.1'
3838

3939
LEGAL_INFO = f'''Video2X GUI Version: {GUI_VERSION}\\
4040
Upscaler Version: {UPSCALER_VERSION}\\
@@ -1173,21 +1173,24 @@ def start(self):
11731173
# load driver settings for the current driver
11741174
self.driver_settings = self.config[AVAILABLE_DRIVERS[self.driver_combo_box.currentText()]]
11751175

1176-
self.upscaler = Upscaler(input_path=input_directory,
1177-
output_path=output_directory,
1178-
driver_settings=self.driver_settings,
1179-
ffmpeg_settings=self.ffmpeg_settings,
1180-
gifski_settings=self.gifski_settings)
1181-
1182-
# set optional options
1183-
self.upscaler.driver = AVAILABLE_DRIVERS[self.driver_combo_box.currentText()]
1184-
self.upscaler.scale_ratio = self.scale_ratio_double_spin_box.value()
1185-
self.upscaler.processes = self.processes_spin_box.value()
1186-
self.upscaler.video2x_cache_directory = pathlib.Path(os.path.expandvars(self.cache_line_edit.text()))
1187-
self.upscaler.extracted_frame_format = self.config['video2x']['extracted_frame_format'].lower()
1188-
self.upscaler.image_output_extension = self.image_output_extension_line_edit.text()
1189-
self.upscaler.video_output_extension = self.video_output_extension_line_edit.text()
1190-
self.upscaler.preserve_frames = bool(self.preserve_frames_check_box.isChecked())
1176+
self.upscaler = Upscaler(
1177+
# required parameters
1178+
input_path=input_directory,
1179+
output_path=output_directory,
1180+
driver_settings=self.driver_settings,
1181+
ffmpeg_settings=self.ffmpeg_settings,
1182+
gifski_settings=self.gifski_settings,
1183+
1184+
# optional parameters
1185+
driver=AVAILABLE_DRIVERS[self.driver_combo_box.currentText()],
1186+
scale_ratio=self.scale_ratio_double_spin_box.value(),
1187+
processes=self.processes_spin_box.value(),
1188+
video2x_cache_directory=pathlib.Path(os.path.expandvars(self.cache_line_edit.text())),
1189+
extracted_frame_format=self.config['video2x']['extracted_frame_format'].lower(),
1190+
image_output_extension=self.image_output_extension_line_edit.text(),
1191+
video_output_extension=self.video_output_extension_line_edit.text(),
1192+
preserve_frames=bool(self.preserve_frames_check_box.isChecked())
1193+
)
11911194

11921195
# run upscaler
11931196
worker = UpscalerWorker(self.upscaler.run)

src/video2x_gui.ui

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>673</width>
10-
<height>910</height>
9+
<width>727</width>
10+
<height>908</height>
1111
</rect>
1212
</property>
1313
<property name="acceptDrops">
@@ -2835,7 +2835,7 @@
28352835
<rect>
28362836
<x>0</x>
28372837
<y>0</y>
2838-
<width>673</width>
2838+
<width>727</width>
28392839
<height>21</height>
28402840
</rect>
28412841
</property>

0 commit comments

Comments
 (0)