Skip to content

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.

fix: eval-6 follow-ups -- fade-in-only --fade, export measures platform loudness, cut names the lossless alternative, report language on short jobs (#195)

claude[bot]84d12c4d7421
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5c6b21f..83ad1cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@
## Unreleased
-(nothing yet)
+- Eval iteration 6 follow-ups. `overlay.py --fade` without `--end` no longer fades the overlay out again at the end of the clip (fade-in only; the fade-out belongs to `--end`). `export.py`'s platform presets (youtube / youtube4k / reels / x) measure the written file and report `loudness` with the platform's target plus a `notes` line naming the `loudness.py` call when it is outside the spec, so an agent plans one pass instead of two. `cut.py` reports `lossless_alternative` (the nearest keyframe `--start`) when the snap forced a re-encode. SKILL.md: a one-command job still gets its `Done:`/`Steps:` lines in the user's language.
## 1.5.1
diff --git a/SKILL.md b/SKILL.md
index 13eb029..80024a9 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -239,7 +239,7 @@ commands work with `talk.wav` in place of `talk.mp4`. What changes:
## Report format
-Reply in the language the user wrote their request in — a Japanese request gets a Japanese report, English gets English, Chinese gets Chinese, and so on for any other language. Keep the shape below and the field labels (`Done:`, `Steps:`, `Check:`, `Look:`, `Notes:`) in English (they read like log fields, not prose, and stay recognisable across languages); the sentences around them, any question asked, and any explanation of a judgement call are in the user's language. Never default to English because the tool names and flags happen to be English. A mid-conversation language switch follows the user's latest message, not the first one.
+Reply in the language the user wrote their request in — a Japanese request gets a Japanese report, English gets English, Chinese gets Chinese, and so on for any other language. Keep the shape below and the field labels (`Done:`, `Steps:`, `Check:`, `Look:`, `Notes:`) in English (they read like log fields, not prose, and stay recognisable across languages); the sentences around them, any question asked, and any explanation of a judgement call are in the user's language. Never default to English because the tool names and flags happen to be English. A mid-conversation language switch follows the user's latest message, not the first one. This holds for a one-command job too: a three-second audio trim answered with English labels, numbers and one Japanese word in `Notes:` is an English report; the `Done:` line's own description (what was cut, from where) and `Steps:` are written in the user's language even when the values are technical.
Finish every job with this shape (numbers from `probe.py`/`check.py`, not memory):
diff --git a/references/scripts.md b/references/scripts.md
index 8a67d81..673a1e6 100644
--- a/references/scripts.md
+++ b/references/scripts.md
@@ -55,7 +55,9 @@ keyframes, instant, lossless); if the snapped result deviates more than
`--tolerance` (0.5 s) from the request, that segment is re-encoded automatically
(x264 CRF 18). `--accurate` always re-encodes; `--tolerance -1` never does.
Multiple segments are concatenated in the order given. stderr reports whether
-the result was "lossless stream copy" or "re-encoded".
+the result was "lossless stream copy" or "re-encoded"; when the snap forced a
+re-encode, the result's `lossless_alternative` names the nearest keyframe
+`--start` that would stream-copy instead, so the trade can be offered.
### fit.py — target duration and/or aspect, rotate/flip
```
@@ -534,6 +536,9 @@ playing. `--video` composites a second video as a picture-in-picture layer
input's audio is kept, the PiP layer's own audio is dropped. `--chromakey`
(with `--video`) keys out that colour first for green-screen compositing.
+`--fade S` fades the overlay in at `--start` (or 0); the fade-out happens
+only at `--end`, so a logo with no `--end` stays to the last frame.
+
### sync.py — offset detection, alignment, drift correction
```
sync.py REFERENCE SECOND [--json] [--max-offset 30] [--analyze-seconds 120] [--fix-drift [--drift-window 60]]
@@ -629,7 +634,11 @@ export.py INPUT --preset youtube|youtube4k|reels|x|prores|h265|gif [--fit pad|cr
export.py --list
```
Scales into the preset frame (pad by default), tags BT.709, sets `+faststart`,
-trims to platform maximums (Reels 90 s, X 140 s) unless `--allow-long`.
+trims to platform maximums (Reels 90 s, X 140 s) unless `--allow-long`. It
+does not touch levels: for youtube / youtube4k / reels / x the written file is
+measured and the result's `loudness` (and a `notes` line) says when it is
+outside the platform's LUFS / true-peak spec, naming the `loudness.py` call
+that fixes it -- plan that pass instead of discovering it from `check.py`.
### proxy.py — low-bitrate proxy for analysis/preview
```
diff --git a/scripts/_contract.py b/scripts/_contract.py
index 92dc44e..ebaad60 100644
--- a/scripts/_contract.py
+++ b/scripts/_contract.py
@@ -181,7 +181,8 @@ TOOL_META: Dict[str, Dict[str, Any]] = {
"export": dict(role="execution", inputs=["video asset"], outputs=["delivery artifact in the preset's format"],
required=FF, optional=[{"capability": X264, "when": "preset youtube / youtube4k / reels / x"}, {"capability": AAC, "when": "preset youtube / youtube4k / reels / x / h265 (prores uses pcm_s16le, copy stream-copies, gif has no audio)"},
{"capability": X265, "when": "preset h265"}, {"capability": "encoder:prores_ks", "when": "preset prores"},
- {"capability": "filter:palettegen", "when": "preset gif"}, {"capability": "encoder:gif", "when": "preset gif"}, {"capability": "filter:boxblur", "when": "--pad-fill blur"}],
+ {"capability": "filter:palettegen", "when": "preset gif"}, {"capability": "encoder:gif", "when": "preset gif"}, {"capability": "filter:boxblur", "when": "--pad-fill blur"},
+ {"capability": "filter:loudnorm", "when": "preset youtube / youtube4k / reels / x with audio: the written file is measured against the platform's loudness target (result `loudness`)"}],
video_required=True, audio_only=False, visual=False, verify=["probe", "check"], produces_artifact=True, idempotency="content_equivalent", deterministic=True),
"check": dict(role="verification", inputs=["media artifact"], outputs=["compliance rows JSON on stdout (no file)"],
required=["ffprobe"], optional=[{"capability": "ffmpeg", "when": "loudness rows (default)"}, {"capability": "filter:loudnorm", "when": "loudness rows (default)"}],
@@ -392,6 +393,9 @@ def output_schema(name: str, meta: Dict[str, Any]) -> Dict[str, Any]:
extra = {"results": {"type": "array"}, "processed": {"type": "integer"}, "total": {"type": "integer"}}
elif name == "report":
extra = {"report": {"type": "string"}, "check": {"type": ["object", "null"]}}
+ elif name == "export":
+ extra = {"loudness": {"type": "object", "description": "platform presets with audio: the written file's lufs/tp against the platform's target_lufs/target_tp, ok true when inside the spec"},
+ "notes": {"type": "array", "items": {"type": "string"}}}
elif name == "loudness":
extra = {"measured": {"type": "object", "description": "--measure-only prints the loudnorm measurement instead (input_i, input_tp, input_lra, input_thresh, target_offset)"}}
elif name == "cut":
@@ -399,7 +403,8 @@ def output_schema(name: str, meta: Dict[str, Any]) -> Dict[str, Any]:
"duration_error_ms": {"type": ["number", "null"], "description": "written minus requested, measured by ffprobe (null under --dry-run)"},
"precision": {"enum": ["packet", "sample", "codec_frame", "frame"],
"description": "packet: stream copy on a packet/keyframe boundary; sample: decoded audio trimmed to the sample, lossless output; codec_frame: sample-trimmed then framed by a lossy encoder (priming delay adds to the length); frame: re-encoded video"},
- "reencoded": {"type": "boolean"}}
+ "reencoded": {"type": "boolean"},
+ "lossless_alternative": {"type": ["string", "null"], "description": "when a lossless cut re-encoded because of the keyframe snap: the --start that would stream-copy instead, and how far it is from the request"}}
elif name == "join":
extra = {"mode": {"enum": ["video", "audio"]}, "clips": {"type": "integer"}, "transition": {"type": "string"}, "expected_duration": {"type": "number"},
"sample_rate": {"type": "integer", "description": "audio mode only"}, "channels": {"type": "integer", "description": "audio mode only"},
diff --git a/scripts/cut.py b/scripts/cut.py
index 39860ad..6e100d6 100755
--- a/scripts/cut.py
+++ b/scripts/cut.py
@@ -245,7 +245,11 @@ def main() -> int:
requested_duration=round(expected, 6), output_duration=round(got, 6) if got is not None else None,
duration_delta_seconds=round(error_ms / 1000, 6) if error_ms is not None else None,
mode=mode, keyframe_snapped=keyframe_snapped,
- nearest_keyframes=sorted(NEAREST_KEYFRAMES) if NEAREST_KEYFRAMES else None)
+ nearest_keyframes=sorted(NEAREST_KEYFRAMES) if NEAREST_KEYFRAMES else None,
+ # the trade the caller can offer instead of a re-encode (eval e02: "without losing quality")
+ lossless_alternative=(f"--start {min(NEAREST_KEYFRAMES, key=lambda k: abs(k - segments[0][0])):.3f} lands on a keyframe: "
+ f"stream copy with no re-encode, {abs(min(NEAREST_KEYFRAMES, key=lambda k: abs(k - segments[0][0])) - segments[0][0]):.2f}s off the requested start")
+ if mode == "hybrid" and NEAREST_KEYFRAMES and len(segments) == 1 else None)
return 0
diff --git a/scripts/export.py b/scripts/export.py
index 005dddb..ef54626 100755
--- a/scripts/export.py
+++ b/scripts/export.py
@@ -27,6 +27,7 @@ from pathlib import Path
from typing import Dict, List
from _common import STATE, add_common, apply_common, bt709_tag_args, emit, cfr_args, default_output, die, ffmpeg_base, info, probe, run, validate_color, pad_filters, add_pad_fill_args, fmt_secs
+from check import SPECS as PLATFORMS, measure_loudness
PRESETS: Dict[str, Dict] = {
"youtube": {"w": 1920, "h": 1080, "ext": "mp4", "video": ["-c:v", "libx264", "-preset", "slow", "-crf", "18", "-profile:v", "high", "-pix_fmt", "yuv420p"], "audio": ["-c:a", "aac", "-b:a", "192k", "-ar", "48000"], "max": None, "desc": "1080p H.264, AAC 192k"},
"youtube4k": {"w": 3840, "h": 2160, "ext": "mp4", "video": ["-c:v", "libx264", "-preset", "slow", "-crf", "18", "-profile:v", "high", "-pix_fmt", "yuv420p"], "audio": ["-c:a", "aac", "-b:a", "192k", "-ar", "48000"], "max": None, "desc": "2160p H.264, AAC 192k"},
@@ -40,6 +41,10 @@ PRESETS: Dict[str, Dict] = {
+# which check.py platform a preset targets (its loudness spec is measured after the write)
+PLATFORM_OF = {"youtube": "youtube", "youtube4k": "youtube", "reels": "reels", "x": "x"}
+
+
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("input", nargs="?")
@@ -123,7 +128,24 @@ def main() -> int:
result = probe(output, role="output")
v = result["video"]
info(f"wrote {output} ({fmt_secs(result['duration'])}, {v['width']}x{v['height']}, {v['codec']})")
- emit(output, **({"notes": notes} if notes else {}))
+ extra: Dict[str, object] = {}
+ platform = PLATFORM_OF.get(args.preset)
+ if platform and has_audio and not STATE.dry_run:
+ # Every eval run that exported for a platform then had to come back with loudness.py: the
+ # preset scales and tags but does not touch levels, and only check.py said so. Measure the
+ # written file here so the result names the gap and the caller plans one pass, not two.
+ spec = PLATFORMS[platform]
+ m = measure_loudness(output)
+ if m:
+ ok = abs(m["lufs"] - spec["lufs"]) <= spec["lufs_tol"] and m["tp"] <= spec["tp"]
+ extra["loudness"] = {"lufs": m["lufs"], "tp": m["tp"], "target_lufs": spec["lufs"], "target_tp": spec["tp"], "ok": ok}
+ if not ok:
+ notes.append(f"loudness {m['lufs']:.1f} LUFS / {m['tp']:+.1f} dBTP is outside {platform}'s {spec['lufs']:g} LUFS / {spec['tp']:g} dBTP; "
+ f"run loudness.py -I {spec['lufs']:g} --tp {spec['tp']:g} on this file (or before export)")
+ info("warning: " + notes[-1])
+ if notes:
+ extra["notes"] = notes
+ emit(output, **extra)
return 0
diff --git a/scripts/overlay.py b/scripts/overlay.py
index a73d3f6..dd38bc4 100755
--- a/scripts/overlay.py
+++ b/scripts/overlay.py
@@ -103,7 +103,7 @@ def main() -> int:
ap.add_argument("--margin", type=int, default=24, help="margin from the edges in px (default 24)")
ap.add_argument("--start", help="show from this time (default: whole video)")
ap.add_argument("--end", help="hide after this time")
- ap.add_argument("--fade", type=float, default=0.0, help="fade in/out duration in seconds")
+ ap.add_argument("--fade", type=float, default=0.0, help="fade-in duration in seconds (at --start or 0); the fade-out happens only at --end")
ap.add_argument("--opacity", type=float, default=1.0, help="0..1 (default 1)")
img = ap.add_argument_group("image options")
img.add_argument("--scale", type=int, help="scale the image to this width in px (keeps aspect)")
@@ -188,12 +188,13 @@ def main() -> int:
if args.opacity < 1:
chain.append(f"colorchannelmixer=aa={args.opacity:g}")
if args.fade > 0:
- # no --start/--end: fade in at 0 and out at the end of the video
+ # no --start: fade in at 0. The fade-out only exists when --end names a moment the
+ # overlay leaves; without --end it stays to the last frame ("fade in at the start" is
+ # the common ask, and a matching fade-out at the very end surprised every eval run)
s = start if start is not None else 0.0
- e = end if end is not None else (meta.get("duration") or 0.0)
chain.append(f"fade=t=in:st={s:.3f}:d={args.fade:g}:alpha=1")
- if e > args.fade:
- chain.append(f"fade=t=out:st={e - args.fade:.3f}:d={args.fade:g}:alpha=1")
+ if end is not None and end > args.fade:
+ chain.append(f"fade=t=out:st={end - args.fade:.3f}:d={args.fade:g}:alpha=1")
x, y = position_exprs(args.position, args.margin, text_mode=False)
ov = f"overlay={x}:{y}:format=auto"
if enable:
@@ -249,8 +250,7 @@ def main() -> int:
opts.append(f"fontfile={escape_filter_path(args.font_file)}")
else:
opts.append(f"font='{escape_drawtext(args.font)}'")
- alpha = alpha_expr(args.opacity, start if start is not None else (0.0 if args.fade > 0 else None),
- end if end is not None else ((meta.get("duration") or None) if args.fade > 0 else None), args.fade)
+ alpha = alpha_expr(args.opacity, start if start is not None else (0.0 if args.fade > 0 else None), end, args.fade)
opts.append(f"fontcolor={args.font_color}")
if alpha != "1":
opts.append(f"alpha='{alpha}'")
diff --git a/tests/test_all.py b/tests/test_all.py
index f52a4fd..3253e7f 100644
--- a/tests/test_all.py
+++ b/tests/test_all.py
@@ -2826,11 +2826,15 @@ class FFmpegSkillTests(unittest.TestCase):
proc = script("loudness.py", silent, "-o", OUT / "silent_norm.mp4", expect_fail=True)
self.assertIn("silent", proc.stderr)
- def test_overlay_fade_without_start_end_fades_at_video_edges(self):
+ def test_overlay_fade_without_start_end_fades_in_only(self):
+ """--fade without --end fades in at 0 and stays; the fade-out belongs to --end (eval 6,
+ e03-logo: every "fade in at the start" run had to caveat an unasked-for fade-out)."""
proc = script("overlay.py", self.src, "--image", self.logo, "--fade", "0.5", "--dry-run")
self.assertIn("fade=t=in:st=0.000", proc.stderr)
- self.assertIn("fade=t=out:st=11.500", proc.stderr)
+ self.assertNotIn("fade=t=out", proc.stderr)
self.assertNotIn("\nwrote ", proc.stderr, "dry-run must not claim a file was written")
+ proc = script("overlay.py", self.src, "--image", self.logo, "--fade", "0.5", "--end", "5", "--dry-run")
+ self.assertIn("fade=t=out:st=4.500", proc.stderr)
# ---------------------------------------------------------------- _common
def test_context_is_attribute_only_and_resets(self):
diff --git a/tests/test_contract.py b/tests/test_contract.py
index 874ac5e..83c8b43 100644
--- a/tests/test_contract.py
+++ b/tests/test_contract.py
@@ -1720,6 +1720,29 @@ class ContractTests(unittest.TestCase):
doc = json.loads(tool("fit", self.src, "--aspect", "1:1", "--dry-run", "-o", self.out("v2_dry.mp4"), "--json", env=env).stdout)
self.assertEqual((doc["result_v2"]["probe"], doc["result_v2"]["output"]), (None, doc["output"]))
+ def test_eval6_followups(self):
+ """Eval iteration 6: overlay --fade without --end fades in only; export measures the
+ written file against the platform's loudness spec and says how to fix it; cut names the
+ lossless alternative when the keyframe snap forced a re-encode."""
+ doc = json.loads(tool("overlay", self.src, "--image", self.logo, "--fade", "0.5", "--dry-run", "--json", "-o", self.out("e6_ov.mp4")).stdout)
+ self.assertIn("fade=t=in", doc["commands"][-1]); self.assertNotIn("fade=t=out", doc["commands"][-1])
+ doc = json.loads(tool("overlay", self.src, "--image", self.logo, "--fade", "0.5", "--end", "4", "--dry-run", "--json", "-o", self.out("e6_ov2.mp4")).stdout)
+ self.assertIn("fade=t=out:st=3.500", doc["commands"][-1])
+ doc = json.loads(tool("export", self.src, "--preset", "x", "--fast", "--json", "-o", self.out("e6_x.mp4")).stdout)
+ self.assertEqual((doc["loudness"]["target_lufs"], doc["loudness"]["ok"]), (-14, False), doc["loudness"])
+ self.assertTrue(any("loudness.py -I -14 --tp -1" in n for n in doc["notes"]), doc.get("notes"))
+ norm = self.out("e6_norm.mp4")
+ tool("loudness", self.src, "-I", "-14", "--tp", "-1", "-o", norm)
+ doc = json.loads(tool("export", norm, "--preset", "x", "--fast", "--json", "-o", self.out("e6_x2.mp4")).stdout)
+ self.assertTrue(doc["loudness"]["ok"]); self.assertNotIn("notes", doc)
+ doc = json.loads(tool("export", self.src, "--preset", "x", "--dry-run", "--json", "-o", self.out("e6_xd.mp4")).stdout)
+ self.assertNotIn("loudness", doc)
+ doc = json.loads(tool("cut", self.src, "--start", "2", "--end", "4", "--fast", "--json", "-o", self.out("e6_cut.mp4")).stdout)
+ self.assertEqual(doc["mode"], "hybrid")
+ self.assertIn("--start 0.000", doc["lossless_alternative"])
+ doc = json.loads(tool("cut", self.src, "--start", "0", "--end", "2", "--json", "-o", self.out("e6_cut0.mp4")).stdout)
+ self.assertIsNone(doc["lossless_alternative"])
+
def test_fifth_review_regressions(self):
"""Review 5 (2026-09-12): render refuses an output that is one of its clip sources (it
overwrote the source and said completed); fit --method trim drops a subtitle track whose