added input_options import for every phase

This commit is contained in:
k4yt3x 2020-05-14 19:55:52 -04:00
parent c1c96815cf
commit 54f8f19c7e

View File

@ -4,7 +4,7 @@
Name: Video2X FFmpeg Controller Name: Video2X FFmpeg Controller
Author: K4YT3X Author: K4YT3X
Date Created: Feb 24, 2018 Date Created: Feb 24, 2018
Last Modified: May 12, 2020 Last Modified: May 14, 2020
Description: This class handles all FFmpeg related operations. Description: This class handles all FFmpeg related operations.
""" """
@ -50,15 +50,15 @@ class Ffmpeg:
""" """
execute = [ execute = [
self.ffmpeg_probe_binary, self.ffmpeg_probe_binary,
# '-v', '-v',
# 'quiet', 'quiet',
'-pix_fmts' '-pix_fmts'
] ]
# turn elements into str # turn elements into str
execute = [str(e) for e in execute] execute = [str(e) for e in execute]
Avalon.debug_info(f'Executing: {" ".join(execute)}') Avalon.debug_info(f'Executing: {shlex.join(execute)}')
# initialize dictionary to store pixel formats # initialize dictionary to store pixel formats
pixel_formats = {} pixel_formats = {}
@ -116,15 +116,22 @@ class Ffmpeg:
self.ffmpeg_binary self.ffmpeg_binary
] ]
# load general options
execute.extend(self._read_configuration(phase='extract_frames')) execute.extend(self._read_configuration(phase='extract_frames'))
# load input_options
execute.extend(self._read_configuration(phase='extract_frames', section='input_options'))
# specify input file
execute.extend([ execute.extend([
'-i', '-i',
input_file input_file
]) ])
# load output options
execute.extend(self._read_configuration(phase='extract_frames', section='output_options')) execute.extend(self._read_configuration(phase='extract_frames', section='output_options'))
# specify output file
execute.extend([ execute.extend([
extracted_frames / f'extracted_%0d.{self.image_format}' extracted_frames / f'extracted_%0d.{self.image_format}'
]) ])
@ -152,7 +159,7 @@ class Ffmpeg:
# read other options # read other options
execute.extend(self._read_configuration(phase='assemble_video')) execute.extend(self._read_configuration(phase='assemble_video'))
# read FFmpeg input options # read input options
execute.extend(self._read_configuration(phase='assemble_video', section='input_options')) execute.extend(self._read_configuration(phase='assemble_video', section='input_options'))
# WORKAROUND FOR WAIFU2X-NCNN-VULKAN # WORKAROUND FOR WAIFU2X-NCNN-VULKAN
@ -192,17 +199,28 @@ class Ffmpeg:
self.ffmpeg_binary self.ffmpeg_binary
] ]
# load general options
execute.extend(self._read_configuration(phase='migrate_streams')) execute.extend(self._read_configuration(phase='migrate_streams'))
# load input options
execute.extend(self._read_configuration(phase='migrate_streams', section='input_options'))
# load input file names
execute.extend([ execute.extend([
# input 1: upscaled intermediate file without sound
'-i', '-i',
upscaled_frames / self.intermediate_file_name, upscaled_frames / self.intermediate_file_name,
# input 2: original video with streams to copy over
'-i', '-i',
input_video input_video
]) ])
# load output options
execute.extend(self._read_configuration(phase='migrate_streams', section='output_options')) execute.extend(self._read_configuration(phase='migrate_streams', section='output_options'))
# load output video path
execute.extend([ execute.extend([
output_video output_video
]) ])
@ -227,16 +245,10 @@ 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()
# for each key in the section's dict
for key in source: for key in source:
if section: if section:
@ -271,7 +283,5 @@ class Ffmpeg:
def _execute(self, execute): def _execute(self, execute):
# turn all list elements into string to avoid errors # turn all list elements into string to avoid errors
execute = [str(e) for e in execute] execute = [str(e) for e in execute]
Avalon.debug_info(f'Executing: {shlex.join(execute)}') Avalon.debug_info(f'Executing: {shlex.join(execute)}')
return subprocess.Popen(execute) return subprocess.Popen(execute)