rereel: Video-as-Code Toolkit for Remotion & AI Agents - mathru.net | 使用Flutter/Unity进行应用开发/音乐及视频制作/素材分发
2026-12-04

rereel: Video-as-Code Toolkit for Remotion & AI Agents

When you combine Remotion with AI coding agents (Claude Code, Codex, Cursor, etc.) to produce and iterate on videos, you quickly run into a different class of bottlenecks than in typical software codebases:

  • Committing PNG frames, uncompressed WAV narrations, B-roll clips, and rendered MP4s quickly balloons .git to gigabytes
  • Fixing a single typo in a caption invalidates the entire Remotion render instead of re-rendering only the affected chunk
  • Trimming silences or retakes by destructively slicing WAV files makes frame-accurate tweaks painful and hard to undo

To solve these problems by treating video projects like software repositories ( Video as Code ), I built rereel ( @mathrunet/rereel ) , an open-source toolkit for Remotion and AI agents. Alpha v0.1.0 is now available on GitHub along with its documentation site.

Note: @mathrunet/rereel is an independent community-built tool designed to work with Remotion and is not officially affiliated with or endorsed by Remotion AG. The npm package is currently being prepared for release; in the meantime, you can clone the GitHub repository and run it immediately.

Teach Your AI Agent the rereel Workflow

rereel is designed so AI coding agents can reliably run a tight inspect → edit JSON → validate → incremental build loop. The repository ships with a dedicated agent skill ( skills/rereel/SKILL.md and references/cli.md ) that can be installed in one line.

Claude Code (Plugin)

/plugin install rereel --marketplace mathrunet/rereel

On older Claude Code versions, add the marketplace first:

/plugin marketplace add mathrunet/rereel
/plugin install rereel@rereel

Codex, Cursor, and Other Agents (skills CLI)

npx skills add mathrunet/rereel

Once installed, you can simply ask your agent:

Change the caption in scene s03 to "Ship it on Monday", rebuild reels/ep01 , and tell me how many chunks re-rendered.

Core Idea: Keep Only Tiny JSON + Lockfiles in Git

Just as web projects keep package.json and package-lock.json in Git while ignoring node_modules/ and dist/ , rereel separates a video project into its Source of Truth (SoT) and gitignored build artifacts .

reels/ep01/
├── rereel.json        # Template reference, resolution, FPS, chunk size, slice preset
├── rereel.lock.json   # SHA-256 hashes and storage URIs for all external media
├── props.json         # Timeline cuts, scenes, and captions passed to Remotion
├── mix_plan.json      # Non-destructive narration, BGM, and SFX mix plan
├── timing.json        # Optional timing metadata
├── captions.srt       # Subtitles
├── media/             # .gitignore (hydrated on demand from rereel.lock.json)
└── build/             # .gitignore (chunk cache, audio stems, final MP4)

Only tens of kilobytes of plain text live in Git. Binary assets, intermediate chunk caches, and final MP4s stay gitignored and are restored or rebuilt on demand via hydrate and build .


Four Core Mechanisms

1. Lockfile-Based Media Hydration ( freeze / hydrate / validate )

rereel freeze scans a working directory for media references, computes SHA-256 digests, uploads assets to your configured storage provider, and emits rereel.lock.json .

Storage providers are pluggable via rereel.storage.json :

Provider Type Purpose
local-cache Shared cache on the local machine
s3 AWS S3, Cloudflare R2, or GCS (lightweight SigV4 signing)
http Read-only static asset URLs
command Integration with any custom asset DB or CLI ( storeCommand / resolveCommand )

rereel hydrate restores binaries into media/ and verifies every file's SHA-256 on restore. rereel validate checks lockfile integrity, references, and leaked absolute paths in CI without needing media files on disk.

2. Slice-Hashed Incremental Chunk Rendering ( build )

Instead of rendering an entire video monolithically, rereel splits the timeline into chunks defined by video.chunkFrames in rereel.json (default 300 frames; 150 frames in the included example).

For each [startFrame, endFrame] chunk, rereel computes a slice hash from:

  • Shared video configuration (resolution, FPS, template, etc.)
  • Cuts, scenes, captions, and overlays intersecting that frame range (selected according to slicePreset )
  • SHA-256 digests of the media referenced in that chunk

Unchanged chunks are reused from cache in 0 seconds; only affected chunks are re-rendered by Remotion. Finally, all chunks are concatenated losslessly with ffmpeg -c copy , so fixing a caption in the intro no longer triggers a full re-encode.

3. --muted Video Rendering + Single-Pass FFmpeg Audio Compilation

Rendering audio per chunk and concatenating chunks often introduces audible clicks and glitches at chunk boundaries.

rereel avoids this by decoupling video and audio pipelines completely:

  1. Each Remotion chunk is rendered video-only with --muted
  2. All audio tracks are compiled from mix_plan.json in a single FFmpeg filtergraph pass (non-destructive narration trimming and placement, automatic BGM ducking during speech intervals, SFX peak normalization, and 2-pass EBU R128 loudnorm )
  3. The concatenated video stream and compiled audio stream are muxed into the final MP4

To remain compatible with FFmpeg 7.1+ (including FFmpeg 9 where -filter_complex_script was removed), rereel uses -/filter_complex with a fallback for older versions.

4. Non-Destructive Silence & Retake Cutting ( cut-retakes ) + AI-Friendly Ripple Patching ( inspect / patch )

Given a raw narration WAV or MP4, rereel cut-retakes combines Whisper word timestamps ( --asr-json ) with FFmpeg silencedetect to remove false starts, stumbles, fillers, and long silences. The original file is never modified; kept utterances are emitted as segment descriptors ( tempo_ratio = 1.0 ) ready for mix_plan.json .

rereel also provides structured commands so AI agents can edit timelines safely:

  • rereel inspect <dir> : Emits a compact JSON summary of cuts, captions, audio, and duration
  • rereel patch <dir> ripple-shift : Atomically shifts downstream timestamps across props.json , mix_plan.json , timing.json , and captions.srt
  • rereel patch <dir> trim-segment / swap-asset : Trims individual segments or swaps media while updating rereel.lock.json

Try Incremental Rebuilds with the Bundled Example

Requirements: Node.js 22+ and ffmpeg` / `ffprobe in PATH . Clone the repository and build the included minimal example:

git clone https://github.com/mathrunet/rereel.git
cd rereel
npm ci
npm run build
node dist/cli.js build examples/minimal-short

examples/minimal-short is a 1080×1920, 30fps, 10-second (300 frames) reel with chunkFrames: 150 (2 chunks) and a self-contained local Remotion template.

The first build writes examples/minimal-short/build/output.mp4 . Next, edit only hook.text (0–3s) in examples/minimal-short/props.json and rebuild:

{
  "hook": {
    "type": "question",
    "text": "Still re-rendering the whole video for one typo?",
    "start_sec": 0,
    "end_sec": 3
  }
}
node dist/cli.js build examples/minimal-short

Only the first chunk (frames 0–149) re-renders, while the second chunk (frames 150–299) is reused directly from cache.


Alpha v0.1.0 establishes the core workflow ( freeze , hydrate , validate , build , inspect , patch , cut-retakes ), the AI agent skill, and the documentation site at https://rereel.dev .

Next up are publishing @mathrunet/rereel to npm and expanding template integrations based on real production pipelines. If you build videos with Remotion or AI agents, check out the repository and docs—issues and feedback are very welcome.