diff --git a/README.md b/README.md index b27cc06..50f19f4 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/batch_encoder/__main__.py b/batch_encoder/__main__.py index 0c4f10d..4b5c29d 100644 --- a/batch_encoder/__main__.py +++ b/batch_encoder/__main__.py @@ -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 @@ def main(): try: main() except KeyboardInterrupt: - logging.error('Exiting after keyboard interrupt') + logging.error('Exiting after keyboard interrupt') \ No newline at end of file diff --git a/batch_encoder/_encode_webm.py b/batch_encoder/_encode_webm.py index d79d1b4..513ccd9 100644 --- a/batch_encoder/_encode_webm.py +++ b/batch_encoder/_encode_webm.py @@ -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): diff --git a/batch_encoder/_encoding_config.py b/batch_encoder/_encoding_config.py index afd64f0..e1ff099 100644 --- a/batch_encoder/_encoding_config.py +++ b/batch_encoder/_encoding_config.py @@ -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 @@ 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) @@ -55,7 +59,7 @@ def from_config(cls, config): 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): diff --git a/batch_encoder/_source_file.py b/batch_encoder/_source_file.py index 9e1df34..8354e02 100644 --- a/batch_encoder/_source_file.py +++ b/batch_encoder/_source_file.py @@ -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') diff --git a/setup.py b/setup.py index 659f1ef..413b466 100644 --- a/setup.py +++ b/setup.py @@ -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',