mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-15 22:08:03 +00:00
Three defects in how ffprobe output and the PNG fallback are combined. The cICP fallback was unreachable. `ffprobeColorSpace ?? stillImageMeta ?.colorSpace` discarded the PNG result whenever ffprobe returned ANY colour field — and ffprobe emits color_space "gbr" for every PNG, including a plain rgb24 with no colour metadata. So on the build the parser exists for (reports gbr, does not decode cICP) an HDR PQ PNG resolved colorTransfer "" , isHdrColorSpace() returned false, and the still graded SDR. Now merged per field. hasAlpha's anchor bound to one alternative. In /(^|[^a-z])yuva|rgba|.../ the `|` is looser than concatenation, so (^|[^a-z]) guarded `yuva` and nothing else. The list also omitted abgr, ya8, ya16 and ayuv64, and `gray[a-z0-9]*a` matched only gray8a/gray16a — names FFmpeg renamed to ya8/ya16 in 2013, so dead against modern builds. A ya8 grayscale-plus-alpha PNG reported hasAlpha:false, resolveFrameFormat picked jpg and the overlay flattened to an opaque rectangle. Replaced with the start-anchored form studio-server already uses, extracted as exported pixelFormatHasAlpha so the test asserts the shipped predicate rather than a copy of the pattern. The PNG parse ran eagerly and was discarded. It sat before the first await, so readFileSync plus the CRC walk executed for every file before a single ffprobe was spawned — a caller fanning out over composition.images with Promise.all serialised entirely: 12 4K PNGs took 2649 ms against 170 ms probe-only, 2.5 s of event-loop stall that also blocks Puppeteer IPC. On the happy path the value was then thrown away. Now lazily memoized behind the paths that actually consult it. Tests: 18 pix_fmt cases against the real predicate. Reverting the regex fails 4. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@hyperframes/engine
Seekable web-page-to-video rendering engine built on Puppeteer and FFmpeg.
Framework-agnostic: works with GSAP, Lottie, Three.js, CSS animations, or any web content that implements the window.__hf seek protocol.
Install
npm install @hyperframes/engine
Requirements: Node.js >= 22, Chrome/Chromium (auto-downloaded by Puppeteer), FFmpeg
What it does
The engine opens your HTML composition in a headless Chrome instance, seeks frame-by-frame using Chrome's HeadlessExperimental.beginFrame API, captures screenshots, and encodes them into video with FFmpeg.
Key services
| Service | Description |
|---|---|
| browserManager | Launches and pools headless Chrome instances (chrome-headless-shell) |
| frameCapture | Manages capture sessions — seek, screenshot, buffer lifecycle |
| screenshotService | BeginFrame-based capture with CDP (Chrome DevTools Protocol) |
| chunkEncoder | FFmpeg encoding with chunked concat, GPU detection, faststart |
| streamingEncoder | Pipe frames to FFmpeg in real time (no intermediate PNGs on disk) |
| audioMixer | Parse <audio> elements and mix audio tracks via FFmpeg |
| videoFrameExtractor | Extract frames from <video> elements for compositing |
| parallelCoordinator | Split frame ranges across worker processes |
| fileServer | Serve local HTML files to the browser via Hono |
Usage
import {
acquireBrowser,
createCaptureSession,
initializeSession,
captureFrame,
closeCaptureSession,
} from "@hyperframes/engine";
// 1. Launch browser
const browserLease = await acquireBrowser({ captureMode: "beginFrame" });
// 2. Open a capture session
const session = createCaptureSession({
browser: browserLease.browser,
url: "http://localhost:3000/my-composition.html",
width: 1920,
height: 1080,
fps: 30,
});
await initializeSession(session);
// 3. Capture frames
for (let i = 0; i < totalFrames; i++) {
await captureFrame(session, i, `/tmp/frames/frame-${i}.png`);
}
// 4. Clean up
await closeCaptureSession(session);
await browserLease.release();
Most users should use @hyperframes/producer or the hyperframes CLI instead of calling the engine directly.
Documentation
Full documentation: hyperframes.heygen.com/packages/engine
Related packages
@hyperframes/core— types, parsers, frame adapters@hyperframes/producer— high-level render pipeline built on this enginehyperframes— CLI