mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-01-01 10:29:09 +00:00
2.8.1 added automatic pixel format and color depth detection
This commit is contained in:
parent
8b845e35b3
commit
ca90c5be02
@ -6,7 +6,7 @@
|
|||||||
Name: FFMPEG Class
|
Name: FFMPEG Class
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: Feb 24, 2018
|
Date Created: Feb 24, 2018
|
||||||
Last Modified: June 15, 2019
|
Last Modified: July 9, 2019
|
||||||
|
|
||||||
Description: This class handles all FFMPEG related
|
Description: This class handles all FFMPEG related
|
||||||
operations.
|
operations.
|
||||||
@ -33,6 +33,40 @@ class Ffmpeg:
|
|||||||
self.ffmpeg_binary = os.path.join(self.ffmpeg_path, 'ffmpeg.exe')
|
self.ffmpeg_binary = os.path.join(self.ffmpeg_path, 'ffmpeg.exe')
|
||||||
self.ffmpeg_probe_binary = os.path.join(self.ffmpeg_path, 'ffprobe.exe')
|
self.ffmpeg_probe_binary = os.path.join(self.ffmpeg_path, 'ffprobe.exe')
|
||||||
self.image_format = image_format
|
self.image_format = image_format
|
||||||
|
self.pixel_format = None
|
||||||
|
|
||||||
|
def get_pixel_formats(self):
|
||||||
|
""" Get a dictionary of supported pixel formats
|
||||||
|
|
||||||
|
List all supported pixel formats and their corresponding
|
||||||
|
bit depth.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dictionary -- JSON dict of all pixel formats to bit depth
|
||||||
|
"""
|
||||||
|
execute = [
|
||||||
|
self.ffmpeg_probe_binary,
|
||||||
|
'-v',
|
||||||
|
'quiet',
|
||||||
|
'-pix_fmts'
|
||||||
|
]
|
||||||
|
|
||||||
|
Avalon.debug_info(f'Executing: {" ".join(execute)}')
|
||||||
|
|
||||||
|
# initialize dictionary to store pixel formats
|
||||||
|
pixel_formats = {}
|
||||||
|
|
||||||
|
# record all pixel formats into dictionary
|
||||||
|
for line in subprocess.run(execute, check=True, stdout=subprocess.PIPE).stdout.decode().split('\n'):
|
||||||
|
try:
|
||||||
|
pixel_formats[' '.join(line.split()).split()[1]] = int(' '.join(line.split()).split()[3])
|
||||||
|
except (IndexError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# print pixel formats for debugging
|
||||||
|
Avalon.debug_info(pixel_formats)
|
||||||
|
|
||||||
|
return pixel_formats
|
||||||
|
|
||||||
def get_video_info(self, input_video):
|
def get_video_info(self, input_video):
|
||||||
""" Gets input video information
|
""" Gets input video information
|
||||||
@ -179,6 +213,13 @@ class Ffmpeg:
|
|||||||
# from only that section
|
# from only that section
|
||||||
if section:
|
if section:
|
||||||
source = self.ffmpeg_settings[phase][section].keys()
|
source = self.ffmpeg_settings[phase][section].keys()
|
||||||
|
|
||||||
|
# if pixel format is not specified, use the source pixel format
|
||||||
|
try:
|
||||||
|
if self.ffmpeg_settings[phase][section].get('-pix_fmt') is None:
|
||||||
|
self.ffmpeg_settings[phase][section]['-pix_fmt'] = self.pixel_format
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
source = self.ffmpeg_settings[phase].keys()
|
source = self.ffmpeg_settings[phase].keys()
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
Name: Video2X Upscaler
|
Name: Video2X Upscaler
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: December 10, 2018
|
Date Created: December 10, 2018
|
||||||
Last Modified: June 26, 2019
|
Last Modified: July 9, 2019
|
||||||
|
|
||||||
Dev: SAT3LL
|
Dev: SAT3LL
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ class Upscaler:
|
|||||||
|
|
||||||
# create a separate w2 instance for each thread
|
# create a separate w2 instance for each thread
|
||||||
if self.waifu2x_driver == 'waifu2x_caffe':
|
if self.waifu2x_driver == 'waifu2x_caffe':
|
||||||
w2 = Waifu2xCaffe(copy.deepcopy(self.waifu2x_settings), self.method, self.model_dir)
|
w2 = Waifu2xCaffe(copy.deepcopy(self.waifu2x_settings), self.method, self.model_dir, self.bit_depth)
|
||||||
if self.scale_ratio:
|
if self.scale_ratio:
|
||||||
thread = threading.Thread(target=w2.upscale,
|
thread = threading.Thread(target=w2.upscale,
|
||||||
args=(thread_info[0],
|
args=(thread_info[0],
|
||||||
@ -314,6 +314,17 @@ class Upscaler:
|
|||||||
|
|
||||||
# get average frame rate of video stream
|
# get average frame rate of video stream
|
||||||
framerate = float(Fraction(video_info['streams'][video_stream_index]['avg_frame_rate']))
|
framerate = float(Fraction(video_info['streams'][video_stream_index]['avg_frame_rate']))
|
||||||
|
fm.pixel_format = video_info['streams'][video_stream_index]['pix_fmt']
|
||||||
|
|
||||||
|
# get a dict of all pixel formats and corresponding bit depth
|
||||||
|
pixel_formats = fm.get_pixel_formats()
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.bit_depth = pixel_formats[fm.pixel_format]
|
||||||
|
except KeyError as e:
|
||||||
|
Avalon.error(f'Unsupported pixel format: {fm.pixel_format}')
|
||||||
|
raise e
|
||||||
|
|
||||||
Avalon.info(f'Framerate: {framerate}')
|
Avalon.info(f'Framerate: {framerate}')
|
||||||
|
|
||||||
# width/height will be coded width/height x upscale factor
|
# width/height will be coded width/height x upscale factor
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
"-vcodec": "libx264",
|
"-vcodec": "libx264",
|
||||||
"-crf": 17,
|
"-crf": 17,
|
||||||
"-b:v": null,
|
"-b:v": null,
|
||||||
"-pix_fmt": "yuv420p"
|
"-pix_fmt": null
|
||||||
},
|
},
|
||||||
"-y": true
|
"-y": true
|
||||||
},
|
},
|
||||||
@ -76,7 +76,7 @@
|
|||||||
"-map": "1?",
|
"-map": "1?",
|
||||||
"-c": "copy",
|
"-c": "copy",
|
||||||
"-map": "-1:v?",
|
"-map": "-1:v?",
|
||||||
"-pix_fmt": "yuv420p"
|
"-pix_fmt": null
|
||||||
},
|
},
|
||||||
"-y": true
|
"-y": true
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ __ __ _ _ ___ __ __
|
|||||||
Name: Video2X Controller
|
Name: Video2X Controller
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: Feb 24, 2018
|
Date Created: Feb 24, 2018
|
||||||
Last Modified: June 26, 2019
|
Last Modified: July 9, 2019
|
||||||
|
|
||||||
Dev: BrianPetkovsek
|
Dev: BrianPetkovsek
|
||||||
Dev: SAT3LL
|
Dev: SAT3LL
|
||||||
@ -57,7 +57,7 @@ import tempfile
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
VERSION = '2.8.0'
|
VERSION = '2.8.1'
|
||||||
|
|
||||||
# each thread might take up to 2.5 GB during initialization.
|
# each thread might take up to 2.5 GB during initialization.
|
||||||
# (system memory, not to be confused with GPU memory)
|
# (system memory, not to be confused with GPU memory)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
Name: Waifu2x Caffe Driver
|
Name: Waifu2x Caffe Driver
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: Feb 24, 2018
|
Date Created: Feb 24, 2018
|
||||||
Last Modified: June 15, 2019
|
Last Modified: July 9, 2019
|
||||||
|
|
||||||
Description: This class is a high-level wrapper
|
Description: This class is a high-level wrapper
|
||||||
for waifu2x-caffe.
|
for waifu2x-caffe.
|
||||||
@ -25,10 +25,11 @@ class Waifu2xCaffe:
|
|||||||
the upscale function.
|
the upscale function.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, waifu2x_settings, process, model_dir):
|
def __init__(self, waifu2x_settings, process, model_dir, bit_depth):
|
||||||
self.waifu2x_settings = waifu2x_settings
|
self.waifu2x_settings = waifu2x_settings
|
||||||
self.waifu2x_settings['process'] = process
|
self.waifu2x_settings['process'] = process
|
||||||
self.waifu2x_settings['model_dir'] = model_dir
|
self.waifu2x_settings['model_dir'] = model_dir
|
||||||
|
self.waifu2x_settings['output_depth'] = bit_depth
|
||||||
|
|
||||||
# arguments passed through command line overwrites config file values
|
# arguments passed through command line overwrites config file values
|
||||||
self.process = process
|
self.process = process
|
||||||
|
Loading…
Reference in New Issue
Block a user