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: output-path mistakes are kind input before ffmpeg runs; batch default outdir no longer doubles a relative folder (#185)
claude[bot]afb6ddf713f9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 66c10b3..53096ac 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,7 +4,8 @@## Unreleased-(nothing yet)+- An output that names a directory, or whose directory does not exist, is refused as `kind: input` before ffmpeg runs (it was `OUTPUT_INVALID` after the run, or the muxer's ENOENT as `kind: ffmpeg`).+- `batch.py` with a relative folder no longer doubles it in the default output directory (`bdir/bdir/out`).## 1.4.10diff --git a/scripts/_common.py b/scripts/_common.pyindex 03048a6..d0f873b 100755--- a/scripts/_common.py+++ b/scripts/_common.py@@ -437,6 +437,20 @@ def refuse_output_is_input(output: str, *inputs: str) -> None:f"(the result would replace the source) -- choose a different --output/-o path", kind="input")+def _check_output_path(cmd: Sequence[str]) -> None:+ """An output whose directory does not exist, or that names a directory, is a caller mistake:+ say so as `kind: input` before ffmpeg runs, instead of the muxer's "No such file or directory"+ as `kind: ffmpeg` (which reads as an encoder failure) or an `OUTPUT_INVALID` after the fact."""+ output = cmd[-1]+ if output == "-" or output.startswith("pipe:") or output.startswith("-"):+ return+ if os.path.isdir(output):+ die(f"output {output!r} is a directory; pass a file path (e.g. {os.path.join(output, 'result.mp4')!r})")+ parent = os.path.dirname(os.path.abspath(output))+ if not os.path.isdir(parent):+ die(f"output directory {parent!r} does not exist; create it first (this tool never creates directories)")++def _check_existing_output(cmd: Sequence[str]) -> None:"""An output path that already exists is someone's file: a previous result, a source theagent mis-named, a deliverable from another run. ffmpeg's -y (which every command carries so@@ -522,6 +536,7 @@ def run(cmd: Sequence[str], *, quiet: bool = False, check: bool = True) -> subpris_ffmpeg = _is_ffmpeg(cmd)if is_ffmpeg:_check_no_overwrite_input(cmd)+ _check_output_path(cmd)_check_existing_output(cmd)STATE.commands.append(_cmdline(cmd))if not quiet:diff --git a/scripts/batch.py b/scripts/batch.pyindex e2638c0..292e00b 100755--- a/scripts/batch.py+++ b/scripts/batch.py@@ -144,7 +144,7 @@ def main() -> int:args = ap.parse_args()apply_common(args)- folder = Path(args.folder)+ folder = Path(args.folder).resolve() # relative 'bdir' used to become bdir/bdir/out once joined with the default outdirif not folder.is_dir():die(f"not a folder: {folder}")try:diff --git a/tests/test_contract.py b/tests/test_contract.pyindex a3ef3c4..7f8ce51 100644--- a/tests/test_contract.py+++ b/tests/test_contract.py@@ -1494,6 +1494,33 @@ class ContractTests(unittest.TestCase):if ps is not None:self.assertEqual(ps.stdout.strip(), "", "an ffmpeg is still running on the output")+ def test_output_directory_mistakes_are_kind_input(self):+ """Fourth review, P2: `-o some/dir` was OUTPUT_INVALID after ffmpeg ran and `-o missing/dir/x.mp4`+ was `kind: ffmpeg` from the muxer's ENOENT, both reading as encoder failures. Both are caller+ mistakes and are refused before ffmpeg runs, under --dry-run too."""+ d = self.out("a_directory"); d.mkdir(exist_ok=True)+ for out, needle in ((d, "is a directory"), (self.out("no_such_dir") / "x.mp4", "does not exist")):+ for extra in ((), ("--dry-run",)):+ proc = tool("fit", self.src, "--aspect", "1:1", "--json", "-o", out, *extra, check=False)+ self.assertNotEqual(proc.returncode, 0)+ doc = json.loads(proc.stdout)+ self.assertEqual(doc["error"]["kind"], "input", doc)+ self.assertIn(needle, doc["error"]["message"])++ def test_batch_default_outdir_is_inside_the_folder_once(self):+ """Fourth review, P2: `batch.py bdir --recipe r.json` with a relative folder wrote to+ bdir/bdir/out because the default outdir (folder / "out") was joined with the folder again."""+ import batch as batch_mod # noqa: E402+ bdir = self.out("bdir"); bdir.mkdir(exist_ok=True)+ shutil.copyfile(self.src, bdir / "clip.mp4")+ recipe = self.out("batch_recipe.json")+ recipe.write_text(json.dumps({"glob": "*.mp4", "steps": [["fit.py", "{in}", "--aspect", "1:1", "-o", "{out}"]]}), encoding="utf-8")+ proc = subprocess.run([sys.executable, str(SCRIPTS / "batch.py"), "bdir", "--recipe", str(recipe), "--dry-run", "--json"],+ cwd=str(self.work), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)+ self.assertEqual(proc.returncode, 0, proc.stderr[-400:])+ self.assertFalse((bdir / "bdir").exists(), "outdir was doubled")+ self.assertTrue((bdir / "out").is_dir(), "default outdir is <folder>/out")+def test_cut_segments_refuses_output_equal_to_input(self):"""Fourth review, P0: `cut.py in.mp4 --segments 0-1,2-3 -o in.mp4` replaced the sourcewith the 2 s join. The run() guard compares the ffmpeg command's -i paths with its output,@@ -1686,7 +1713,9 @@ class ContractTests(unittest.TestCase):def test_ffmpeg_failures_are_loud(self):doc = self._fails("color", self.src, "--lut", self.badlut, "--fast", "-o", self.out("g1.mp4"), kind="ffmpeg")self.assertTrue(any("ffmpeg" in c for c in doc["commands"]), "the failing command is reported")- self._fails("loudness", self.wav, "-o", self.work / "no_such_dir" / "g2.wav", kind="ffmpeg")+ # a missing output directory is the caller's mistake, refused before ffmpeg runs (kind input+ # since 1.4.10; it used to surface as the muxer's ENOENT, kind ffmpeg)+ self._fails("loudness", self.wav, "-o", self.work / "no_such_dir" / "g2.wav", kind="input")self._fails("cut", self.src, "--start", "1", "--end", "3", "-o", self.out("g3.txt")) # unknown containerself.assertFalse(self.out("g1.mp4").exists())