feat: improve audio stream selection and caching
This commit is contained in:
1 parent
4cde4a7332
commit
2aa6d03810
4 files changed
+86
-29
No files matched your search
+8
-15
@@ -75,7 +75,8 @@ def _codec_args(codec: str, out_idx: int) -> list[str]:
|
||||
|
||||
|
||||
def build_ffmpeg_cmd(file_a: str, file_b: str, lag_sec: float, out_path: str) -> list[str]:
|
||||
"""Build ffmpeg command to mux A video + A audio + delayed B audio streams."""
|
||||
"""Build ffmpeg command to mux A video + all A audio + all delayed B audio streams."""
|
||||
a_streams = probe_audio_streams(file_a)
|
||||
b_streams = probe_audio_streams(file_b)
|
||||
|
||||
lag_ms = lag_sec * 1000
|
||||
@@ -99,22 +100,22 @@ def build_ffmpeg_cmd(file_a: str, file_b: str, lag_sec: float, out_path: str) ->
|
||||
if filters:
|
||||
cmd += ["-filter_complex", ";".join(filters)]
|
||||
|
||||
# Map: video from A, all audio from A, all delayed B audio
|
||||
# Map: video from A, ALL audio from A, all delayed B audio
|
||||
cmd += ["-map", "0:v", "-map", "0:a"]
|
||||
for i in range(len(b_streams)):
|
||||
cmd += ["-map", f"[d{i}]"]
|
||||
|
||||
# Codecs: copy video + A's audio, re-encode B's filtered audio with same codec
|
||||
n_a_audio = len(probe_audio_streams(file_a))
|
||||
n_a = len(a_streams)
|
||||
cmd += ["-c:v", "copy"]
|
||||
for i in range(n_a_audio):
|
||||
for i in range(n_a):
|
||||
cmd += [f"-c:a:{i}", "copy"]
|
||||
for i, s in enumerate(b_streams):
|
||||
cmd += _codec_args(s["codec"], n_a_audio + i)
|
||||
cmd += _codec_args(s["codec"], n_a + i)
|
||||
|
||||
# Language metadata for B audio streams (they become the last N audio streams in output)
|
||||
# Language metadata for B audio streams (they start after A's streams)
|
||||
for i, s in enumerate(b_streams):
|
||||
out_audio_idx = n_a_audio + i # 0-based index in output audio streams
|
||||
out_audio_idx = n_a + i
|
||||
if set_german and i == 0:
|
||||
cmd += [f"-metadata:s:a:{out_audio_idx}", "language=ger"]
|
||||
elif s["language"] not in ("und", "unknown", ""):
|
||||
@@ -183,14 +184,6 @@ def main():
|
||||
|
||||
print(f"\nSynced output: {out_path}")
|
||||
|
||||
# Auto-launch verify_sync in full mode
|
||||
verify_script = os.path.join(os.path.dirname(os.path.abspath(__file__)), "verify_sync.py")
|
||||
if os.path.exists(verify_script):
|
||||
verify_cmd = [sys.executable, verify_script, "--config", args.config or "config.toml",
|
||||
"--lag", f"{args.lag:.6f}", "--mode", "full"]
|
||||
print(f"Launching verify: {' '.join(verify_cmd)}")
|
||||
subprocess.Popen(verify_cmd)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user