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
+34
@@ -410,6 +410,8 @@ _stems = _derive_stems(INPUT_FILES)
|
||||
# ─── Prepare output folder ───
|
||||
os.makedirs(OUT_DIR, exist_ok=True)
|
||||
|
||||
_audio_stream_selections = [] # track selected stream indices for config
|
||||
|
||||
for _file_idx, INPUT_FILE in enumerate(INPUT_FILES):
|
||||
|
||||
# ─── Derive output filenames ───
|
||||
@@ -430,6 +432,7 @@ for _file_idx, INPUT_FILE in enumerate(INPUT_FILES):
|
||||
print(f"[audio] {stem}: selected stream {audio_stream}")
|
||||
else:
|
||||
print(f"[audio] {stem}: no audio selected, skipping audio extraction")
|
||||
_audio_stream_selections.append(audio_stream)
|
||||
|
||||
# ─── Extract video-only (duration s, no audio, CPU FFV1 re-encode) ───
|
||||
# Only apply fps filter if probed fps differs from target (avoid needless re-timing)
|
||||
@@ -489,3 +492,34 @@ for _file_idx, INPUT_FILE in enumerate(INPUT_FILES):
|
||||
|
||||
print(f"-" * 50)
|
||||
print(f"All done. Files are in:", OUT_DIR)
|
||||
|
||||
# ─── Save selected audio stream indices to config.toml ───
|
||||
if len(_audio_stream_selections) >= 2 and CONFIG_PATH and os.path.exists(CONFIG_PATH):
|
||||
try:
|
||||
with open(CONFIG_PATH, "r") as f:
|
||||
cfg_text = f.read()
|
||||
# Update or add audio_stream_a and audio_stream_b in [extract] section
|
||||
import re
|
||||
def _cfg_set(key: str, val) -> str:
|
||||
nonlocal cfg_text
|
||||
pat = re.compile(rf'(^{key}\s*=\s*).*$')
|
||||
replacement = f'{key} = {val}'
|
||||
if pat.search(cfg_text):
|
||||
cfg_text = pat.sub(replacement, cfg_text, count=1)
|
||||
else:
|
||||
# Insert before the next section header or at end of [extract]
|
||||
ins_pat = re.compile(r'(\[audio\])')
|
||||
if ins_pat.search(cfg_text):
|
||||
cfg_text = ins_pat.sub(f'{replacement}\n\n\\1', cfg_text, count=1)
|
||||
else:
|
||||
cfg_text += f"\n{replacement}\n"
|
||||
_cfg_set("audio_stream_a", _audio_stream_selections[0]
|
||||
if _audio_stream_selections[0] is not None else "null")
|
||||
_cfg_set("audio_stream_b", _audio_stream_selections[1]
|
||||
if _audio_stream_selections[1] is not None else "null")
|
||||
with open(CONFIG_PATH, "w") as f:
|
||||
f.write(cfg_text)
|
||||
print(f"[config] saved audio_stream_a={_audio_stream_selections[0]}, "
|
||||
f"audio_stream_b={_audio_stream_selections[1]} → {CONFIG_PATH}")
|
||||
except Exception as e:
|
||||
print(f"[config] warn: could not save stream indices: {e}", file=sys.stderr)
|
||||
Reference in new issue
Block a user