From 67eaf22ae95f417ca8c2bb2058262201546cca24 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 9 Nov 2023 01:11:51 +0100 Subject: [PATCH] melt bug with a/v timeline not resulting in correct length. render a and v and join after that --- render.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/render.py b/render.py index f7adb21..6c4db1d 100644 --- a/render.py +++ b/render.py @@ -56,6 +56,8 @@ def compose(clips, target=150, base=1024, voice_over=None): 'back': { 'V1': [], 'V2': [], + }, + 'audio-back': { 'A1': [], }, 'audio-center': { @@ -225,7 +227,7 @@ def compose(clips, target=150, base=1024, voice_over=None): blur = seq() * 3 if blur: scene['back']['V1'][-1]['filter']['blur'] = blur - scene['back']['A1'].append({ + scene['audio-back']['A1'].append({ 'duration': clip['duration'], 'src': clip['original'], }) @@ -394,8 +396,8 @@ def render_all(options): if ext == '.wav': cmd += ['vn=1'] else: - if not timeline.endswith("back.kdenlive"): - cmd += ['an=1'] + #if not timeline.endswith("back.kdenlive"): + cmd += ['an=1'] cmd += ['vcodec=libx264', 'x264opts=keyint=1', 'crf=15'] subprocess.call(cmd) if ext == '.wav' and timeline.endswith('audio.kdenlive'): @@ -445,18 +447,34 @@ def render_all(options): "-c", "copy", fragment_prefix / "front-5.1.mp4", ]) + cmds.append([ + "ffmpeg", "-y", + "-nostats", "-loglevel", "error", + "-i", fragment_prefix / "back.mp4", + "-i", fragment_prefix / "audio-back.wav", + "-c:v", "copy", + fragment_prefix / "back-audio.mp4", + ]) for cmd in cmds: #print(" ".join([str(x) for x in cmd])) subprocess.call(cmd) - ft = ox.avinfo(str(fragment_prefix / "front-5.1.mp4"))['duration'] - bt = ox.avinfo(str(fragment_prefix / "back.mp4"))['duration'] - if ft != bt: - print(ft, fragment_prefix / "front-5.1.mp4") - print(bt, fragment_prefix / "back.mp4") - sys.exit(-1) + + for a, b in ( + ("back-audio.mp4", "back.mp4"), + ("front-5.1.mp4", "back.mp4"), + ): + duration_a = ox.avinfo(str(fragment_prefix / a))['duration'] + duration_b = ox.avinfo(str(fragment_prefix / b))['duration'] + if duration_a != duration_b: + print('!!', duration_a, fragment_prefix / a) + print('!!', duration_b, fragment_prefix / b) + sys.exit(-1) + shutil.move(fragment_prefix / "back-audio.mp4", fragment_prefix / "back.mp4") shutil.move(fragment_prefix / "front-5.1.mp4", fragment_prefix / "front.mp4") for fn in ( - "audio-5.1.mp4", "fl.wav", "fr.wav", "fc.wav", "lfe.wav", "bl.wav", "br.wav", + "audio-5.1.mp4", + "audio-back-wav", "back-audio.mp4", + "fl.wav", "fr.wav", "fc.wav", "lfe.wav", "bl.wav", "br.wav", ): fn = fragment_prefix / fn if os.path.exists(fn):