# @hyperframes/producer
Full HTML-to-video rendering pipeline: capture frames with Chrome's BeginFrame API, encode with FFmpeg, mix audio — all in one call.
## Install
```bash
npm install @hyperframes/producer
```
**Requirements:** Node.js >= 22.19, FFmpeg, and the pinned `chrome-headless-shell`: run `npx hyperframes browser ensure` once, or name a browser in `PRODUCER_HEADLESS_SHELL_PATH`. A cached browser is used only when its files match the pinned build. HDR capture needs a full Chrome named in `HYPERFRAMES_BROWSER_PATH`.
## Usage
### Render a video
```typescript
import { createRenderJob, executeRenderJob } from "@hyperframes/producer";
const job = createRenderJob({
fps: 30,
quality: "standard",
});
await executeRenderJob(job, "./my-project", "./output.mp4", (currentJob) => {
console.log(`${Math.round(currentJob.progress)}%`);
});
```
### Run as an HTTP server
The producer can also run as a render server, accepting render requests over HTTP:
```typescript
import { startServer } from "@hyperframes/producer";
await startServer({ port: 8080 });
// POST /render or /render/stream with projectDir, html, or previewUrl (public HTTPS only) and render options
```
A browser request (one that carries an `Origin` or `Sec-Fetch-Site` header) is accepted
only under an IP address, `localhost` or a `*.localhost` name, so a page that points its
own domain at the server cannot start renders or lint. If browsers reach the server
through a proxy name, list that name in `allowedHosts` or in the comma-separated
`PRODUCER_ALLOWED_HOSTS` variable. Requests without those headers, such as curl or
another service, are unaffected.
Every route except `/health` requires `Authorization: Bearer `. Set the token with
`authToken` or `PRODUCER_AUTH_TOKEN`. If you set none, `startServer` makes one for the run
and writes it to `~/.hyperframes/producer/.token` (or `authTokenFile`, or
`PRODUCER_AUTH_TOKEN_FILE`), readable only by the account that runs the server, and logs
that path. Any local account, container or program can reach a loopback port, so the
server never listens without a token. It listens on `127.0.0.1` unless you pass
`hostname` or set `PRODUCER_HOST`, and it refuses any other address unless you set the
token yourself. `createProducerApp` without `authToken`, and `createRenderHandlers`
always, check no caller: serve them only behind your own authentication.
A request's `projectDir` must resolve, symlinks included, inside
`projectsDir` (`PRODUCER_PROJECTS_DIR`, default: the working directory). Its `entryFile`
must stay inside that project, and `outputPath` must be inside `rendersDir`
(`PRODUCER_RENDERS_DIR`, default: a new private folder in the OS temp dir). `debug: true` is refused unless you set
`allowDebug` or `PRODUCER_ALLOW_DEBUG=1`. `createProducerApp` applies these path and
debug checks by default. `createRenderHandlers`, for mounting the handlers inside your own
trusted service, applies them only with `confineRequests: true`.
Both HTTP routes accept optional `pageMotionBlur: "off"` to disable authored page
motion blur. Omit it to preserve the composition's behavior. Other explicit values
are rejected before a render starts. This is separate from engine sub-frame
`motionBlur` sampling.
### Configuration
`RenderConfig` controls the render pipeline:
| Option | Default | Description |
| ------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `entryFile` | `index.html` | Entry composition inside the project directory. Its authored dimensions set the canvas size. |
| `fps` | required | Frame rate as an integer or exact `{ num, den }` rational. |
| `quality` | required | Encoder preset (`"draft"`, `"standard"`, `"high"`). |
| `pageMotionBlur` | authored setting | Set `"off"` to disable page motion blur; omit to preserve authored behavior. |
| `format` | `"mp4"` | Output container — `"mp4"`, `"webm"`, `"mov"`, `"gif"`, `"png-sequence"`, or `"hls"`. See [Transparent Video Output](#transparent-video-output) and [HLS Output](#hls-output) below. |
| `hlsSegmentSeconds` | `4` | HLS target segment length in whole seconds. Ignored for every other format. |
| `videoFrameFormat` | `"auto"` | Source video frame extraction format — `"auto"`, `"jpg"`, or `"png"`. Use `"png"` for UI recordings, screen captures, and color-sensitive source videos. |
| `chromaSubsampling` | `"420"` | MP4 chroma, `"420"` or `"444"`. `"444"` encodes yuv444p from lossless PNG capture for text/UI masters; SDR MP4 and software encoder only. Many players cannot decode it. |
## Transparent Video Output
The producer can render HTML compositions to formats that carry a **true alpha channel** — not chroma key. The same composition that renders an opaque MP4 renders a layerable overlay when you set `format`.
| `format` | Codec / pixel format | Alpha | Audio | Use case |
| ----------------- | --------------------------------- | ------------------ | ------------------- | --------------------------------------------------------------------------------------- |
| `"mp4"` (default) | H.264 (yuv420p) or H.265 + HDR10 | No | AAC | Streaming, social, default deliverable |
| `"webm"` | VP9 + yuva420p | **True alpha** | Opus | Web playback as overlay (`