Renderer class provides local video rendering capabilities for Helios compositions. It captures frames from a browser instance and encodes them to video using FFmpeg.
Basic usage
Create a renderer instance and call therender method:
Renderer options
TheRendererOptions interface defines the configuration for rendering:
Required options
Output video width in pixels
Output video height in pixels
Frames per second for the output video
Duration of the composition in seconds
Render mode
The rendering mode:
'canvas': Captures frames by converting the first<canvas>element to a data URL using WebCodecs. Best for canvas-based animations.'dom': Captures frames by taking a screenshot of the entire viewport. Best for CSS/DOM-based animations.
CSS selector to find the canvas element in ‘canvas’ mode. Supports Shadow DOM.
CSS selector to find the target element in ‘dom’ mode. If provided, the screenshot will be limited to this element. Supports deep selection across Shadow DOM boundaries.
Video encoding
The video codec to use for final output (e.g.,
'libx264', 'libx265', 'libvpx-vp9', 'copy')The pixel format for the output video
Constant Rate Factor for quality control. Lower values mean better quality. Range varies by codec (typically 0-51 for H.264).
Encoding preset (e.g.,
'ultrafast', 'fast', 'medium', 'slow', 'veryslow')Video bitrate (e.g.,
'5M', '1000k'). If provided, overrides CRF for some codecs.Intermediate capture
The codec to use for intermediate capture in ‘canvas’ mode with WebCodecs:
'vp8': Widely supported, good performance'vp9': Better compression, higher quality'av1': Best compression, requires newer hardware/browsers'avc1.4d002a': H.264 High Profile
The image format to use for intermediate capture in ‘dom’ mode, or as a fallback in ‘canvas’ mode if WebCodecs is not available
The quality of the intermediate image (0-100). Only applicable if
intermediateImageFormat is 'jpeg'.The number of frames between keyframes (GOP size) when using WebCodecs in ‘canvas’ mode. Defaults to 2 seconds worth of frames (fps * 2).
Audio configuration
Path to an audio file to include in the output video
Array of audio tracks to mix with the video. Can be simple file paths or configuration objects.
The audio codec to use. Defaults to
'aac' (or 'libvorbis' for WebM)Audio bitrate (e.g.,
'128k', '192k')Advanced options
The frame to start rendering from. Useful for rendering a range of frames (distributed rendering).
The exact number of frames to render. If provided, this overrides
durationInSeconds for calculating loop limits.Path to an SRT file to burn into the video. Note: This requires video transcoding (
videoCodec cannot be 'copy').Optional props to inject into the composition. These will be available as
window.__HELIOS_PROPS__.Seed for the deterministic random number generator
Timeout in milliseconds to wait for the frame to stabilize (e.g., loading fonts, images, custom hooks)
Path to the FFmpeg binary. Defaults to the binary provided by
@ffmpeg-installer/ffmpeg.Hardware acceleration method to use for FFmpeg (e.g.,
'cuda', 'vaapi', 'qsv', 'videotoolbox', 'auto')Preference for using WebCodecs hardware acceleration in ‘canvas’ mode:
'hardware': Prioritize hardware-accelerated codecs'software': Prioritize software-based codecs (useful for deterministic testing)'disabled': Disable WebCodecs entirely and fall back to image capture
Whether to mix the audio from the input video (stream 0:a) into the output. Useful for multi-pass rendering.
Browser configuration
Configuration for the Playwright browser instance:
Audio track configuration
For advanced audio mixing, use theAudioTrackConfig interface:
Example with audio tracks
Job options
Therender method accepts optional job configuration:
Callback for progress updates. Receives a number between 0 and 1.
An AbortSignal to cancel the rendering process
Path to save the Playwright trace file (zip). If provided, Playwright tracing will be enabled for the session.
Example with progress tracking
Rendering workflow
Navigate to composition
The browser navigates to the composition URL and injects
inputProps if provided via window.__HELIOS_PROPS__.Initialize time driver
Based on the mode, either
CdpTimeDriver (canvas) or SeekTimeDriver (DOM) is initialized to control time.Prepare render strategy
The selected strategy (Canvas or DOM) prepares for capture:
- Preloads fonts and images
- Validates target element exists
- Initializes WebCodecs encoder (canvas mode)
- Scans for audio tracks in the DOM
Spawn FFmpeg process
FFmpeg is spawned with arguments generated by
FFmpegBuilder, which handles:- Video input format (H.264, IVF, or image2pipe)
- Audio track mixing and filtering
- Output encoding parameters
Capture loop
For each frame:
- Set the composition time using the time driver
- Capture the frame using the render strategy
- Write the frame data to FFmpeg’s stdin
- Report progress via callback
GPU acceleration
Helios automatically attempts to use GPU acceleration at multiple levels:Browser GPU acceleration
The renderer enables GPU acceleration in Chromium with these flags:--use-gl=egl: Use EGL for OpenGL--ignore-gpu-blocklist: Override GPU blocklists--enable-gpu-rasterization: Enable GPU rasterization--enable-zero-copy: Enable zero-copy texture uploads
WebCodecs hardware encoding
In canvas mode, Helios uses the WebCodecs API for hardware-accelerated encoding:- H.264 (AVC) - Best hardware support
- VP9 - Good quality/compression
- AV1 - Best compression (requires newer hardware)
- VP8 - Fallback option
FFmpeg hardware acceleration
For the final encoding step, you can specify FFmpeg hardware acceleration:hwAccel values:
'cuda': NVIDIA CUDA'vaapi': Video Acceleration API (Linux)'qsv': Intel Quick Sync Video'videotoolbox': Apple VideoToolbox (macOS)'auto': Let FFmpeg choose
The renderer validates that the requested hardware acceleration method is available in your FFmpeg build. If not available, a warning is logged.
Diagnostics
Use thediagnose() method to check browser and FFmpeg capabilities:
Error handling
The renderer captures and propagates errors from:- Page crashes
- Console errors
- FFmpeg failures
- Abort signals