Skip to content

heygen-com/hyperframes-vercel-template

Repository files navigation

HyperFrames on Vercel

Preview HTML-based video compositions in the browser and render MP4s server-side — on Vercel. Powered by Vercel Sandbox for rendering and Vercel Blob for output storage.

HyperFrames is an open-source video rendering framework: write HTML + CSS + GSAP, get a reproducible MP4.

Template preview showing the UI 3D Reveal composition playing in the browser

Live demo: hyperframes-on-vercel.vercel.app

Deploy

Deploy with Vercel

Deploying provisions a Vercel Blob store; BLOB_READ_WRITE_TOKEN is injected automatically. Sandbox auth is handled at runtime via VERCEL_OIDC_TOKEN — no extra setup.

What this template does

  • Preview a bundled composition (ui-3d-reveal) in the browser using <hyperframes-player>, the zero-dependency web component from @hyperframes/player.
  • Render the composition to an MP4 by POSTing to /api/render. The route restores a pre-baked Vercel Sandbox, runs hyperframes render, uploads the MP4 to Vercel Blob, and returns a public URL.

Authoring happens locally. This template ships with one pre-authored composition. To build your own, use the HyperFrames CLI on your machine:

npx hyperframes init my-video
cd my-video
npx hyperframes preview   # live-reload editor in your browser

Then swap it into this template (see Swapping the composition below).

Architecture

 Browser                   Vercel Functions (node)         Vercel Sandbox (Firecracker microVM)
┌──────────────────┐      ┌────────────────────────┐      ┌──────────────────────────────────┐
│ <hyperframes-    │ ───▶ │ /api/render            │ ──▶  │ (restored from snapshot, or      │
│  player>         │      │  - read composition    │      │  freshly provisioned in dev)     │
│ preview iframe   │      │  - writeFiles to sbox  │      │                                  │
│                  │      │  - runCommand: render  │      │  hyperframes render composition  │
│                  │ ◀──  │  - readFileToBuffer    │ ◀──  │    (Chromium + ffmpeg-static)    │
│                  │ url  │  - put() → Vercel Blob │  mp4 │                                  │
└──────────────────┘      └────────────────────────┘      └──────────────────────────────────┘

The build-time snapshot

Cold render of a 20s composition is ~70 seconds. Most of that time is the actual Chromium render — not setup — because we pre-bake a sandbox snapshot at build time instead of installing dependencies on every request.

scripts/create-snapshot.ts runs as part of next build:

  1. Spin up a fresh node22 sandbox
  2. dnf install Chromium system libraries (nss, libXcomposite, pango, …)
  3. npm install hyperframes ffmpeg-static
  4. Symlink ffmpeg-static/ffmpeg to /usr/local/bin/ffmpeg
  5. npx hyperframes browser ensure to download chrome-headless-shell
  6. sandbox.snapshot({ expiration: 7 days }) and write the snapshot ID to a pointer blob at snapshot-cache/<deployment_id>.json

At render time, lib/sandbox.ts' restoreOrCreate reads the pointer blob, restores a sandbox from the snapshot in ~100 ms, writes the composition files, and runs hyperframes render. In non-production (local vercel dev) it falls back to a fresh setup automatically.

Why Vercel Sandbox (and not a regular serverless function)

Vercel Functions cap at 300s and 50 MB compressed bundle — HyperFrames needs a full Chromium + FFmpeg at runtime, which busts the bundle limit. Vercel Sandbox is the purpose-built primitive for this workload: an Amazon Linux 2023 Firecracker microVM with sudo-level package installs, up to 5 hours of runtime, and up to 8 vCPUs (we use 4).

With 4 vCPUs, hyperframes render --workers auto launches 3 parallel Chrome workers, cutting the render time roughly 2× vs. the single-worker default.

Local development

npm install
npm run dev

Browser preview works locally out of the box. The /api/render route needs Vercel Sandbox auth — run vercel env pull .env.local after linking the project to get VERCEL_OIDC_TOKEN locally, or use vercel dev.

Project structure

app/
  api/render/route.ts    # POST → restore sandbox, render, upload to Blob
  page.tsx               # Preview + "Render" button
  layout.tsx
  globals.css
lib/
  sandbox.ts             # Snapshot-aware wrapper around @vercel/sandbox
scripts/
  create-snapshot.ts     # Build-time: pre-bake the sandbox snapshot
public/
  compositions/
    ui-3d-reveal/        # The bundled example composition
      index.html
      compositions/*.html

Swapping the composition

  1. Drop your composition bundle into public/compositions/<your-name>/.
  2. Update PREVIEW_COMPOSITION_DIR at the top of lib/preview.ts (used by both preview and render).
  3. Optionally update COMPOSITION_WIDTH / COMPOSITION_HEIGHT at the top of app/page.tsx to match your composition's dimensions.

Pricing

Vercel Sandbox pricing — Pro plans include $20/mo in Sandbox credit. At ~70s per render on 4 vCPUs, that covers roughly a hundred renders/month of the bundled 20-second example. Snapshot storage (the ~650 MB snapshot per deployment) is included in Sandbox pricing.

License

Apache-2.0 — same license as HyperFrames itself.

Links

About

Next.js template for HyperFrames — preview HTML video compositions and render MP4s on Vercel Sandbox

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors