feat: add start-offset validation against file durations
This commit is contained in:
1 parent
e34badd87f
commit
885560ef5f
1 file changed
+18
+18
@@ -439,6 +439,24 @@ _stems = _derive_stems(INPUT_FILES)
|
||||
# ─── Prepare output folder ───
|
||||
os.makedirs(OUT_DIR, exist_ok=True)
|
||||
|
||||
# ─── Validate start offset against file durations ───
|
||||
for _check_idx, _check_file in enumerate(INPUT_FILES):
|
||||
try:
|
||||
_r = subprocess.run(
|
||||
["ffprobe", "-v", "error", "-show_entries", "format=duration",
|
||||
"-of", "default=noprint_wrappers=1:nokey=1", _check_file],
|
||||
capture_output=True, text=True, timeout=10
|
||||
)
|
||||
_dur = float(_r.stdout.strip()) if _r.returncode == 0 else 0
|
||||
_label = "A" if _check_idx == 0 else "B"
|
||||
if _dur > 0 and START_SEC >= _dur:
|
||||
print(f"WARNING: start={START_SEC}s is BEYOND file {_label} duration ({_dur:.1f}s) — extraction will produce empty/silent output!", file=sys.stderr)
|
||||
elif _dur > 0 and START_SEC + DURATION > _dur:
|
||||
_remaining = _dur - START_SEC
|
||||
print(f"WARNING: start={START_SEC}s + duration={DURATION}s exceeds file {_label} ({_dur:.1f}s) — only {_remaining:.1f}s available", file=sys.stderr)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
_audio_stream_selections = [] # track selected stream indices for config
|
||||
|
||||
for _file_idx, INPUT_FILE in enumerate(INPUT_FILES):
|
||||
|
||||
Reference in new issue
Block a user