ClientSideExporter class provides browser-based export functionality for Helios compositions. It captures frames and audio, encodes them using WebCodecs, and outputs video files or images.
Installation
The exporter is included in the@helios-project/player package:
Basic usage
Constructor
HeliosController
required
Controller instance connected to the composition.
Methods
export(options)
Exports the composition to a video file or image.'mp4' | 'webm' | 'png' | 'jpeg'
default:"mp4"
Output format. Use
mp4 or webm for video, png or jpeg for single-frame images.number
Output video width in pixels. If omitted, uses composition width. Scales the canvas/DOM during capture.
number
Output video height in pixels. If omitted, uses composition height.
number
default:"5000000"
Video bitrate in bits per second. Higher values = better quality, larger file size.
string
default:"video"
Filename without extension. Extension is added automatically based on format.
'auto' | 'canvas' | 'dom'
default:"auto"
Capture mode.
auto attempts canvas first, falls back to DOM. canvas captures the canvas element directly. dom renders the entire document.string
default:"canvas"
CSS selector for the canvas element when using canvas mode.
boolean
default:"true"
Whether to burn captions into the video frames.
object
Caption appearance customization:
color(string) - Text color (default:'white')backgroundColor(string) - Background color (default:'rgba(0, 0, 0, 0.7)')fontFamily(string) - Font family (default:'sans-serif')scale(number) - Font size as fraction of video height (default:0.05)
(progress: number) => void
required
Progress callback. Called with values from 0.0 to 1.0 as export progresses.
AbortSignal
Abort signal to cancel the export. Connect to an AbortController.
Promise<void> - Resolves when export completes and download begins.
Throws: Error if export fails or is aborted.
saveCaptionsAsSRT(cues, filename)
Saves captions as an SRT file.SubtitleCue[]
required
Array of subtitle cues with
index, startTime, endTime, and text properties.string
required
Filename for the SRT file (include
.srt extension).Export formats
MP4 video
- Codec: H.264 (AVC)
- Audio codec: AAC
- Best browser support
- Recommended for web delivery
WebM video
- Codec: VP9
- Audio codec: Opus
- Better compression than MP4
- May have limited browser support on some platforms
PNG image
- Captures the current frame as a lossless PNG
- Useful for thumbnails or poster images
JPEG image
- Captures the current frame as a JPEG
- Smaller file size than PNG
- Lossy compression
Capture modes
Auto mode (recommended)
Attempts canvas capture first, falls back to DOM if canvas is not accessible:Canvas mode
Captures directly from a canvas element (fast, efficient):- Composition must render to a canvas
- Canvas must be accessible (same-origin)
DOM mode
Captures the entire document using DOM-to-bitmap rendering (slower, more flexible):- Compositions without canvas
- HTML/CSS-based animations
- SVG content
Caption rendering
Burn captions into video
Export captions as separate SRT file
Progress tracking
Abort handling
Playback range export
Export only a portion of the composition:Full example: Export UI
Performance tips
- Use canvas mode when possible - Much faster than DOM mode
- Lower resolution for previews - Export at lower resolution for quick previews
- Adjust bitrate - Higher bitrate = better quality but larger files and longer encoding
- Minimize DOM complexity - Simpler DOMs render faster in DOM mode
- Close VideoFrames - Always close captured frames to avoid memory leaks
Browser compatibility
Requires:- WebCodecs API (Chrome 94+, Edge 94+)
- OffscreenCanvas (Chrome 69+, Firefox 105+)
- MediaRecorder API for encoding
- Safari (WebCodecs not available)
- Older browsers