Local video editor for coding agents: 42 FFmpeg tools with a machine-readable contract and an MCP server, for Claude Code, Cursor and Codex. Cut, captions, reframe, loudness, platform exports. No cloud, no API keys.
Python agent-skillsai-agentsaudio-processingcaptionsclaude-codecodexcoding-agentcursorffmpegloudness-normalizationmcpmcp-servermodel-context-protocolpythonsubtitlestranscodingvideovideo-editingvideo-processingwhisper
fix: render/caption/sequence name every bad input before any work (#287)
Shogo Kajiyamaf22c3a869fbc
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 413c297..344ea7f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,6 +4,13 @@## Unreleased+- The same check-everything-first rule as `join.py --list`, where one bad input used to cost a+ whole run: `render.py` checks every clip source before cutting the first one and names every+ missing, empty or directory source in one refusal (`problems[]`) -- before, a missing clip 7+ surfaced after clips 0-6 were cut, one missing source per rerun. `caption.py --mode mux`+ names every missing extra `--srt` track at once, before any work. `sequence.py` warns when+ frames exist past a gap in the numbering instead of silently stopping at the gap.+## 2.2.0### Addeddiff --git a/scripts/caption.py b/scripts/caption.pyindex ddd85b3..a325bc5 100755--- a/scripts/caption.py+++ b/scripts/caption.py@@ -1146,6 +1146,14 @@ def main() -> int:die(f"--track-title given {len(args.track_title)} times for {len(srt_tracks)} --srt file(s)",kind="input")args.srt = srt_tracks[0][0] if srt_tracks else None+ # 2.2.1: the extra --srt tracks (always inputs; the first may be written by --text or+ # --transcribe) are checked up front, every missing one named together, before any work.+ # Dry-run plans on files earlier steps have not written yet, as join.py does.+ missing_srt = [{"index": i, "path": p, "reason": "missing"}+ for i, (p, _l) in enumerate(srt_tracks) if i > 0 and not os.path.exists(p)]+ if missing_srt and not STATE.dry_run:+ die(f"{len(missing_srt)} SRT file(s) not found: " + ", ".join(m["path"] for m in missing_srt),+ kind="input", problems=missing_srt)srt_path = args.srtif args.transcribe:if not args.input:diff --git a/scripts/render.py b/scripts/render.pyindex a01fcb9..cabc336 100755--- a/scripts/render.py+++ b/scripts/render.py@@ -930,13 +930,30 @@ def main() -> int:f'{snap_spec.get("to")!r}', kind="input")# ---- clips+ # 2.2.1: every clip source is checked before the first one is cut, and every problem is named+ # in one refusal -- before, clip 7's missing file surfaced after clips 0-6 had been cut, and+ # only the first of several missing sources was reported per run.+ problems: List[Dict[str, Any]] = []+ for i, c in enumerate(clips):+ src = rel(c["src"])+ if not os.path.exists(src): # under --dry-run too: a plan for a missing file is no plan+ problems.append({"index": i, "path": src, "reason": "missing"})+ elif os.path.isdir(src):+ problems.append({"index": i, "path": src, "reason": "a directory, not a file"})+ elif os.path.getsize(src) == 0:+ problems.append({"index": i, "path": src, "reason": "empty (0 bytes)"})+ if problems:+ die(f"{len(problems)} of {len(clips)} clip sources unusable: "+ + "; ".join(f"clip {p['index']}: {p['reason']}: {p['path']}" for p in problems),+ kind="input", problems=problems,+ hint="fix or remove these clips in the project; nothing was cut")+ if not STATE.dry_run:+ for c in clips:+ probe(rel(c["src"])) # an unreadable source stops the run before any clip is cut+parts: List[str] = []for i, c in enumerate(clips):src = rel(c["src"])- if not os.path.exists(src):- die(f"clip {i}: source not found: {src}") # under --dry-run too: a plan for a missing file is no plan- if not STATE.dry_run:- probe(src)needs_cut = c.get("in") is not None or c.get("out") is not Nonepart = str(work / f"clip{i:02d}{mid}")if needs_cut:diff --git a/scripts/sequence.py b/scripts/sequence.pyindex 702de7e..69ecb79 100644--- a/scripts/sequence.py+++ b/scripts/sequence.py@@ -37,6 +37,20 @@ def natural_key(name: str) -> list:return [int(t) if t.isdigit() else t.lower() for t in re.split(r"(\d+)", name)]+def _frames_after(directory: Path, pattern: str, index: int) -> list:+ """Files in `directory` that match printf `pattern` with a number above `index`."""+ m = re.search(r"%0?(\d*)d", pattern)+ if not m:+ return []+ rx = re.compile("^" + re.escape(pattern[:m.start()]) + r"(\d+)" + re.escape(pattern[m.end():]) + "$")+ found = []+ for f in directory.iterdir():+ hit = rx.match(f.name)+ if hit and int(hit.group(1)) > index:+ found.append((int(hit.group(1)), f))+ return [f for _n, f in sorted(found)]++def main() -> int:ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)ap.add_argument("--dir", required=True, help="directory containing the frames")@@ -79,6 +93,12 @@ def main() -> int:if not frames:die(f"first frame not found: {directory / (args.pattern % args.start_number)} (check --pattern / --start-number)")info(f"found {len(frames)} consecutive frames from index {args.start_number}")+ # 2.2.1: frames past a gap in the numbering (one render or export step that failed) used+ # to be dropped silently, giving a shorter video; name the gap and what was left out+ later = _frames_after(directory, args.pattern, i)+ if later:+ info(f"WARNING: frame {args.pattern % i} is missing; {len(later)} later frame(s) "+ f"(from {later[0].name}) are NOT in the sequence -- fill the gap or rename them")frame_meta = probe(str(frames[0]))if not frame_meta.get("video"):diff --git a/tests/test_editing.py b/tests/test_editing.pyindex 8c41960..bc54a1b 100644--- a/tests/test_editing.py+++ b/tests/test_editing.py@@ -619,6 +619,17 @@ class EditingTests(MediaFixtures):else:self.assertGreater(px[2], 100, f"frame {i} should be blue")+ def test_sequence_warns_about_frames_past_a_numbering_gap(self):+ """2.2.1: frame 2 missing used to silently stop the sequence at 2 frames."""+ frames_dir = OUT / "seqframes_gap"+ frames_dir.mkdir(exist_ok=True)+ for i in (0, 1, 3, 4):+ sh("ffmpeg", "-y", "-hide_banner", "-loglevel", "error", "-f", "lavfi", "-i", "color=c=red:s=64x48",+ "-frames:v", "1", frames_dir / f"frame_{i:04d}.png")+ proc = script("sequence.py", "--dir", frames_dir, "--pattern", "frame_%04d.png", "--fps", "5",+ "-o", OUT / "seq_gap.mp4")+ self.assertIn("frame_0002.png is missing; 2 later frame(s)", proc.stderr)+def test_sequence_glob_pattern(self):frames_dir = OUT / "seqframes_glob"frames_dir.mkdir(exist_ok=True)diff --git a/tests/test_orchestration.py b/tests/test_orchestration.pyindex 6f5190f..a3bcf23 100644--- a/tests/test_orchestration.py+++ b/tests/test_orchestration.py@@ -658,9 +658,25 @@ class OrchestrationTests(MediaFixtures):tmpl = OUT / "render_template_valid.json"script("render.py", "--init", tmpl)proc = script("render.py", tmpl, "--dry-run", expect_fail=True) # only REPLACE_ME.mp4 is missing- self.assertIn("source not found", proc.stderr)+ self.assertIn("clip 0: missing: ", proc.stderr)self.assertNotIn("unknown key", proc.stderr)+ def test_render_names_every_unusable_clip_source_before_cutting(self):+ """2.2.1: a missing third clip used to surface after the first two were cut, and a second+ missing clip only on the next run. Now every missing/empty source is named in one refusal."""+ empty = OUT / "render_empty_src.mp4"+ empty.write_bytes(b"")+ body = {"clips": [{"src": "source.mp4", "in": 0, "out": 1},+ {"src": "gone_a.mp4"},+ {"src": str(empty)},+ {"src": "gone_b.mp4"}]}+ proc = script("render.py", self._proj("render_preflight.json", body), "--json", expect_fail=True)+ doc = json.loads(proc.stdout)+ self.assertEqual((doc["status"], doc["error"]["kind"]), ("failed", "input"))+ self.assertEqual([(p["index"], p["reason"]) for p in doc["problems"]],+ [(1, "missing"), (2, "empty (0 bytes)"), (3, "missing")])+ self.assertIn("3 of 4 clip sources unusable", proc.stderr)+def test_emit_and_die_use_the_ctx_they_were_given_for_the_plan(self):"""Review 9: run()/emit()/die() took ctx= but write_plan() and the atexit hook still readSTATE -- emit(ctx=...) wrote an empty plan while reporting one, and die(ctx=...) let thediff --git a/tests/test_picture.py b/tests/test_picture.pyindex 3bb36e2..8ff51c0 100644--- a/tests/test_picture.py+++ b/tests/test_picture.py@@ -821,6 +821,18 @@ class PictureTests(MediaFixtures):"-o", OUT / "dup4.mkv", expect_fail=True)self.assertIn("not found", missing.stderr)+ def test_every_missing_extra_srt_track_is_named_at_once(self):+ """2.2.1: two missing extra tracks are one refusal naming both, not two reruns."""+ srt = OUT / "mux_multi_ok.srt"+ srt.write_text("1\n00:00:00,000 --> 00:00:02,000\nHello\n", encoding="utf-8")+ proc = script("caption.py", self.src, "--mode", "mux", "--srt", f"{srt}:en",+ "--srt", str(OUT / "gone_ja.srt") + ":ja", "--srt", str(OUT / "gone_fr.srt") + ":fr",+ "-o", OUT / "multi_missing.mkv", "--json", expect_fail=True)+ doc = json.loads(proc.stdout)+ self.assertEqual(doc["error"]["kind"], "input")+ self.assertEqual([p["index"] for p in doc["problems"]], [1, 2])+ self.assertIn("2 SRT file(s) not found", doc["error"]["message"])+def test_burn_with_two_srts_refused(self):srt = OUT / "mux_burn2.srt"srt.write_text("1\n00:00:00,000 --> 00:00:02,000\nHello\n", encoding="utf-8")