Skip to content

Commit

Permalink
Merge pull request #20 from Kyrch/SequencingOfCommands
Browse files Browse the repository at this point in the history
feat: Alternate between source files
  • Loading branch information
paranarimasu committed May 19, 2023
2 parents 1f5ccff + 84b38f2 commit 071ec5d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 15 additions & 2 deletions batch_encoder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -133,4 +146,4 @@ def main():
try:
main()
except KeyboardInterrupt:
logging.error('Exiting after keyboard interrupt')
logging.error('Exiting after keyboard interrupt')
2 changes: 1 addition & 1 deletion batch_encoder/_encode_webm.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_second_pass(self, encoding_mode, crf=None, threads=4, video_filters='',
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):
Expand Down
10 changes: 7 additions & 3 deletions batch_encoder/_encoding_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -48,14 +51,15 @@ def from_config(cls, config):
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)

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):
Expand Down
2 changes: 1 addition & 1 deletion batch_encoder/_source_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ def apply_audio_resampling(self, audio_filters):
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')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='animethemes-batch-encoder',
version='1.1',
version='1.2',
author='AnimeThemes',
author_email='admin@animethemes.moe',
url='https://github.com/AnimeThemes/animethemes-batch-encoder',
Expand Down

0 comments on commit 071ec5d

Please sign in to comment.