README.md
# Video Production Assistant (AgentRove native agent)
`agentrove.video-production` 0.2.2 · MIT · Node.js >= 20 · no npm dependencies · no network
Published by AgentRove (provisional, configurable name). Package identifiers keep the agentrove prefix for compatibility.
Turns a script (the `script` type, for example the output of AgentRove video-script) into a
production plan and captions, and edits video with **your own FFmpeg**. Planning and captions are
deterministic and derived from your segments and timings: no generative video, voice or image APIs.
Three tools are offline and side-effect free. **`render` is the one tool that executes anything:**
it runs FFmpeg on files inside your media folder, only after you confirm (`"confirm": true`).
## Tools
| Tool | Side effects | What it does |
| --- | --- | --- |
| `plan_production` | none | Shot list (A-roll for hook and call to action; body segments split into shots of at most `max_shot_seconds`, default 6, alternating A-roll and B-roll cutaways), B-roll needs (keywords from the segment text with web addresses removed, or a source card for a sourced claim, each with a rights note), on-screen text plan (hook title, key figures such as `40%`, `9.4 km` or `$1,500` but not bare years, `Source: host` credits for claims with `source_url`, end card, closing sources card for claims that match no segment), aspect-ratio safe-area note, and a CMX3600 EDL (non-drop-frame at 24/25/30/50/60 fps; A-roll on reel `AROLL`, B-roll as video-only placeholders on reel `BROLL` over continuing A-roll audio). |
| `export_captions` | none | SRT and WebVTT from the segments: at most `max_lines` (default 2) lines of `max_chars_per_line` (default 42) per cue, using the fewest cues needed, breaking after sentence or clause punctuation where possible, with balanced line lengths; cues timed by text length within each segment, overlaps fixed, optional `offset_seconds`. Markup tags, ASS overrides, control characters and `-->` are removed; VTT text is entity-escaped. |
| `ffmpeg_commands` | none | **Text only.** Commands for `trim` (stream copy, or `reencode: true` for frame-accurate cuts), `concat` (demuxer with a generated list file, or the concat filter), `burn_captions` (subtitles filter with font size, outline and margin), `fit` (scale + pad or crop to an even width/height, e.g. 1080x1920) and `transcode`. Codecs follow the output extension: `.mp4 .mov .m4v .mkv` = H.264 + AAC, `.webm` = VP9 + Opus. Returns `argv` arrays and a POSIX-shell or PowerShell string; `-n` (never overwrite) unless `overwrite: true`; `executed` is always `false`. |
| `render` | **writes local files** (confirmation required) | **Executes** the same operations with your FFmpeg, in order (a later operation may use an earlier output), and returns ffprobe metadata (container, duration, size, codecs, resolution, frame rate, aspect ratio) for every output. Accepts caption text inline (`subtitles_text`, e.g. `captions_srt` from `export_captions`). |
### render: what it will and will not do
- Runs only after `"confirm": true`. Preview the exact commands with `ffmpeg_commands` first.
- Reads and writes only inside the **media folder**: `AGENTROVE_MEDIA_ROOT` if set, otherwise the
folder the CLI or MCP server was started in. Paths that leave it (including through links) are
refused, and it does not create folders.
- Never overwrites an input of any operation. An existing output is kept unless `"overwrite": true`.
- Checks every input with ffprobe first: it must be an MP4/MOV, Matroska or WebM file with a video
stream; subtitles must be SRT, WebVTT or ASS. Concat inputs are checked for matching codecs or size.
- Starts FFmpeg without a shell, with an argv that passed the option, value and filter allowlist,
`-nostdin`, `-protocol_whitelist file` on every input, and a reduced environment (no API keys).
- Limits: `timeout_seconds` per operation (default 600), `max_output_seconds` (default 900; checked
before running and enforced with `-t`), `max_output_megabytes` (default 1024; enforced with `-fs`).
- On failure it reports the FFmpeg exit code and the last FFmpeg messages, lists which earlier
operations completed, and removes the failed operation's partial output if it created it.
- Caption and concat-list files are written to a private temporary folder and deleted afterwards.
### How generated commands are kept safe
- Commands are built from structured operations, never from free-form arguments.
- Every path is checked: no FFmpeg protocols or URLs (`http:`, `concat:`, `pipe:`, ...; Windows drive
letters are allowed), no leading `-` (option injection), no control characters or line breaks,
expected extensions only (video `.mp4 .mov .mkv .webm .m4v`, subtitles `.srt .vtt .ass .ssa`,
list `.txt`), and the output must differ from every input. `render` also refuses `:` after the
drive letter.
- Every generated argv is validated against an allowlist of options and values (`-ss`, `-t`, `-i`,
`-f concat`, `-safe`, `-c`, `-c:v libx264|libvpx-vp9|copy`, `-c:a aac|libopus|copy`, `-crf`,
`-preset`, `-b:v 0`, `-deadline`, `-cpu-used`, `-row-mt`, `-pix_fmt`, `-movflags`, `-b:a`, `-map`,
`-vf`, `-filter_complex`, `-an`, `-y`/`-n`, `-fs`, `-protocol_whitelist file`, `-loglevel`,
`-hide_banner`, `-nostdin`, `-nostats`) and of filters (`subtitles`, `scale`, `pad`, `crop`,
`setsar`, `concat`, `format`, `fps`). Anything else, such as `-filter_script`, `-f lavfi`,
`movie=` or `drawtext=textfile=`, is refused.
- Filter option values use FFmpeg's documented two-level filtergraph escaping, then shell quoting
(POSIX single quotes, or PowerShell single quotes with typographic quotes doubled too).
## Requirements for render: FFmpeg
`render` uses an FFmpeg you install yourself; this pack does not include or download it.
- Official download page: <https://ffmpeg.org/download.html> (links to builds for Windows, macOS
and Linux; most Linux distributions and Homebrew also package it).
- Needs `ffmpeg` and `ffprobe`, built with libx264 (H.264), libvpx-vp9 and libopus (WebM) and
libass (caption burn-in). `render` checks the build and names any missing encoder or filter.
- Location: set `FFMPEG_PATH` to the absolute path of `ffmpeg` (`ffmpeg.exe` on Windows), or put it
on `PATH`. `ffprobe` is taken from `FFPROBE_PATH`, the same folder as ffmpeg, or `PATH`. Relative
`PATH` entries are ignored. If none is found, `render` fails with `ffmpeg_not_found`.
- Licence: FFmpeg is LGPL 2.1+; builds that include libx264 (most full builds) are GPL. This agent
only runs FFmpeg as a separate program and does not bundle or link it; follow your build's licence
if you redistribute FFmpeg or encoded output commercially (H.264/AAC patent licensing may also apply
in some countries).
## Usage (Node CLI)
```sh
node bin/cli.js --help
node bin/cli.js plan_production --input script.json # {"script": {...}, "fps": 30, "aspect_ratio": "9:16"}
node bin/cli.js export_captions --input script.json # {"script": {...}}
node bin/cli.js ffmpeg_commands --json '{"operations":[{"op":"trim","input":"take1.mp4","output":"hook.mp4","start":0,"end":3}]}'
# Executes FFmpeg (run in the folder that holds your media, or set AGENTROVE_MEDIA_ROOT):
node bin/cli.js render --input render.json # {"confirm": true, "operations": [{"op": "fit", "input": "final.mp4", "output": "vertical.mp4", "width": 1080, "height": 1920}]}
```
On Windows PowerShell, prefer `--input file.json` and pass `"shell": "powershell"` to
`ffmpeg_commands` to get PowerShell-quoted commands. For `concat` with the demuxer in
`ffmpeg_commands`, save the returned `files[].content` as the list file before running the command
(`render` does this for you in a temporary folder).
## Use as an MCP server
```sh
claude mcp add video-production -- node /absolute/path/to/video-production/bin/mcp.js
```
The MCP server's start folder is the media folder for `render` unless `AGENTROVE_MEDIA_ROOT` is set.
`claude-code/SKILL.md` is a Claude Code skill that drives the CLI.
## Testing status
- Node.js (Vitest): `tests/video-production.test.ts` (plan, captions, command text, allowlists,
MCP) and `tests/render.test.ts`.
- `tests/render.test.ts` runs **real FFmpeg** when `FFMPEG_PATH` (or `PATH`) finds it, and skips
those tests with the reason otherwise. AgentRove ran them with FFmpeg 9.1 (gyan.dev essentials
build) on Windows 11 using original synthetic media generated by the test (FFmpeg `testsrc2`
pattern and `sine` tone): captions exported and burned in (verified by comparing pixels),
trim, concat (filter and stream-copy demuxer), fit to 9:16 and 16:9, MP4 (H.264/AAC) and WebM
(VP9/Opus) outputs verified with ffprobe, plus invalid media, a disguised playlist, a genuine
FFmpeg failure, missing FFmpeg, limits, timeouts, overwrite rules, the CLI and MCP stdio.
- Other FFmpeg builds, macOS and Linux have not been tested by AgentRove.
- Not yet verified inside Claude Code or other MCP clients by AgentRove for this version.
## Limitations
- The plan is rule-based: shot splitting, framing, key figures and B-roll keywords come from segment
kinds, timing, patterns and word frequency, not from understanding the content. Treat it as a
starting point.
- The EDL assumes the A-roll recording follows the script timing (source = record timecode); adjust
source timecodes after recording. Drop-frame (29.97) timecode is not supported.
- Caption timing within a segment is proportional to text length, not aligned to speech.
- `render` supports only the five structured operations; there are no overlays, transitions, audio
mixing, colour work or arbitrary filters. Concat needs inputs with the same size and sample aspect
ratio (use `fit` first); the demuxer additionally needs the same codecs.
- VP9 encoding is slow at the default `medium` preset; `ultrafast`/`superfast` use libvpx realtime
mode (faster, larger files).
- Commands are quoted for POSIX shells and PowerShell; `cmd.exe` quoting is not provided (use the
`argv` array with your own tooling instead).