@remotion/video-mattingv4.0.523
Separate a video into an opaque base layer and a foreground layer with alpha, locally in the browser using WebGPU.
Installation
- Remotion CLI
- npm
- bun
- pnpm
- yarn
npx remotion add @remotion/video-matting @huggingface/transformers
This assumes you are currently using v4.0.522 of Remotion.npm i --save-exact @remotion/[email protected] @huggingface/[email protected]
Also update
remotion and all `@remotion/*` packages to the same version.Remove all
^ character in front of the version numbers of it as it can lead to a version conflict.This assumes you are currently using v4.0.522 of Remotion.pnpm i @remotion/[email protected] @huggingface/[email protected]
Also update
remotion and all `@remotion/*` packages to the same version.Remove all
^ character in front of the version numbers of it as it can lead to a version conflict.This assumes you are currently using v4.0.522 of Remotion.bun i @remotion/[email protected] @huggingface/[email protected]
Also update
remotion and all `@remotion/*` packages to the same version.Remove all
^ character in front of the version numbers of it as it can lead to a version conflict.This assumes you are currently using v4.0.522 of Remotion.yarn --exact add @remotion/[email protected] @huggingface/[email protected]
Also update
remotion and all `@remotion/*` packages to the same version.Remove all
^ character in front of the version numbers of it as it can lead to a version conflict.Example
separate-video.tsimport {separateVideoLayers } from '@remotion/video-matting'; constfile = newFile ([], 'input.mp4'); const {base ,foreground } = awaitseparateVideoLayers ({src :file , }); constbaseBlob = awaitbase .getBlob (); constforegroundBlob = awaitforeground .getBlob (); awaitPromise .all ([base .dispose (),foreground .dispose ()]);
Call dispose() after retrieving the blobs to release package-owned temporary storage.
The model is downloaded on the first call and cached by the browser. Call loadVideoMattingModel() first to display download progress.
Model hosting
Model files are downloaded from immutable paths on remotion.media. We find that downloads are faster from a R2 mirror than from Hugging Face directly. The models are byte-identical to the ones you can find from Hugging Face.
APIs
Requirements
WebGPU requires HTTPS in production or localhost during development. Use canUseVideoMatting() to check whether the selected model is supported.
If the page uses a strict Content Security Policy, add https://remotion.media to its connect-src directive, for example connect-src 'self' https://remotion.media.
The browser must also be able to decode the input video and encode VP9 with alpha through WebCodecs. separateVideoLayers() checks these media capabilities for the selected input.
License
The package is MIT licensed. Downloaded model weights retain the licenses listed under getAvailableModels().