Skip to main content

loadVideoMattingModel()v4.0.523

Initializes a previously downloaded video matting model on WebGPU. Call downloadVideoMattingModel() first.

separateVideoLayers() loads the model automatically; call loadVideoMattingModel() when you want to initialize it before processing.

load-model.ts
import {downloadVideoMattingModel, loadVideoMattingModel} from '@remotion/video-matting'; await downloadVideoMattingModel({model: 'modnet'}); await using result = await loadVideoMattingModel({ model: 'modnet', }); console.log(result.alreadyLoaded);

Options​

model​

One of the names returned by getAvailableModels().

signal?v4.0.528​

An AbortSignal used to cancel waiting for the model. Aborting rejects with the signal's reason and stops progress callbacks for this call. Other calls sharing the model continue. GPU initialization already in progress finishes in the background; unused resources are then released.

onProgress?​

Called while the cached model is initialized. Use downloadVideoMattingModel() for download progress. Default: no callback.

The callback receives these properties:

status​

The current model-loading status.

file​

The model file associated with the update, or null for aggregate progress.

progress​

null during initialization and 1 when ready.

loadedBytes​

Always null; downloads happen in downloadVideoMattingModel().

totalBytes​

Always null.

Return value​

Returns an object with this property:

alreadyLoaded​

Whether the same model was already initialized in memory.

[Symbol.asyncDispose]()v4.0.528​

Releases resources allocated by this function.

Use await using to call this method automatically when leaving the current scope.

Call disposeVideoMattingModel() to dispose the pipeline explicitly regardless of retained load handles.

Compatibility​

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also​