mirror of
https://github.com/AnimeThemes/animethemes-batch-encoder.git
synced 2026-07-11 01:24:29 +02:00
Merge pull request #20 from Kyrch/SequencingOfCommands
feat: Alternate between source files
This commit is contained in:
@@ -67,6 +67,8 @@ Available bitrate control modes are:
|
||||
|
||||
`LimitSizeEnable` is a flag for including the `-fs` argument to terminate an encode when it exceeds the allowed size. Default is True.
|
||||
|
||||
`AlternateSourceEnable` is a flag for alternate command lines between source files. Default is False.
|
||||
|
||||
`IncludeUnfiltered` is a flag for including or excluding an encode without video filters for each bitrate control mode and CRF pairing. Default is True.
|
||||
|
||||
`VideoFilters` is a configuration item list used for named video filtergraphs for each bitrate control mode and CRF pairing.
|
||||
|
||||
@@ -59,6 +59,7 @@ def main():
|
||||
EncodingConfig.config_crfs: EncodingConfig.default_crfs,
|
||||
EncodingConfig.config_threads: EncodingConfig.default_threads,
|
||||
EncodingConfig.config_limit_size_enable: EncodingConfig.default_limit_size_enable,
|
||||
EncodingConfig.config_alternate_source_files: EncodingConfig.default_alternate_source_files,
|
||||
EncodingConfig.config_include_unfiltered: EncodingConfig.default_include_unfiltered,
|
||||
EncodingConfig.config_default_video_stream: '',
|
||||
EncodingConfig.config_default_audio_stream: ''}
|
||||
@@ -96,9 +97,21 @@ def main():
|
||||
for seek in seek_collector.get_seek_list():
|
||||
logging.info(f'Generating commands with seek ss: \'{seek.ss}\', to: \'{seek.to}\'')
|
||||
encode_webm = EncodeWebM(source_file, seek)
|
||||
commands = commands + encode_webm.get_commands(encoding_config)
|
||||
load_commands = encode_webm.get_commands(encoding_config)
|
||||
commands = commands + load_commands
|
||||
except KeyboardInterrupt:
|
||||
logging.info(f'Exiting from inclusion of file \'{source_file_candidate}\' after keyboard interrupt')
|
||||
|
||||
# Alternate lines per source files
|
||||
if encoding_config.alternate_source_files == True:
|
||||
output_list = []
|
||||
lines_per_source = len(load_commands)
|
||||
for i in range(lines_per_source):
|
||||
output_list.append(commands[i])
|
||||
for k in range(1, len(commands) // lines_per_source):
|
||||
output_list.append(commands[i + lines_per_source * k])
|
||||
|
||||
commands = output_list
|
||||
|
||||
# Write commands to file
|
||||
if args.mode == 1:
|
||||
@@ -133,4 +146,4 @@ if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
logging.error('Exiting after keyboard interrupt')
|
||||
logging.error('Exiting after keyboard interrupt')
|
||||
@@ -130,7 +130,7 @@ class EncodeWebM:
|
||||
f'{self.colorspace.get_args()} ' \
|
||||
f'-c:a libopus -b:a {self.audio_bitrate} -ar 48k ' \
|
||||
f'{limit_size}' \
|
||||
f'-map_metadata -1 -map_chapters -1 -sn -f webm -y {webm_filename}.webm'
|
||||
f'-map_metadata:g -1 -map_metadata:s:v -1 -map_metadata:s:a -1 -map_chapters -1 -sn -f webm -y {webm_filename}.webm'
|
||||
|
||||
# Build audio filtergraph for encodes
|
||||
def get_audio_filters(self):
|
||||
|
||||
@@ -8,6 +8,7 @@ class EncodingConfig:
|
||||
config_crfs = 'CRFs'
|
||||
config_threads = 'Threads'
|
||||
config_limit_size_enable = 'LimitSizeEnable'
|
||||
config_alternate_source_files = 'AlternateSourceFiles'
|
||||
config_include_unfiltered = 'IncludeUnfiltered'
|
||||
|
||||
# Default Config keys
|
||||
@@ -18,21 +19,23 @@ class EncodingConfig:
|
||||
default_allowed_filetypes = '.avi,.m2ts,.mkv,.mp4,.wmv'
|
||||
default_encoding_modes = f'{BitrateMode.VBR.name},{BitrateMode.CBR.name}'
|
||||
default_crfs = '12,15,18,21,24'
|
||||
default_limit_size_enable = True
|
||||
default_threads = '4'
|
||||
default_limit_size_enable = True
|
||||
default_alternate_source_files = False
|
||||
default_include_unfiltered = True
|
||||
default_video_filters = {'filtered': 'hqdn3d=0:0:3:3,gradfun,unsharp',
|
||||
'lightdenoise': 'hqdn3d=0:0:3:3',
|
||||
'heavydenoise': 'hqdn3d=1.5:1.5:6:6',
|
||||
'unsharp': 'unsharp'}
|
||||
|
||||
def __init__(self, allowed_filetypes, encoding_modes, crfs, threads, limit_size_enable, include_unfiltered, video_filters, default_video_stream,
|
||||
def __init__(self, allowed_filetypes, encoding_modes, crfs, threads, limit_size_enable, alternate_source_files, include_unfiltered, video_filters, default_video_stream,
|
||||
default_audio_stream):
|
||||
self.allowed_filetypes = allowed_filetypes
|
||||
self.encoding_modes = encoding_modes
|
||||
self.crfs = crfs
|
||||
self.threads = threads
|
||||
self.limit_size_enable = limit_size_enable
|
||||
self.alternate_source_files = alternate_source_files
|
||||
self.include_unfiltered = include_unfiltered
|
||||
self.video_filters = video_filters
|
||||
self.default_video_stream = default_video_stream
|
||||
@@ -48,6 +51,7 @@ class EncodingConfig:
|
||||
threads = config['Encoding'].get(EncodingConfig.config_threads,
|
||||
EncodingConfig.default_threads)
|
||||
limit_size_enable = config.getboolean('Encoding', EncodingConfig.config_limit_size_enable, fallback=EncodingConfig.default_limit_size_enable)
|
||||
alternate_source_files = config.getboolean('Encoding', EncodingConfig.config_alternate_source_files, fallback=EncodingConfig.default_alternate_source_files)
|
||||
include_unfiltered = config.getboolean('Encoding', EncodingConfig.config_include_unfiltered,
|
||||
fallback=EncodingConfig.default_include_unfiltered)
|
||||
video_filters = config.items('VideoFilters', EncodingConfig.default_video_filters)
|
||||
@@ -55,7 +59,7 @@ class EncodingConfig:
|
||||
default_video_stream = config['Encoding'].get(EncodingConfig.config_default_video_stream)
|
||||
default_audio_stream = config['Encoding'].get(EncodingConfig.config_default_audio_stream)
|
||||
|
||||
return cls(allowed_filetypes, encoding_modes, crfs, threads, limit_size_enable, include_unfiltered, video_filters, default_video_stream,
|
||||
return cls(allowed_filetypes, encoding_modes, crfs, threads, limit_size_enable, alternate_source_files, include_unfiltered, video_filters, default_video_stream,
|
||||
default_audio_stream)
|
||||
|
||||
def get_default_stream(self, stream_type):
|
||||
|
||||
@@ -150,4 +150,4 @@ class SourceFile:
|
||||
channels = int(self.audio_format['streams'][0].get('channels', 2))
|
||||
channel_layout = self.audio_format['streams'][0].get('channel_layout', 'stereo')
|
||||
if channels != 2 or channel_layout != 'stereo':
|
||||
audio_filters.append('aresample=ocl=stereo')
|
||||
audio_filters.append('aresample=ochl=stereo')
|
||||
|
||||
Reference in New Issue
Block a user