Communitygithub.com

html-to-video

Convert an animated HTML / SVG / Canvas / JavaScript page with Web Audio sound into a deterministic, frame-accurate MP4 (60 or 90 fps, 1080x1080 square or 1080x1920 vertical) with synchronized audio, using headless Chromium and ffmpeg. Use whenever the user asks to export, render, record, convert or "turn into a video" any HTML animation, SVG motion graphic, logo reveal or web animation into an .mp4 (Reels, Shorts, TikTok, YouTube, a website hero), wants the sound kept, wants a clean version without UI buttons, reports a choppy or out-of-sync screen recording, or asks to verify an exported video's loudness, length or sync.

What is html-to-video?

html-to-video is a Claude Code agent skill that convert an animated HTML / SVG / Canvas / JavaScript page with Web Audio sound into a deterministic, frame-accurate MP4 (60 or 90 fps, 1080x1080 square or 1080x1920 vertical) with synchronized audio, using headless Chromium and ffmpeg. Use whenever the user asks to export, render, record, convert or "turn into a video" any HTML animation, SVG motion graphic, logo reveal or web animation into an .mp4 (Reels, Shorts, TikTok, YouTube, a website hero), wants the sound kept, wants a clean version without UI buttons, reports a choppy or out-of-sync screen recording, or asks to verify an exported video's loudness, length or sync.

Works with✓Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/Haewhynot/Logo-Motion/tree/HEAD/skills/html-to-video

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

HTML to Video

Export an animation that runs in a browser into an MP4 frame by frame, so the result is smooth, identical on every run, and the sound is perfectly aligned.

Why not just screen-record?

A screen recorder samples whatever the machine managed to draw: dropped frames, uneven timing, the mouse cursor, the page's own buttons, and audio that drifts. This exporter never records. It sets the time itself (t = frame * 1000 / fps), asks the page to draw that exact moment, takes a screenshot, and repeats. The audio is rendered offline by the page and merged at the end.

Route A (default): headless browser capture

Works for any page that exposes the motion contract, and for the bundled reference template without edits.

pip install -r "${CLAUDE_SKILL_DIR}/scripts/requirements.txt"
python -m playwright install chromium          # one time, downloads a browser (~150 MB)

# quick look first: PNG stills at chosen times, no video
python "${CLAUDE_SKILL_DIR}/scripts/export_mp4.py" page.html --snapshots 0,2000,5000,9000

# square 1080x1080, 60 fps, with sound
python "${CLAUDE_SKILL_DIR}/scripts/export_mp4.py" page.html -o out-square.mp4 --fps 60

# vertical 1080x1920 (Reels / Shorts / TikTok): the square stage is centred
python "${CLAUDE_SKILL_DIR}/scripts/export_mp4.py" page.html -o out-reel.mp4 --preset vertical --fps 90

Useful options: --scheme dark (page dark mode), --tail-ms 800 (let reverb ring out), --no-audio, --outro (reference template's "draw back in" loop ending), --size 1440x2560 --stage 1440 (custom canvas), --crf 12 (higher quality), --wav-out sound.wav (keep the audio). --help lists all.

The script ends by running verify_mp4.py. Read its report; do not skip it:

python "${CLAUDE_SKILL_DIR}/scripts/verify_mp4.py" out.mp4 --expect-audio --expect-size 1080x1920 --expect-fps 60

What the exporter does for you

  1. Opens the page in headless Chromium with requestAnimationFrame frozen, so the page cannot animate on its own.
  2. Injects CSS that hides the UI (.bar, #hint, [data-export-hide]), centres the stage and resizes it to --stage pixels.
  3. Detects window.__motion (or the reference template's globals), reads the duration and the "static ranges" (stretches where nothing changes, reused instead of re-drawn).
  4. Renders and screenshots every frame, piping PNGs straight into ffmpeg.
  5. Renders the audio inside the page (OfflineAudioContext), converts to 16-bit WAV, trims/pads to the exact video length.
  6. Encodes H.264 yuv420p (BT.709 colour tags, +faststart) and AAC 48 kHz stereo, with a short fade-out so a cut tail does not click.

Make a page exportable

Read references/contract.md. In short, the page needs window.__motion = { duration, render(tMs), audio(lengthMs), staticRanges }, where render is a pure function of time. examples/minimal-contract/index.html at the repo root is a 60-line working example. If the page animates with CSS animations, setTimeout, Date.now() or Math.random(), it must be converted first; the contract file explains how.

Route B: pure-Python re-implementation (fallback)

Use only if a headless browser cannot run (locked-down machine, no Chromium) or the animation must be re-drawn without a browser. You port the timeline, easing, springs and vector shapes into Python and rasterise with Pillow/OpenCV. It is much more work and drifts from the browser's rendering (SVG filters, anti-aliasing). Concepts, pitfalls and the manual MP4-audio muxing technique are in references/route-b-python-port.md. Prefer Route A.

Checklist before delivering

  • verify_mp4.py shows no FAIL; any WARN is understood (loudness, true peak, A/V length).
  • Open the MP4 in a normal player and scrub: no UI, no cursor, no black frames, edges crisp.
  • Sound: starts on the first visual event, no click at the end, not clipping.
  • Right sizes delivered: square for feeds, vertical for Reels/Shorts/TikTok; filenames say which.
  • If the user will upload to a social platform, check that platform's current specs (resolution, fps, loudness, length) rather than trusting this file's defaults.

Common failures (details in references/gotchas.md)

SymptomLikely cause
"No window.__motion contract found"Page does not expose the contract; add it.
Video is one frozen framerender(t) ignores t, or the page re-renders itself from requestAnimationFrame only.
Silent MP4audio missing or threw; check the [warning] line. Page audio must be built with OfflineAudioContext.
Colours look washed out in some playersMissing BT.709 tags. The exporter sets them; do not re-encode without them.
Executable doesn't exist from PlaywrightRun python -m playwright install chromium.
Export takes very long at 90 fpsAdd staticRanges for settled intervals; lower --x264-preset to veryfast while testing.

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

Related Skills