feat(cli): expose png-sequence format

The producer already supports `format: "png-sequence"` end-to-end (see
RenderConfig in renderOrchestrator.ts), but the CLI's VALID_FORMAT
validator rejects it before the flag reaches the producer. Surface it
the same way `mov` and `webm` are surfaced.

Behaviour:
- `--format png-sequence` accepted alongside mp4/webm/mov.
- Auto-output path uses no extension (FORMAT_EXT["png-sequence"] = "")
  since the producer treats outputPath as a directory of frame_NNNNNN.png.
- `printRenderComplete` sums the contained file sizes when outputPath
  is a directory, instead of reporting the platform-dependent inode
  size.
- DockerRenderOptions.format type extended; existing buildDockerRunArgs
  is unchanged because it forwards the string verbatim.

Tests:
- renderLocal forwards `format: "png-sequence"` to createRenderJob.
- buildDockerRunArgs propagates `--format png-sequence` to the
  container.

Docs:
- Rendering guide: format flag table, format comparison table, new
  "PNG sequence (no encoding)" section, "How it works" extended.
- CLI package docs: format flag table updated.
This commit is contained in:
Theodor Kleynhans
2026-05-07 01:56:06 +02:00
parent 0e7e33cf7d
commit 4e28658173
6 changed files with 82 additions and 16 deletions
+12 -3
View File
@@ -116,7 +116,7 @@ Render your Hyperframes [compositions](/concepts/compositions) to MP4, MOV, or W
| Flag | Values | Default | Description | | Flag | Values | Default | Description |
|------|--------|---------|-------------| |------|--------|---------|-------------|
| `--output` | path | `renders/<name>.mp4` | Output file path | | `--output` | path | `renders/<name>.mp4` | Output file path |
| `--format` | mp4, mov, webm | mp4 | Output format (see [Transparent Video](#transparent-video) below) | | `--format` | mp4, mov, webm, png-sequence | mp4 | Output format (see [Transparent Video](#transparent-video) below) |
| `--fps` | 24, 30, 60 | 30 | Frames per second | | `--fps` | 24, 30, 60 | 30 | Frames per second |
| `--quality` | draft, standard, high | standard | Encoding quality preset | | `--quality` | draft, standard, high | standard | Encoding quality preset |
| `--crf` | 051 | — | Override CRF (lower = higher quality). Cannot combine with `--video-bitrate` | | `--crf` | 051 | — | Override CRF (lower = higher quality). Cannot combine with `--video-bitrate` |
@@ -301,19 +301,28 @@ npx hyperframes render --format mov --output overlay.mov
|--------|-------|-------------|---------------|----------|-----------| |--------|-------|-------------|---------------|----------|-----------|
| **MOV** | ProRes 4444 | Yes | CapCut, Final Cut, Premiere, DaVinci, After Effects | No | Large | | **MOV** | ProRes 4444 | Yes | CapCut, Final Cut, Premiere, DaVinci, After Effects | No | Large |
| **WebM** | VP9 | Yes | None (shows black background) | Chrome, Firefox | Small | | **WebM** | VP9 | Yes | None (shows black background) | Chrome, Firefox | Small |
| **PNG sequence** | RGBA PNGs (no encoding) | Yes (lossless) | After Effects, Nuke, Fusion (image-sequence import) | No | Largest |
| **MP4** | H.264 | No | All | All | Small | | **MP4** | H.264 | No | All | All | Small |
<Note> <Note>
**WebM VP9 alpha** is technically supported but all major video editors ignore the alpha channel and render transparent areas as black. Only Chromium-based browsers (Chrome, Arc, Brave, Edge) decode VP9 alpha correctly. Safari does not support it. Use MOV for editor workflows and WebM only for browser-based playback. **WebM VP9 alpha** is technically supported but all major video editors ignore the alpha channel and render transparent areas as black. Only Chromium-based browsers (Chrome, Arc, Brave, Edge) decode VP9 alpha correctly. Safari does not support it. Use MOV for editor workflows and WebM only for browser-based playback.
</Note> </Note>
### PNG sequence (no encoding)
```bash Terminal
npx hyperframes render --format png-sequence --output frames/
```
`--format png-sequence` skips the encoder entirely. The captured RGBA frames are copied to `<output>/frame_NNNNNN.png` (zero-padded) and, if the composition has audio, an `audio.aac` sidecar is written alongside. Use this when you want lossless frames — for compositing in After Effects / Nuke / Fusion, or as the input to a custom encode pipeline. `--output` is treated as a directory and is created if it doesn't exist.
### How it works ### How it works
When you render with `--format mov` or `--format webm`, Hyperframes: When you render with `--format mov`, `--format webm`, or `--format png-sequence`, Hyperframes:
1. Captures each frame as a **PNG with alpha channel** (instead of JPEG for MP4) 1. Captures each frame as a **PNG with alpha channel** (instead of JPEG for MP4)
2. Sets Chrome's page background to transparent via `Emulation.setDefaultBackgroundColorOverride` 2. Sets Chrome's page background to transparent via `Emulation.setDefaultBackgroundColorOverride`
3. Encodes with an alpha-capable codec (ProRes 4444 for MOV, VP9 for WebM) 3. Encodes with an alpha-capable codec (ProRes 4444 for MOV, VP9 for WebM); `png-sequence` skips encoding and writes the captured frames directly
Your composition's HTML should **not** set a `background` on `html` or `body` — leave it unset so the transparent background comes through. Your composition's HTML should **not** set a `background` on `html` or `body` — leave it unset so the transparent background comes through.
+1 -1
View File
@@ -604,7 +604,7 @@ This is suppressed in CI environments, non-TTY shells, and when `HYPERFRAMES_NO_
| Flag | Values | Default | Description | | Flag | Values | Default | Description |
|------|--------|---------|-------------| |------|--------|---------|-------------|
| `--output` | path | `renders/<name>.mp4` | Output file path | | `--output` | path | `renders/<name>.mp4` | Output file path |
| `--format` | mp4, webm, mov | mp4 | Output format (WebM/MOV render with transparency) | | `--format` | mp4, webm, mov, png-sequence | mp4 | Output format (WebM/MOV render with transparency; png-sequence writes a directory of RGBA PNGs) |
| `--fps` | 24, 30, 60 | 30 | Frames per second | | `--fps` | 24, 30, 60 | 30 | Frames per second |
| `--quality` | draft, standard, high | standard | Encoding quality preset (drives CRF/bitrate) | | `--quality` | draft, standard, high | standard | Encoding quality preset (drives CRF/bitrate) |
| `--crf` | 0-51 | — | Override encoder CRF (lower = higher quality). Mutually exclusive with `--video-bitrate` | | `--crf` | 0-51 | — | Override encoder CRF (lower = higher quality). Mutually exclusive with `--video-bitrate` |
+17 -2
View File
@@ -143,6 +143,21 @@ describe("renderLocal browser GPU config", () => {
expect(producerState.createdJobs[0]?.variables).toEqual({ title: "Hello", count: 3 }); expect(producerState.createdJobs[0]?.variables).toEqual({ title: "Hello", count: 3 });
}); });
it("forwards format: png-sequence through to createRenderJob", async () => {
const { renderLocal } = await import("./render.js");
await renderLocal("/tmp/project", "/tmp/frames", {
fps: 30,
quality: "standard",
format: "png-sequence",
gpu: false,
browserGpuMode: "software",
hdrMode: "auto",
quiet: true,
});
expect(producerState.createdJobs[0]?.format).toBe("png-sequence");
});
it("omits variables from createRenderJob when not provided", async () => { it("omits variables from createRenderJob when not provided", async () => {
const { renderLocal } = await import("./render.js"); const { renderLocal } = await import("./render.js");
await renderLocal("/tmp/project", "/tmp/out.mp4", { await renderLocal("/tmp/project", "/tmp/out.mp4", {
@@ -165,7 +180,7 @@ describe("renderLocal browser GPU config", () => {
quality: "standard", quality: "standard",
format: "mp4", format: "mp4",
gpu: false, gpu: false,
browserGpu: false, browserGpuMode: "software",
hdrMode: "auto", hdrMode: "auto",
quiet: true, quiet: true,
entryFile: "compositions/intro.html", entryFile: "compositions/intro.html",
@@ -181,7 +196,7 @@ describe("renderLocal browser GPU config", () => {
quality: "standard", quality: "standard",
format: "mp4", format: "mp4",
gpu: false, gpu: false,
browserGpu: false, browserGpuMode: "software",
hdrMode: "auto", hdrMode: "auto",
quiet: true, quiet: true,
}); });
+40 -9
View File
@@ -1,12 +1,16 @@
import { defineCommand } from "citty"; import { defineCommand } from "citty";
import type { Example } from "./_examples.js"; import type { Example } from "./_examples.js";
import { mkdirSync, readFileSync, statSync, writeFileSync, rmSync } from "node:fs"; import { mkdirSync, readdirSync, readFileSync, statSync, writeFileSync, rmSync } from "node:fs";
export const examples: Example[] = [ export const examples: Example[] = [
["Render to MP4", "hyperframes render --output output.mp4"], ["Render to MP4", "hyperframes render --output output.mp4"],
["Render a specific composition", "hyperframes render -c compositions/intro.html -o intro.mp4"], ["Render a specific composition", "hyperframes render -c compositions/intro.html -o intro.mp4"],
["Render transparent overlay (ProRes)", "hyperframes render --format mov --output overlay.mov"], ["Render transparent overlay (ProRes)", "hyperframes render --format mov --output overlay.mov"],
["Render transparent WebM overlay", "hyperframes render --format webm --output overlay.webm"], ["Render transparent WebM overlay", "hyperframes render --format webm --output overlay.webm"],
[
"Render PNG sequence (RGBA frames for AE/Nuke/Fusion)",
"hyperframes render --format png-sequence --output frames/",
],
["High quality at 60fps", "hyperframes render --fps 60 --quality high --output hd.mp4"], ["High quality at 60fps", "hyperframes render --fps 60 --quality high --output hd.mp4"],
["Deterministic render via Docker", "hyperframes render --docker --output deterministic.mp4"], ["Deterministic render via Docker", "hyperframes render --docker --output deterministic.mp4"],
["Parallel rendering with 6 workers", "hyperframes render --workers 6 --output fast.mp4"], ["Parallel rendering with 6 workers", "hyperframes render --workers 6 --output fast.mp4"],
@@ -47,15 +51,22 @@ import {
const VALID_FPS = new Set([24, 30, 60]); const VALID_FPS = new Set([24, 30, 60]);
const VALID_QUALITY = new Set(["draft", "standard", "high"]); const VALID_QUALITY = new Set(["draft", "standard", "high"]);
const VALID_FORMAT = new Set(["mp4", "webm", "mov"]); const VALID_FORMAT = new Set(["mp4", "webm", "mov", "png-sequence"]);
const FORMAT_EXT: Record<string, string> = { mp4: ".mp4", webm: ".webm", mov: ".mov" }; // `png-sequence` writes a directory of frames rather than a single muxed file,
// so its "extension" is empty — the auto-output path becomes a directory name.
const FORMAT_EXT: Record<string, string> = {
mp4: ".mp4",
webm: ".webm",
mov: ".mov",
"png-sequence": "",
};
const CPU_CORE_COUNT = cpus().length; const CPU_CORE_COUNT = cpus().length;
export default defineCommand({ export default defineCommand({
meta: { meta: {
name: "render", name: "render",
description: "Render a composition to MP4, WebM, or MOV", description: "Render a composition to MP4, WebM, MOV, or a PNG sequence",
}, },
args: { args: {
dir: { dir: {
@@ -89,7 +100,10 @@ export default defineCommand({
}, },
format: { format: {
type: "string", type: "string",
description: "Output format: mp4, webm, mov (MOV/WebM render with transparency)", description:
"Output format: mp4, webm, mov, png-sequence " +
"(MOV/WebM render with transparency; png-sequence writes RGBA frames " +
"to a directory for AE/Nuke/Fusion ingest)",
default: "mp4", default: "mp4",
}, },
workers: { workers: {
@@ -187,10 +201,10 @@ export default defineCommand({
// ── Validate format ───────────────────────────────────────────────── // ── Validate format ─────────────────────────────────────────────────
const formatRaw = args.format ?? "mp4"; const formatRaw = args.format ?? "mp4";
if (!VALID_FORMAT.has(formatRaw)) { if (!VALID_FORMAT.has(formatRaw)) {
errorBox("Invalid format", `Got "${formatRaw}". Must be mp4, webm, or mov.`); errorBox("Invalid format", `Got "${formatRaw}". Must be mp4, webm, mov, or png-sequence.`);
process.exit(1); process.exit(1);
} }
const format = formatRaw as "mp4" | "webm" | "mov"; const format = formatRaw as "mp4" | "webm" | "mov" | "png-sequence";
// ── Validate workers ────────────────────────────────────────────────── // ── Validate workers ──────────────────────────────────────────────────
let workers: number | undefined; let workers: number | undefined;
@@ -464,7 +478,7 @@ export default defineCommand({
interface RenderOptions { interface RenderOptions {
fps: 24 | 30 | 60; fps: 24 | 30 | 60;
quality: "draft" | "standard" | "high"; quality: "draft" | "standard" | "high";
format: "mp4" | "webm" | "mov"; format: "mp4" | "webm" | "mov" | "png-sequence";
workers?: number; workers?: number;
gpu: boolean; gpu: boolean;
/** /**
@@ -976,7 +990,24 @@ function printRenderComplete(outputPath: string, elapsedMs: number, quiet: boole
let fileSize = "unknown"; let fileSize = "unknown";
try { try {
fileSize = formatBytes(statSync(outputPath).size); const stat = statSync(outputPath);
if (stat.isDirectory()) {
// png-sequence output is a directory; sum the contained file sizes so
// the user sees the on-disk footprint of the deliverable rather than
// the platform-specific size of the directory inode itself.
let total = 0;
for (const entry of readdirSync(outputPath, { withFileTypes: true })) {
if (!entry.isFile()) continue;
try {
total += statSync(join(outputPath, entry.name)).size;
} catch {
// skip unreadable entries
}
}
fileSize = formatBytes(total);
} else {
fileSize = formatBytes(stat.size);
}
} catch { } catch {
// file doesn't exist or is inaccessible // file doesn't exist or is inaccessible
} }
@@ -181,6 +181,17 @@ describe("buildDockerRunArgs", () => {
expect(args).toContain("compositions/intro.html"); expect(args).toContain("compositions/intro.html");
}); });
it("forwards --format png-sequence to the container", () => {
const args = buildDockerRunArgs({
...FIXED_INPUT,
outputFilename: "frames",
options: { ...BASE, format: "png-sequence" },
});
const formatIdx = args.indexOf("--format");
expect(formatIdx).toBeGreaterThanOrEqual(0);
expect(args[formatIdx + 1]).toBe("png-sequence");
});
it("forwards --video-bitrate to the container when set", () => { it("forwards --video-bitrate to the container when set", () => {
const args = buildDockerRunArgs({ const args = buildDockerRunArgs({
...FIXED_INPUT, ...FIXED_INPUT,
+1 -1
View File
@@ -21,7 +21,7 @@ export interface DockerRunArgsInput {
export interface DockerRenderOptions { export interface DockerRenderOptions {
fps: 24 | 30 | 60; fps: 24 | 30 | 60;
quality: "draft" | "standard" | "high"; quality: "draft" | "standard" | "high";
format: "mp4" | "webm" | "mov"; format: "mp4" | "webm" | "mov" | "png-sequence";
workers?: number; workers?: number;
gpu: boolean; gpu: boolean;
browserGpu: boolean; browserGpu: boolean;