From af310d7e3eefd218aa7218ef5a46ab29d388b195 Mon Sep 17 00:00:00 2001 From: Manfred Stock Date: Thu, 22 Jul 2021 22:42:02 +0200 Subject: [PATCH] Add --audio-streams flag to configure number of audio streams for .ts output Since videos with translations appear to require at least as many audio streams in the intro/outro as there are audio streams in the main video, this allows to create intro/outro files for videos with more than one translation (so far, the code already created 2 streams). --- make.py | 4 ++++ renderlib.py | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/make.py b/make.py index 6c0834c..20ea5a0 100755 --- a/make.py +++ b/make.py @@ -56,6 +56,10 @@ Render frames using resvg instead of Inkscape. Usage: ./make.py yourproject/ --resvg ''') +parser.add_argument('--audio-streams', action="store", default=2, type=int, help=''' + Number of audio streams to generate. + Usage: ./make.py yourproject/ --audio-streams 4 + ''') if len(sys.argv) < 2: parser.print_help() diff --git a/renderlib.py b/renderlib.py index 0d749f1..3f28b38 100644 --- a/renderlib.py +++ b/renderlib.py @@ -176,16 +176,18 @@ def rendertask_video(task): cmd = 'cd {0} && '.format(task.workdir) cmd += 'ffmpeg -f image2 -i .frames/%04d.png ' if task.audiofile is None: - cmd += '-ar 48000 -ac 1 -f s16le -i /dev/zero -ar 48000 -ac 1 -f s16le -i /dev/zero ' + audio_input = '-ar 48000 -ac 1 -f s16le -i /dev/zero ' else: - cmd += '-i {0} -i {0} '.format(task.audiofile) + audio_input = '-i {0} '.format(task.audiofile) + cmd += audio_input * args.audio_streams cmd += '-map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 ' if task.audiofile is None: - cmd += '-map 1:0 -map 2:0 ' + audio_map = '-map {0}:0 ' else: - cmd += '-map 1:0 -c:a copy -map 2:0 -c:a copy ' + audio_map = '-map {0}:0 -c:a copy ' + cmd += ''.join(audio_map.format(index + 1) for index in range(args.audio_streams)) cmd += '-shortest -f mpegts "{0}"'.format(task.outfile) elif task.outfile.endswith('.mov'): cmd = 'cd {0} && '.format(task.workdir)