/clefcut-cloudflare-remotion-video:clefcut-cloudflare-remotion-videofrom clefcut-cloudflare-remotion-video
Runs staged quality checks on Remotion videos using Cloudflare CLEF and CLAIRIC models. Uses a 4-layer cost model with local ffmpeg measurements, cheap model reads, and agent eyes only on disagreements.
Ships in clefcut-cloudflare-remotion-video. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
ClefCut runs staged quality checks on a rendered Remotion video: free local measurements on every frame, cheap Cloudflare model reads on the frames that matter, and agent eyes only where those two disagree. The QA design is adapted from SageCut by Levanto Labs (MIT).
| Layer | What runs | Cost |
|---|---|---|
| 1. Local checks | Frame extraction and measurements with ffmpeg (black/blank, frozen, flash, ink) plus free local OCR (tesseract.js or system tesseract) | Free, offline, nothing uploaded |
| 2. CLEF reads frames | Cloudflare CLEF answers yes/no (noul), option-pick (choice), and rating (score) questions about frames | Cents per thousand frames (estimate) |
| 3. CLAIRIC extracts | Cloudflare CLAIRIC pulls typed values (text, numbers, dates, lists) out of frames | Cents per thousand frames (estimate) |
| 4. Agent eyes | Three subagent critics see ≤32 selected frames; the main agent opens a frame only when a model answer and a local measurement disagree | The expensive layer — keep it rare |
Why layers: each layer is at least an order of magnitude cheaper than the one above it. An agent that opens every frame of a 30-second video spends more tokens than every model call combined, so layers 1–3 exist to keep layer 4 rare.
The two-widths rule for text (stated once; load-bearing, inherited from SageCut):
test/ frames written at
the test width (layers 2–3). Never pay to re-verify what a free check
already measured.templates/env.example into the project's .env file (or
~/.clefcut/.env for all projects) and have the user fill it in.CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN (the
token needs Workers AI permission — Workers AI - Read, plus Edit unless it
was created from the dashboard template). Optional: CLEFCUT_GATEWAY_ID
(route through an AI Gateway), CLEFCUT_FFMPEG (explicit ffmpeg path).node "<skill-dir>/scripts/video-qa.mjs" doctor and fix everything it
reports before any other command. Once per machine/install, also run
node "<skill-dir>/scripts/video-qa.mjs" verify <render>.mp4 on any real
render — it proves the whole pipeline (probe, frames, check, synthesize,
compare, dry rate gate) works on this machine and footage.node "<skill-dir>/scripts/video-qa.mjs" <cmd> from
the user's Remotion project root. Never use npx for the tool itself
(npx remotion ... for rendering is fine).| Command | What it does |
|---|---|
doctor | Check env vars, ffmpeg, and text-engine availability. Run it first. --ping makes one clef-flash call to verify the token. |
frames | Extract frames from the render. Native video width by default (no rescale) — full-resolution read frames for OCR and CLEF; --width W rescales. --fps samples, --frames A-B selects a 0-based frame-accurate range. --test-width N (default 350) also writes test/ frames for legibility questions; --safe shorts|tiktok|reels|creator (requires --test-width) also writes safe/ frames — the test-width frames with translucent red boxes over the platform's UI occlusion zones (the ui_occlusion question reads these; the zone numbers live in one place, the SAFE_ZONES table in the script); --diff also writes diff/ difference images for pop/abrupt-change questions; --sheet also writes sheet.png, an 8-column contact sheet for staging-order questions. manifest.artifacts records which exist. |
check | Free local measurements on every frame: black/blank, frozen, flash, and ink (almost nothing drawn — the fraction of pixels deviating more than --ink-threshold, default 12, from the frame's median luma; below 0.005 is a finding). The ink floor is a starting-point heuristic — tune --ink-threshold per project, and declare designed sparse frames (intro cards, fades) in --declared so blackouts and holds suppress them. Writes findings.json. --declared declared.json suppresses findings that match declared intentional edits, ink included (see below). |
compare | Fix-round proof image: two PNGs become one same-height side-by-side PNG (the taller input is scaled to the shorter height), or two frame dirs become one combined side-by-side contact sheet of matching frame numbers plus a JSON index mapping left/right files. No text is burned in; the JSON carries the mapping. |
text | Read on-screen text with --engine local, clairic, or auto. Writes text.json. |
ask | Send frames plus a question file (--questions, starting from the 9-question templates/questions.example.json) to CLEF, batched at ≤4 images and ≤6 MiB per request, with --controls. Writes answers.json. |
extract | Typed extraction from frames with CLAIRIC via a --fields file. Writes extract.json. |
synthesize | Build free positive controls (black, ghost, 96px left-edge shift) from the run's own frames, plus a controls.json with trips mapped to the default bank ids. |
verify | Real-footage self-test of the tool itself: runs the tool's own pipeline (probe → frames with --test-width --safe → check → synthesize → compare → dry rate gate) in a temp dir on any render and prints PASS/FAIL/SKIP per step; exit 1 on any FAIL. Run it once per machine/install to prove the pipeline on real footage. The rate step is SKIP without Cloudflare credentials; no network unless credentials exist and --ping is passed. |
npx remotion render <id> out/<name>.mp4 --codec h264 --crf 17 --color-space bt709.--test-width, --diff,
--sheet, and — when the delivery target is a short-form feed —
--safe <platform> artifacts as the question bank needs.--declared for intentional edits. Findings carry measurements.templates/questions.example.json),
with positive controls in their own requests (--controls). ask takes
one input and one question file per invocation, so the bank runs as ONE
PASS PER ARTIFACT (main frames, test/, diff/, safe/, and a per-sheet
dir for staging_order) — see references/workflow.md step 7; the cost
gate is per pass.opened.json.--out per range; see
references/workflow.md), then write the final report.The full loop (schedule check, controls, opened.json fields, report format) is
in references/workflow.md. Read it before the first full run.
Frozen, black, flash, and ink findings are cross-checked against the project's
DECLARED cuts, holds, blackouts, and effects before they become findings. Run
check --declared declared.json and every finding that matches a declared
range is suppressed — moved to suppressed in findings.json with the
declaring reason and excluded from the exit code. Declared design is not a
defect. The declared.json format and how to derive it from the Remotion
schedule/source: references/workflow.md.
CLEF returns ONE answer per question PER REQUEST, and a request carries a
batch of up to 4 frames. The script auto-isolates any batch that fails or
escalates — it re-asks that batch one frame per request — so the final
answers.json rows are per-frame with the true frame number. But an
escalation raised during a batch sweep may come from the isolation pass, not
the original batch; both passes are recorded in usage.
Every command writes a file that can be quoted instead of retyping numbers:
| File | From | What to read |
|---|---|---|
findings.json | check | Free measurements per frame — the ground truth for reconciliation |
text.json | text | Engine used, each frame's OCR text and confidence |
answers.json | ask | Per-frame answer rows (fail/escalate/pass), severity, unreliable flag, usage |
extract.json | extract | Typed values with p_null and confidence per field |
compare.png + its .json | compare | Before/after proof image and the JSON index mapping left/right files |
opened.json | Agent | Every frame the agent opened and why (see references/workflow.md) |
frames artifacts live in the frames dir as frame_%06d.png plus, per the
flags used: test/ (test-width), safe/ (safe-zone), diff/ (difference),
and sheet.png — recorded in manifest.json under artifacts. The test/,
safe/ and diff/ subdirs each carry their own minimal manifest.json, so
asking about a range extract's subdirs reports true frame indices.
Cost lines come from the usage objects in these files. Any cost number not
traceable to a usage object is an estimate and must say so.
| Engine | Cost | Strengths | Weaknesses |
|---|---|---|---|
local | Free, offline | tesseract.js (npm i -D tesseract.js) or system tesseract; reads at full resolution; nothing is uploaded | Weaker on stylized fonts, low contrast, and rotated or animated text |
clairic | ~$0.10 per million input tokens, no output charge | Nothing to install; a confidence and p_null per field; handles stylized and low-contrast text | Frames are uploaded; the model is in Preview and its behavior may change |
auto | Free when a local engine is installed; CLAIRIC pricing otherwise | The engine is chosen ONCE per run — local when a local engine is installed, otherwise CLAIRIC for the whole run (never a per-frame fallback); the run report states which engine produced the results | Costs money for the whole run whenever no local engine is available |
Ask the user which engine to use when a project starts; default to auto.
The two-widths rule applies regardless of engine: integrity = local + full
resolution; legibility = model + test width.
These rules are load-bearing. Breaking them is how a cheap QA becomes a surprise bill.
--yes (or CLEFCUT_YES=1) above 240 frames. The
agent must still state the estimate to the user and get the OK before
running. Example form: "300 frames ≈ 154k tokens ≈ $0.04 on clef, $0.006 on
clef-flash (estimate)."usage fields of completed runs.Worked token math and per-model details: references/clef.md and
references/clairic.md.
A row of "pass" answers proves nothing if the model cannot see the defect class at all. Before trusting a model run:
synthesize:
a black frame (trips dead_frame), a ghost double-image — the two most
different consecutive frames blended 50/50 (trips overlap) — and a frame
with 96px cut off the left edge (trips text_integrity). The emitted
controls.json already maps these trips to the default bank ids; re-map
them only when the bank uses different ids. Extra ffmpeg recipes (freeze,
edge cut) are in references/question-bank.md.ask --controls <dir> —
controls travel in their OWN requests, one control per request, never mixed
with real frames, and are excluded from the main tally.Model answers reduce to a 0–1 defect probability; a probability at or above
the question's pass line is a fail (and a finding), a probability in the band
just below it escalates, escalate_only ids never fail on their own, null
answers escalate, and choice answers escalate below the fixed 0.5 confidence
floor. The ONE authoritative copy of these rules — thresholds, margin,
defect-direction convention, choice floor — lives in
references/question-bank.md.
CLEFCUT-CRITIC-<run-id> as the first line of every critic prompt. The
run id comes from the current run folder.Show this text if the user asks what the critics see:
The critics do not scroll through the whole video. Every frame was measured locally for free, and the flagged and sampled frames were read by CLEF first. The critics then look only at the ≤32 frames the run selected.
| File | Load it before... |
|---|---|
references/clef.md | any ask run — models, prices, request schema, response shapes, retries, token math |
references/clairic.md | text --engine clairic or extract — field types, response shape, Preview caveats |
references/ai-gateway-and-mcp.md | routing through an AI Gateway or calling the Cloudflare API MCP server |
references/question-bank.md | composing or editing questions, pass lines, or positive controls |
references/workflow.md | running the full loop, writing opened.json, or writing the final report |
references/ai-gateway-and-mcp.md (opens in a new tab)references/clairic.md (opens in a new tab)references/clef.md (opens in a new tab)references/question-bank.md (opens in a new tab)references/workflow.md (opens in a new tab)scripts/video-qa.mjs (opens in a new tab)templates/env.example (opens in a new tab)templates/questions.example.json (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub secondsky/claude-skills --plugin clefcut-cloudflare-remotion-videoOther plugins' skills for the same job