mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-14 13:27:13 +00:00
9 optimizations targeting the frame capture hot path (86% of total render time): 1. Enable streaming encode by default — overlaps capture with FFmpeg encoding, eliminating the encode stage as a separate step. Saves ~10% wall time. 2. Multi-page shared browser — screenshot-mode workers share a single Chrome process instead of launching N separate browsers. Eliminates N-1 Chrome startup costs (~2-3s each) and shares GPU/cache across pages. 3. Lower streaming JPEG quality (55 vs 80/95) — intermediate frames piped to FFmpeg are re-encoded, so quality loss is invisible in the final output. Smaller buffers transfer faster over CDP, cutting per-frame capture time. 4. Hardware GPU acceleration — replace forced SwiftShader (software renderer) with native GPU (Metal on macOS, Vulkan on Linux). CSS effects like box-shadow, blur, and transforms render 10-100x faster. Falls back to SwiftShader automatically in Docker/CI where no GPU exists. 5. Optimized seek evaluation — string eval replaces function serialization in the per-frame page.evaluate() call, skipping Puppeteer's serialize + Runtime.callFunctionOn overhead. Removes redundant __hf.seek guard that was already validated during session initialization. 6. FFmpeg multi-threading — adds -threads 0 across all encoding paths (streaming, chunk, extraction) to let FFmpeg auto-parallelize. 7. Parallel audio processing — audio extraction now runs concurrently with frame capture instead of blocking it. Audio uses separate FFmpeg processes that don't compete with Chrome for CPU. 8. Hardware-accelerated video extraction — adds -hwaccel auto for H.264 sources and reduces PNG compression from level 6 to 1 (temp files). 9. Tuned parallelism defaults — more aggressive worker allocation (8 max, 2 cores/worker, 24 min frames/worker) suited to modern hardware. All 494 engine tests pass. No regressions.
@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,
releaseBrowser,
createCaptureSession,
initializeSession,
captureFrame,
closeCaptureSession,
} from "@hyperframes/engine";
// 1. Launch browser
const browser = await acquireBrowser({ captureMode: "beginFrame" });
// 2. Open a capture session
const session = createCaptureSession({
browser: browser.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 releaseBrowser(browser);
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