DevTools Logo

Canvas WebM / Animated GIF Exporter

Canvas WebM / GIF Recorder

Animate a canvas and export locally as WebM or deterministic GIF

Canvas animation

A small local animation demonstrates frame timing. No pixels leave your browser.

WebM capture is unavailable in this browser.

Examples

VP9 preference

Input
selectWebmMimeType(["video/webm", "video/webm;codecs=vp8", "video/webm;codecs=vp9"])
Output
"video/webm;codecs=vp9"

Candidates scan in VP9 → VP8 → plain order, so the best available codec wins.

Two-second 24 fps plan

Input
createFramePlan(48, 24, render).length + encodeGif([frame], 2, 2, { fps: 10 }).slice(0, 6)
Output
{ frames: 48, lastTime: 47/24, magic: "GIF89a" }

Frame count is duration × fps with even 1/fps spacing; GIF output starts with GIF89a.

About this tool

Canvas WebM Recorder plans and encodes canvas exports without touching browser APIs: createFramePlan(frameCount, fps, render) builds AnimationFrame entries with index, time (index / fps), and rendered pixels, throwing on non-positive frameCount or fps, so a 2 s clip at 24 fps is exactly 48 frames.

MIME negotiation is pure feature detection via selectWebmMimeType(supported) (alias chooseWebmMimeType): it lowercases the supported list and returns the first of video/webm;codecs=vp9, video/webm;codecs=vp8, video/webm — VP9 preferred over VP8 over plain, null when nothing matches.

GIF fallback is a deterministic GIF89a encoder: rgbaToIndexed maps RGBA to the fixed 16-entry GIF_PALETTE by nearest color, encodeGif writes header, global palette, NETSCAPE2.0 loop block, per-frame delay round(100 / fps) clamped to 1–65535, LZW image data (min code size 4), and a 0x3b trailer. Dimensions must be integers in 1–65535 and each frame must hold exactly width × height indices.

How to use this tool

  1. Plan frames

    Call createFramePlan with frameCount = duration × fps and a render callback per index/time.

  2. Negotiate MIME

    Pass MediaRecorder.isTypeSupported results to selectWebmMimeType — VP9 wins when present.

  3. Export GIF fallback

    Map RGBA through rgbaToIndexed, then encodeGif with width, height, and fps for a loopable GIF89a.

Use cases

Recording canvas animations

Plan fixed-fps frame captures before handing buffers to MediaRecorder.

Picking a WebM codec

Choose VP9, VP8, or plain WebM from isTypeSupported output without user-agent sniffing.

Exporting animated GIFs

Encode small palette-based previews with deterministic LZW output for sharing.

Common mistakes

Mistake:Passing fps 0 or NaN and expecting empty output.

Fix:Non-positive or non-finite fps throws — validate duration × fps before planning or encoding.

Mistake:Feeding RGBA bytes straight to encodeGif.

Fix:Reduce through rgbaToIndexed first; encodeGif expects one palette index per pixel (width × height).

Frequently asked questions

What does this tool do?

It plans canvas captures with createFramePlan (index, time, pixels per frame) and encodes fallbacks with encodeGif, while selectWebmMimeType picks the best WebM codec from feature-detection results without touching browser APIs.

How are codecs, frame counts, and GIF output determined?

MIME scans VP9 → VP8 → plain WebM with null on no match; frame count is duration × fps spaced by 1/fps; GIF output is deterministic GIF89a with a 16-color palette, delay round(100/fps), LZW data, and a 0x3b trailer.

Is my canvas uploaded or stored?

No. Frame planning, palette mapping, and GIF encoding run fully client-side.

Why did planning throw, or GIF encoding fail?

Non-positive frameCount or fps throws fps/frameCount must be positive, dimensions must be integers in 1–65535, and encodeGif needs one palette index per pixel — reduce RGBA via rgbaToIndexed first.

References & standards