@videoflow/renderer-server
Render VideoJSON to an MP4 file or buffer from Node using Playwright + ffmpeg.
Classes
ServerRenderer
Methods
constructor
(videoJSON: VideoJSON): ServerRendererParameters
| Name | Type | Description |
|---|---|---|
videoJSON | VideoJSON |
Returns
ServerRenderercleanup
(): Promise<void>Release all resources: browser context, temporary files, and shared browser.
Returns
Promise<void>listLayerTypes
(): string[]Every external layer type registered on this instance.
Returns
string[]registerLayerType
(type: string, descriptor: ServerLayerTypeModuleDescriptor): voidRegister (or replace) an external layer type for this render. ```ts const renderer = new ServerRenderer(videoJSON); renderer.registerLayerType('custom', { modulePath: '/absolute/path/to/custom-layer-type.js', exportName: 'default', }); await renderer.renderVideo(options); ``` `modulePath` must be an **absolute** local filesystem path to a browser-compatible module exporting a `{ runtime, propertiesDefinition }` descriptor. The module is bundled into the renderer page script and registered on the in-page `BrowserRenderer` before its first frame — runtime classes are functions and cannot be passed through `page.evaluate` or Playwright's structured serialization, so bundling is the only way across the realm boundary. Lifecycle: register after construction and **before** `renderVideo()` / `renderFrame()` / `renderAudio()`, i.e. before the headless page is opened. Registering afterwards throws.
Parameters
| Name | Type | Description |
|---|---|---|
type | string | |
descriptor | ServerLayerTypeModuleDescriptor |
renderAudio
(): Promise<Buffer<ArrayBufferLike> | null>Render the full audio track and return it as a WAV Buffer. Opens the headless page on first call, then renders all audio layers into a single WAV buffer via the in-page BrowserRenderer.
Returns
Promise<Buffer<ArrayBufferLike> | null>renderFrame
(frame: number): Promise<Buffer<ArrayBufferLike>>Render a single frame and return it as a JPEG screenshot Buffer. Opens the headless page on first call, then renders the requested frame via the in-page BrowserRenderer.
Parameters
| Name | Type | Description |
|---|---|---|
frame | number | The frame number to render. |
Returns
Promise<Buffer<ArrayBufferLike>>renderVideo
(options: ServerRenderOptions): Promise<string | Buffer<ArrayBufferLike>>Render the loaded project. Picks the encoding pipeline based on `options.ffmpeg`; defaults to the in-browser export path. This is the primary entry point when using external layer types — register them on the instance first, then call this: ```ts const renderer = new ServerRenderer(videoJSON); renderer.registerLayerType('custom', { modulePath: '/abs/path/custom.js' }); const out = await renderer.renderVideo({ outputType: 'file', output: './out.mp4' }); await renderer.cleanup(); ``` Callers own cleanup — call cleanup when done (the static render helper does this for you).
Parameters
| Name | Type | Description |
|---|---|---|
options | ServerRenderOptions |
Returns
Promise<string | Buffer<ArrayBufferLike>>render
(videoJSON: VideoJSON, options: ServerRenderOptions): Promise<string | Buffer<ArrayBufferLike>>Render a VideoJSON to a Buffer or file. Convenience wrapper over the instance API. External layer types can be passed as `options.layerTypes` (each entry is forwarded to registerLayerType); for anything more involved, construct a `ServerRenderer` and drive it directly.
Parameters
| Name | Type | Description |
|---|---|---|
videoJSON | VideoJSON | The compiled video JSON. |
options | ServerRenderOptions | Rendering options (outputType, output path, signal, layerTypes). |
Returns
Promise<string | Buffer<ArrayBufferLike>>Functions
closeSharedBrowser
(): Promise<void>Close the shared browser instance. Call this when the server is shutting down to release resources.
Returns
Promise<void>