"""Lays the sound of an edit again under a finished render, picture untouched: py -I remix.py edl.py film.mp4""" import importlib.util import os import subprocess import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import cut # noqa: E402 spec = importlib.util.spec_from_file_location("edl", sys.argv[1]) edl = importlib.util.module_from_spec(spec) sys.modules["edl"] = edl spec.loader.exec_module(edl) film = sys.argv[2] wav = film + ".remix.wav" song = cut.decode(getattr(edl, "TRACK", cut.TRACK)) * getattr(edl, "TRACK_GAIN", 1.0) cut.mix(song, cut.Clock(edl.KEEP), getattr(edl, "SFX", []), wav) tmp = film + ".remix.mp4" subprocess.run(["ffmpeg", "-y", "-v", "error", "-i", film, "-i", wav, "-map", "0:v", "-map", "1:a", "-c:v", "copy", "-c:a", "aac", "-b:a", "320k", "-shortest", "-movflags", "+faststart", tmp], check=True) os.replace(tmp, film) os.remove(wav) print("remixed", film)