Skip to content

Video Export

Elucim can export animations as video files without any server-side rendering. The export pipeline captures each frame by rendering the SVG scene to a <canvas>, then encodes the frame sequence using the browser’s MediaRecorder API.

The high-level function that renders all frames and triggers a browser download.

import { exportAnimation } from '@elucim/core';
await exportAnimation(svgElement, renderFrame, {
fps: 60,
totalFrames: 300,
width: 1920,
height: 1080,
format: 'webm',
bitrate: 5_000_000,
onProgress: (frame, total) => console.log(`${frame}/${total}`),
});
ParameterTypeDescription
svgElementSVGSVGElementReference to the SVG element to capture
renderFrame(frame: number) => void | Promise<void>Function that updates the scene to a given frame
optionsExportOptionsExport configuration (see below)
OptionTypeDefaultDescription
fpsnumber60Frames per second
totalFramesnumberrequiredNumber of frames to capture
widthnumber1920Output width in pixels
heightnumber1080Output height in pixels
format'webm' | 'mp4''webm'Output format
bitratenumber5_000_000Video bitrate in bits/second
onProgress(frame, total) => voidProgress callback

A React hook that wraps exportAnimation with state management for progress tracking and cancellation.

import { useExport } from '@elucim/core';
function ExportButton({ svgRef, setFrame }) {
const { isExporting, progress, currentFrame, startExport, cancel } = useExport();
const handleExport = () =>
startExport(svgRef.current!, setFrame, {
fps: 60,
totalFrames: 300,
format: 'webm',
});
return (
<div>
{isExporting ? (
<>
<progress value={progress} max={1} />
<span>Frame {currentFrame}</span>
<button onClick={cancel}>Cancel</button>
</>
) : (
<button onClick={handleExport}>Export Video</button>
)}
</div>
);
}
PropertyTypeDescription
isExportingbooleanWhether an export is in progress
progressnumberExport progress from 0 to 1
currentFramenumberThe frame currently being captured
startExport(svg, setFrame, opts) => Promise<void>Begin exporting
cancel() => voidCancel the current export

Export relies on HTMLCanvasElement, MediaRecorder, and the video/webm MIME type. This works in Chrome, Edge, and Firefox. Safari support for MediaRecorder may vary — check caniuse.com for the latest status.