mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-01-01 10:29:09 +00:00
upscaler 4.1.0: removed Anime4KCPP workaround to enable support for GIF and progress bar
This commit is contained in:
parent
192c6ef38b
commit
5af49012c8
114
src/upscaler.py
114
src/upscaler.py
@ -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: May 15, 2020
|
Last Modified: May 16, 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
|
||||||
@ -49,7 +49,7 @@ language.install()
|
|||||||
_ = language.gettext
|
_ = language.gettext
|
||||||
|
|
||||||
# version information
|
# version information
|
||||||
UPSCALER_VERSION = '4.0.0'
|
UPSCALER_VERSION = '4.1.0'
|
||||||
|
|
||||||
# these names are consistent for
|
# these names are consistent for
|
||||||
# - driver selection in command line
|
# - driver selection in command line
|
||||||
@ -243,14 +243,6 @@ class Upscaler:
|
|||||||
self.driver_settings['scale_width'] = None
|
self.driver_settings['scale_width'] = None
|
||||||
self.driver_settings['scale_height'] = None
|
self.driver_settings['scale_height'] = None
|
||||||
|
|
||||||
# temporary file type check for Anime4KCPP
|
|
||||||
# it doesn't support GIF processing yet
|
|
||||||
if self.driver == 'anime4kcpp':
|
|
||||||
for task in self.processing_queue.queue:
|
|
||||||
if task[0].suffix.lower() == '.gif':
|
|
||||||
Avalon.error(_('Anime4KCPP doesn\'t yet support GIF processing'))
|
|
||||||
raise AttributeError('Anime4KCPP doesn\'t yet support GIF file processing')
|
|
||||||
|
|
||||||
def _upscale_frames(self):
|
def _upscale_frames(self):
|
||||||
""" Upscale video frames with waifu2x-caffe
|
""" Upscale video frames with waifu2x-caffe
|
||||||
|
|
||||||
@ -480,72 +472,58 @@ class Upscaler:
|
|||||||
# if input file is a image/gif file or a video
|
# if input file is a image/gif file or a video
|
||||||
elif input_file_mime_type == 'image/gif' or input_file_type == 'video':
|
elif input_file_mime_type == 'image/gif' or input_file_type == 'video':
|
||||||
|
|
||||||
# drivers that have native support for video processing
|
self.create_temp_directories()
|
||||||
if input_file_type == 'video' and self.driver == 'anime4kcpp':
|
|
||||||
Avalon.info(_('Starting to upscale video with Anime4KCPP'))
|
|
||||||
# enable video processing mode for Anime4KCPP
|
|
||||||
self.driver_settings['videoMode'] = True
|
|
||||||
self.process_pool.append(self.driver_object.upscale(self.current_input_file, output_path))
|
|
||||||
self._wait()
|
|
||||||
Avalon.info(_('Upscaling completed'))
|
|
||||||
self.processing_queue.task_done()
|
|
||||||
self.total_processed += 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
else:
|
# get video information JSON using FFprobe
|
||||||
self.create_temp_directories()
|
Avalon.info(_('Reading video information'))
|
||||||
|
video_info = self.ffmpeg_object.probe_file_info(self.current_input_file)
|
||||||
|
# analyze original video with FFprobe and retrieve framerate
|
||||||
|
# width, height = info['streams'][0]['width'], info['streams'][0]['height']
|
||||||
|
|
||||||
# get video information JSON using FFprobe
|
# find index of video stream
|
||||||
Avalon.info(_('Reading video information'))
|
video_stream_index = None
|
||||||
video_info = self.ffmpeg_object.probe_file_info(self.current_input_file)
|
for stream in video_info['streams']:
|
||||||
# analyze original video with FFprobe and retrieve framerate
|
if stream['codec_type'] == 'video':
|
||||||
# width, height = info['streams'][0]['width'], info['streams'][0]['height']
|
video_stream_index = stream['index']
|
||||||
|
break
|
||||||
|
|
||||||
# find index of video stream
|
# exit if no video stream found
|
||||||
video_stream_index = None
|
if video_stream_index is None:
|
||||||
for stream in video_info['streams']:
|
Avalon.error(_('Aborting: No video stream found'))
|
||||||
if stream['codec_type'] == 'video':
|
raise StreamNotFoundError('no video stream found')
|
||||||
video_stream_index = stream['index']
|
|
||||||
break
|
|
||||||
|
|
||||||
# exit if no video stream found
|
# get average frame rate of video stream
|
||||||
if video_stream_index is None:
|
framerate = float(Fraction(video_info['streams'][video_stream_index]['r_frame_rate']))
|
||||||
Avalon.error(_('Aborting: No video stream found'))
|
Avalon.info(_('Framerate: {}').format(framerate))
|
||||||
raise StreamNotFoundError('no video stream found')
|
# self.ffmpeg_object.pixel_format = video_info['streams'][video_stream_index]['pix_fmt']
|
||||||
|
|
||||||
# get average frame rate of video stream
|
# extract frames from video
|
||||||
framerate = float(Fraction(video_info['streams'][video_stream_index]['r_frame_rate']))
|
self.process_pool.append((self.ffmpeg_object.extract_frames(self.current_input_file, self.extracted_frames)))
|
||||||
Avalon.info(_('Framerate: {}').format(framerate))
|
self._wait()
|
||||||
# self.ffmpeg_object.pixel_format = video_info['streams'][video_stream_index]['pix_fmt']
|
|
||||||
|
|
||||||
# extract frames from video
|
# if driver is waifu2x-caffe
|
||||||
self.process_pool.append((self.ffmpeg_object.extract_frames(self.current_input_file, self.extracted_frames)))
|
# pass pixel format output depth information
|
||||||
self._wait()
|
if self.driver == 'waifu2x_caffe':
|
||||||
|
# get a dict of all pixel formats and corresponding bit depth
|
||||||
|
pixel_formats = self.ffmpeg_object.get_pixel_formats()
|
||||||
|
|
||||||
# if driver is waifu2x-caffe
|
# try getting pixel format's corresponding bti depth
|
||||||
# pass pixel format output depth information
|
try:
|
||||||
if self.driver == 'waifu2x_caffe':
|
self.driver_settings['output_depth'] = pixel_formats[self.ffmpeg_object.pixel_format]
|
||||||
# get a dict of all pixel formats and corresponding bit depth
|
except KeyError:
|
||||||
pixel_formats = self.ffmpeg_object.get_pixel_formats()
|
Avalon.error(_('Unsupported pixel format: {}').format(self.ffmpeg_object.pixel_format))
|
||||||
|
raise UnsupportedPixelError(f'unsupported pixel format {self.ffmpeg_object.pixel_format}')
|
||||||
|
|
||||||
# try getting pixel format's corresponding bti depth
|
# width/height will be coded width/height x upscale factor
|
||||||
try:
|
# original_width = video_info['streams'][video_stream_index]['width']
|
||||||
self.driver_settings['output_depth'] = pixel_formats[self.ffmpeg_object.pixel_format]
|
# original_height = video_info['streams'][video_stream_index]['height']
|
||||||
except KeyError:
|
# scale_width = int(self.scale_ratio * original_width)
|
||||||
Avalon.error(_('Unsupported pixel format: {}').format(self.ffmpeg_object.pixel_format))
|
# scale_height = int(self.scale_ratio * original_height)
|
||||||
raise UnsupportedPixelError(f'unsupported pixel format {self.ffmpeg_object.pixel_format}')
|
|
||||||
|
|
||||||
|
# upscale images one by one using waifu2x
|
||||||
# width/height will be coded width/height x upscale factor
|
Avalon.info(_('Starting to upscale extracted frames'))
|
||||||
# original_width = video_info['streams'][video_stream_index]['width']
|
self._upscale_frames()
|
||||||
# original_height = video_info['streams'][video_stream_index]['height']
|
Avalon.info(_('Upscaling completed'))
|
||||||
# scale_width = int(self.scale_ratio * original_width)
|
|
||||||
# scale_height = int(self.scale_ratio * original_height)
|
|
||||||
|
|
||||||
# upscale images one by one using waifu2x
|
|
||||||
Avalon.info(_('Starting to upscale extracted frames'))
|
|
||||||
self._upscale_frames()
|
|
||||||
Avalon.info(_('Upscaling completed'))
|
|
||||||
|
|
||||||
# if file is none of: image, image/gif, video
|
# if file is none of: image, image/gif, video
|
||||||
# skip to the next task
|
# skip to the next task
|
||||||
@ -572,7 +550,7 @@ class Upscaler:
|
|||||||
# frames to video
|
# frames to video
|
||||||
Avalon.info(_('Converting extracted frames into video'))
|
Avalon.info(_('Converting extracted frames into video'))
|
||||||
self.process_pool.append(self.ffmpeg_object.assemble_video(framerate, self.upscaled_frames))
|
self.process_pool.append(self.ffmpeg_object.assemble_video(framerate, self.upscaled_frames))
|
||||||
# f'{scale_width}x{scale_height}',
|
# f'{scale_width}x{scale_height}'
|
||||||
self._wait()
|
self._wait()
|
||||||
Avalon.info(_('Conversion completed'))
|
Avalon.info(_('Conversion completed'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user