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
number
required
Output video width in pixels
number
required
Output video height in pixels
number
required
Frames per second for the output video
number
required
Duration of the composition in seconds
Render mode
'canvas' | 'dom'
default:"'canvas'"
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.
string
default:"'canvas'"
CSS selector to find the canvas element in ‘canvas’ mode. Supports Shadow DOM.
string
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
string
default:"'libx264'"
The video codec to use for final output (e.g.,
'libx264', 'libx265', 'libvpx-vp9', 'copy')string
default:"'yuv420p'"
The pixel format for the output video
number
Constant Rate Factor for quality control. Lower values mean better quality. Range varies by codec (typically 0-51 for H.264).
string
default:"'fast'"
Encoding preset (e.g.,
'ultrafast', 'fast', 'medium', 'slow', 'veryslow')string
Video bitrate (e.g.,
'5M', '1000k'). If provided, overrides CRF for some codecs.Intermediate capture
string
default:"'vp8'"
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
'png' | 'jpeg'
default:"'png'"
The image format to use for intermediate capture in ‘dom’ mode, or as a fallback in ‘canvas’ mode if WebCodecs is not available
number
The quality of the intermediate image (0-100). Only applicable if
intermediateImageFormat is 'jpeg'.number
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
string
Path to an audio file to include in the output video
(string | AudioTrackConfig)[]
Array of audio tracks to mix with the video. Can be simple file paths or configuration objects.
string
The audio codec to use. Defaults to
'aac' (or 'libvorbis' for WebM)string
Audio bitrate (e.g.,
'128k', '192k')Advanced options
number
default:"0"
The frame to start rendering from. Useful for rendering a range of frames (distributed rendering).
number
The exact number of frames to render. If provided, this overrides
durationInSeconds for calculating loop limits.string
Path to an SRT file to burn into the video. Note: This requires video transcoding (
videoCodec cannot be 'copy').Record<string, any>
Optional props to inject into the composition. These will be available as
window.__HELIOS_PROPS__.number
default:"0x12345678"
Seed for the deterministic random number generator
number
default:"30000"
Timeout in milliseconds to wait for the frame to stabilize (e.g., loading fonts, images, custom hooks)
string
Path to the FFmpeg binary. Defaults to the binary provided by
@ffmpeg-installer/ffmpeg.string
Hardware acceleration method to use for FFmpeg (e.g.,
'cuda', 'vaapi', 'qsv', 'videotoolbox', 'auto')'hardware' | 'software' | 'disabled'
default:"'hardware'"
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
boolean
default:"false"
Whether to mix the audio from the input video (stream 0:a) into the output. Useful for multi-pass rendering.
Browser configuration
BrowserConfig
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:
(progress: number) => void
Callback for progress updates. Receives a number between 0 and 1.
AbortSignal
An AbortSignal to cancel the rendering process
string
Path to save the Playwright trace file (zip). If provided, Playwright tracing will be enabled for the session.
Example with progress tracking
Rendering workflow
1
Initialize browser
The Renderer launches a Chromium instance with GPU acceleration flags:
2
Navigate to composition
The browser navigates to the composition URL and injects
inputProps if provided via window.__HELIOS_PROPS__.3
Initialize time driver
Based on the mode, either
CdpTimeDriver (canvas) or SeekTimeDriver (DOM) is initialized to control time.4
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
5
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
6
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
7
Finalize encoding
After all frames are captured:
- Call
strategy.finish()to flush any remaining data - Close FFmpeg stdin
- Wait for FFmpeg to complete encoding
- Clean up browser and temporary resources
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