mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-01-01 10:29:09 +00:00
fixed global scaling variable errors and Gifski output resolution issues
This commit is contained in:
parent
d824cd6516
commit
bfdb051705
@ -591,24 +591,29 @@ class Upscaler:
|
|||||||
# calculate scale width/height/ratio and scaling jobs if required
|
# calculate scale width/height/ratio and scaling jobs if required
|
||||||
Avalon.info(_('Calculating scaling parameters'))
|
Avalon.info(_('Calculating scaling parameters'))
|
||||||
|
|
||||||
|
# create a local copy of the global output settings
|
||||||
|
output_scale = self.scale_ratio
|
||||||
|
output_width = self.scale_width
|
||||||
|
output_height = self.scale_height
|
||||||
|
|
||||||
# calculate output width and height if scale ratio is specified
|
# calculate output width and height if scale ratio is specified
|
||||||
if self.scale_ratio is not None:
|
if output_scale is not None:
|
||||||
output_width = int(math.ceil(width * self.scale_ratio / 2.0) * 2)
|
output_width = int(math.ceil(width * output_scale / 2.0) * 2)
|
||||||
output_height = int(math.ceil(height * self.scale_ratio / 2.0) * 2)
|
output_height = int(math.ceil(height * output_scale / 2.0) * 2)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# scale keeping aspect ratio is only one of width/height is given
|
# scale keeping aspect ratio is only one of width/height is given
|
||||||
if self.scale_width == 0 or self.scale_width is None:
|
if output_width == 0 or output_width is None:
|
||||||
self.scale_width = self.scale_height / height * width
|
output_width = output_height / height * width
|
||||||
|
|
||||||
elif self.scale_height == 0 or self.scale_height is None:
|
elif output_height == 0 or output_height is None:
|
||||||
self.scale_height = self.scale_width / width * height
|
output_height = output_width / width * height
|
||||||
|
|
||||||
output_width = int(math.ceil(self.scale_width / 2.0) * 2)
|
output_width = int(math.ceil(output_width / 2.0) * 2)
|
||||||
output_height = int(math.ceil(self.scale_height / 2.0) * 2)
|
output_height = int(math.ceil(output_height / 2.0) * 2)
|
||||||
|
|
||||||
# calculate required minimum scale ratio
|
# calculate required minimum scale ratio
|
||||||
self.scale_ratio = max(output_width / width, output_height / height)
|
output_scale = max(output_width / width, output_height / height)
|
||||||
|
|
||||||
# if driver is one of the drivers that doesn't support arbitrary scaling ratio
|
# if driver is one of the drivers that doesn't support arbitrary scaling ratio
|
||||||
# TODO: more documentations on this block
|
# TODO: more documentations on this block
|
||||||
@ -617,7 +622,7 @@ class Upscaler:
|
|||||||
# select the optimal driver scaling ratio to use
|
# select the optimal driver scaling ratio to use
|
||||||
supported_scaling_ratios = sorted(DRIVER_FIXED_SCALING_RATIOS[self.driver])
|
supported_scaling_ratios = sorted(DRIVER_FIXED_SCALING_RATIOS[self.driver])
|
||||||
|
|
||||||
remaining_scaling_ratio = math.ceil(self.scale_ratio)
|
remaining_scaling_ratio = math.ceil(output_scale)
|
||||||
self.scaling_jobs = []
|
self.scaling_jobs = []
|
||||||
|
|
||||||
while remaining_scaling_ratio > 1:
|
while remaining_scaling_ratio > 1:
|
||||||
@ -645,7 +650,7 @@ class Upscaler:
|
|||||||
remaining_scaling_ratio /= supported_scaling_ratios[-1]
|
remaining_scaling_ratio /= supported_scaling_ratios[-1]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.scaling_jobs = [self.scale_ratio]
|
self.scaling_jobs = [output_scale]
|
||||||
|
|
||||||
# print file information
|
# print file information
|
||||||
Avalon.debug_info(_('Framerate: {}').format(framerate))
|
Avalon.debug_info(_('Framerate: {}').format(framerate))
|
||||||
@ -654,7 +659,7 @@ class Upscaler:
|
|||||||
Avalon.debug_info(_('Total number of frames: {}').format(self.total_frames))
|
Avalon.debug_info(_('Total number of frames: {}').format(self.total_frames))
|
||||||
Avalon.debug_info(_('Output width: {}').format(output_width))
|
Avalon.debug_info(_('Output width: {}').format(output_width))
|
||||||
Avalon.debug_info(_('Output height: {}').format(output_height))
|
Avalon.debug_info(_('Output height: {}').format(output_height))
|
||||||
Avalon.debug_info(_('Required scale ratio: {}').format(self.scale_ratio))
|
Avalon.debug_info(_('Required scale ratio: {}').format(output_scale))
|
||||||
Avalon.debug_info(_('Upscaling jobs queue: {}').format(self.scaling_jobs))
|
Avalon.debug_info(_('Upscaling jobs queue: {}').format(self.scaling_jobs))
|
||||||
|
|
||||||
# extract frames from video
|
# extract frames from video
|
||||||
@ -733,7 +738,7 @@ class Upscaler:
|
|||||||
if output_path.suffix.lower() == '.gif':
|
if output_path.suffix.lower() == '.gif':
|
||||||
Avalon.info(_('Converting extracted frames into GIF image'))
|
Avalon.info(_('Converting extracted frames into GIF image'))
|
||||||
gifski_object = Gifski(self.gifski_settings)
|
gifski_object = Gifski(self.gifski_settings)
|
||||||
self.process_pool.append(gifski_object.make_gif(self.upscaled_frames, output_path, framerate, self.extracted_frame_format))
|
self.process_pool.append(gifski_object.make_gif(self.upscaled_frames, output_path, framerate, self.extracted_frame_format, output_width, output_height))
|
||||||
self._wait()
|
self._wait()
|
||||||
Avalon.info(_('Conversion completed'))
|
Avalon.info(_('Conversion completed'))
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
Name: Gifski Wrapper
|
Name: Gifski Wrapper
|
||||||
Creator: K4YT3X
|
Creator: K4YT3X
|
||||||
Date Created: May 11, 2020
|
Date Created: May 11, 2020
|
||||||
Last Modified: June 7, 2020
|
Last Modified: September 13, 2020
|
||||||
|
|
||||||
Description: High-level wrapper for Gifski.
|
Description: High-level wrapper for Gifski.
|
||||||
"""
|
"""
|
||||||
@ -22,13 +22,17 @@ class Gifski:
|
|||||||
def __init__(self, gifski_settings):
|
def __init__(self, gifski_settings):
|
||||||
self.gifski_settings = gifski_settings
|
self.gifski_settings = gifski_settings
|
||||||
|
|
||||||
def make_gif(self, upscaled_frames: pathlib.Path, output_path: pathlib.Path, framerate: float, extracted_frame_format: str) -> subprocess.Popen:
|
def make_gif(self, upscaled_frames: pathlib.Path, output_path: pathlib.Path, framerate: float, extracted_frame_format: str, output_width: int, output_height: int) -> subprocess.Popen:
|
||||||
execute = [
|
execute = [
|
||||||
self.gifski_settings['gifski_path'],
|
self.gifski_settings['gifski_path'],
|
||||||
'-o',
|
'-o',
|
||||||
output_path,
|
output_path,
|
||||||
'--fps',
|
'--fps',
|
||||||
int(round(framerate, 0))
|
int(round(framerate, 0)),
|
||||||
|
'--width',
|
||||||
|
output_width,
|
||||||
|
'--height',
|
||||||
|
output_height
|
||||||
]
|
]
|
||||||
|
|
||||||
# load configurations from config file
|
# load configurations from config file
|
||||||
|
Loading…
Reference in New Issue
Block a user