Skip to content

rereel build

Builds an MP4 from a bundle. Video is rendered by Remotion in fixed-size frame chunks. A chunk is re-rendered only when its slice hash changes (see Incremental rendering). In mix_plan audio mode, chunks are rendered muted and the soundtrack is compiled separately (see Audio compilation).

Terminal window
rereel build <reel_dir> [--out <mp4>] [--template-dir <dir>] [--offline] [--storage-config <path>]

What it does (remotion_single / remotion_chapter)

Section titled “What it does (remotion_single / remotion_chapter)”
  1. Reads the bundle. Loads rereel.json, the lockfile (missing = empty), and props.json (required).

  2. Determines the duration, using the first match:

    1. duration_sec > 0 in timing.json (timingFile, default timing.json)
    2. props.duration_sec
    3. props.durationSec
    4. props.durationInFrames / props.fps
    5. props.clip.end_sec - props.clip.start_sec
    6. props.outline.duration_sec

    If none matches, the build fails with exit 2. Then totalFrames = max(1, round(duration × fps)), with fps = video.fps || 30.

  3. Stages the template into <reel_dir>/build/template/:

    • Source directory: --template-dir if given, otherwise resolved from rereel.json template (details).
    • Files are copied, skipping top-level node_modules, .remotion, out, and props.
    • If build/template/node_modules does not exist yet, it is cloned from the source template’s node_modules. If the source has none, it comes from ~/.cache/rereel/node_modules/<template.name>-<sha256(package-lock.json)[0:16] | nolock>/, which is populated on first use by running npm ci (with a lockfile) or npm install with --no-audit --no-fund.
    • <reel_dir>/media/ is copied into build/template/public/media/.
  4. Hydrates media (same as hydrate with the source template dir and --offline), then re-stages so freshly hydrated media lands in public/media/.

  5. Computes the template hash over package.json, remotion.config.*, and every file under src/ of the staged template.

  6. Detects the entry: template.entry (must exist, else exit 2), otherwise the first existing of src/index.ts, src/index.tsx, src/index.js, src/Root.tsx.

  7. Renders chunks. For start = 0, chunkFrames, 2·chunkFrames, …, the chunk covers frames [start, min(totalFrames, start+chunkFrames) − 1] and is written to build/chunks/<SSSSS>-<EEEEE>.mp4 (zero-padded, inclusive end). A chunk is reused when its manifest entry key equals the new slice hash, the file exists, and ffprobe counts the expected number of frames. Otherwise it runs:

    remotion render <entry> <composition> <chunk.mp4> --props <reel_dir>/props.json
    --frames <start>-<end> --concurrency=<video.concurrency|2> --image-format=<video.imageFormat|jpeg>
    --log=error [--muted] [--jpeg-quality=<video.jpegQuality|80>] [...video.remotionArgs]

    --muted is added unless audioMode is remotion. --jpeg-quality is added only for JPEG. The command runs in build/template/ with a 15-minute timeout. After rendering, the frame count must match exactly (else exit 1), and build/chunks/manifest.json is updated after every chunk.

  8. Concatenates chunks with the FFmpeg concat demuxer and -c copy into build/video.muted.mp4 (-an unless audioMode is remotion).

  9. Audio:

    • audioMode: "mix_plan": uses mix_plan.json, or, if absent, a plan derived from props (see deriveMixPlanFromProps). If neither yields anything, the muted video is copied. A missing duration_sec in the plan is filled with the build duration. The plan is compiled with scope chapter for remotion_chapter (no loudness normalization; stems for a later merge) and final otherwise (2-pass loudnorm). The result is muxed with -c:v copy -c:a aac -b:a 192k.
    • remotion / none: the concatenated video is copied to the output.
template.source Resolution
local template.path resolved relative to <reel_dir>. Must contain package.json (exit 2). Missing path → exit 2.
builtin <root>/<template.name>/package.json for root in $REREEL_TEMPLATES_DIR, then ~/.samurai/templates/remotion. Not found → exit 3.
storage template.uri is fetched through template.provider (or default) and extracted into the template cache. The archive can contain package.json at its root or under remotion/ (Kogatana). The root takes precedence when both are present. An already extracted template is reused. Missing uri or package.json → exit 2.
  1. Hydrates the composite bundle itself (no template dir).
  2. For each entry in parts (in order):
    • kind: "chapter": recursively runs build on <reel_dir>/<part.reelDir> with the same --template-dir and --offline, and uses the child’s default output (<child>/build/output.mp4). Chunk counters are summed.
    • kind: "media": uses <reel_dir>/<part.mediaPath>. It must exist, else exit 1.
  3. Probes the video streams before concatenating them into build/final.video.mp4. Compatible streams at the configured dimensions and frame rate are copied. Otherwise, each video is scaled and padded to the configured dimensions, resampled to the target frame rate, and encoded as H.264 before concatenation. Each segment’s video frame count sets its placement, independent of its audio duration.
  4. If audioMode is mix_plan and mix_plan.json exists, compiles it with scope final (a missing duration_sec is taken from the probed video duration) and muxes. Otherwise the muted video is copied as-is. Typically the composite mix_plan.json uses chapters[] to merge each chapter’s stems.
  5. totalFrames is counted from the output file with ffprobe.
Flag Type Default Description
<reel_dir> path (positional) — (required) Bundle directory.
--out path <reel_dir>/build/output.mp4 (composite: <reel_dir>/build/final.mp4) Output MP4 path.
--template-dir path from rereel.json template Use this template directory instead of resolving template. Also passed to chapter builds.
--offline flag off Hydrate without network; fail on any missing or mismatched asset.
--storage-config path lookup rules Storage configuration file.
<reel_dir>/build/
├── template/ # staged Remotion workspace (+ public/media/)
├── chunks/
│ ├── manifest.json # { "chunks": { "<name>.mp4": { key, frames, sha256, renderedAt } } }
│ ├── concat.txt
│ └── 00000-00299.mp4 …
├── video.muted.mp4
├── stems/ # narration.wav bgm.wav sfx.wav brand.wav premix.wav filter_complex.txt mix.json
├── mix.wav
└── output.mp4 # default --out
{
"status": "built",
"reelDir": "/abs/path/reels/ep01",
"outPath": "/abs/path/reels/ep01/build/output.mp4",
"sha256": "c0ffee…",
"totalFrames": 1800,
"fps": 30,
"chunksTotal": 6,
"chunksRendered": 1,
"chunksReused": 5
}
Key Description
outPath Absolute output path.
sha256 SHA-256 of the output MP4.
totalFrames Computed frame count (composite: counted from the output).
fps video.fps.
chunksTotal / chunksRendered / chunksReused Chunk counters (composite: summed over chapter parts).
Code When
0 Built.
1 Chunk frame-count mismatch, composite media part missing, audio asset in mix_plan.json not found, or any hydrate failure.
2 Missing <reel_dir>, rereel.json, or props.json; duration cannot be determined; no template and no --template-dir; entry not found; invalid local/storage template ref; composite without parts; mix plan without positive duration.
3 Builtin template not found, or ffmpeg, ffprobe, Remotion, npm, cp, or tar cannot be spawned.
4 Remotion render, FFmpeg, npm, or tar exited non-zero, or loudnorm measurements could not be parsed.
Terminal window
rereel build ./reels/ep01 --out ./reels/ep01/build/final.mp4

Use a local checkout of the template and stay offline:

Terminal window
rereel build ./reels/ep01 --template-dir ./remotion-template --offline