Skip to content

🎥 Make videos programmatically with React

Docs: Clarify WebGPU model loading and cleanup

Jonny Burger394d42362796
diff --git a/packages/docs/docs/video-matting/dispose-video-matting-model.mdx b/packages/docs/docs/video-matting/dispose-video-matting-model.mdx
index fcfe1930d3..04beff129d 100644
--- a/packages/docs/docs/video-matting/dispose-video-matting-model.mdx
+++ b/packages/docs/docs/video-matting/dispose-video-matting-model.mdx
@@ -8,6 +8,8 @@ crumb: '@remotion/video-matting'
Releases the memory used by initialized video matting models. Persistent cached model files are not deleted.
+Use `await using` with [`loadVideoMattingModel()`](/docs/video-matting/load-video-matting-model) for cleanup at the end of a scope; call `disposeVideoMattingModel()` when you want to release a model loaded automatically.
+
```ts twoslash title="dispose.ts"
import {disposeVideoMattingModel} from '@remotion/video-matting';
diff --git a/packages/docs/docs/video-matting/index.mdx b/packages/docs/docs/video-matting/index.mdx
index 9b03d48a94..09d0a4830f 100644
--- a/packages/docs/docs/video-matting/index.mdx
+++ b/packages/docs/docs/video-matting/index.mdx
@@ -32,7 +32,6 @@ export const matteVideo = async (file: File) => {
await using modelHandle = await loadVideoMattingModel({
model,
});
- console.log('Model already in memory:', modelHandle.alreadyLoaded);
await using layers = await separateVideoLayers({
src: file,
@@ -49,6 +48,8 @@ export const matteVideo = async (file: File) => {
};
```
+[`separateVideoLayers()`](/docs/video-matting/separate-video-layers) loads the model automatically; use [`loadVideoMattingModel()`](/docs/video-matting/load-video-matting-model) with `await using` when you want to initialize it before processing and release it when the scope ends. Call [`disposeVideoMattingModel()`](/docs/video-matting/dispose-video-matting-model) when you want to release a model loaded automatically. `await using` also removes the temporary output files when `matteVideo()` returns; the blobs remain usable.
+
## Model hosting
We noticed that hosting the models on R2 leads to faster downloading than through Hugging Face directly.
diff --git a/packages/docs/docs/video-matting/load-video-matting-model.mdx b/packages/docs/docs/video-matting/load-video-matting-model.mdx
index c8b47d9652..529282cb64 100644
--- a/packages/docs/docs/video-matting/load-video-matting-model.mdx
+++ b/packages/docs/docs/video-matting/load-video-matting-model.mdx
@@ -8,7 +8,7 @@ crumb: '@remotion/video-matting'
Initializes a previously downloaded video matting model on WebGPU. Call [`downloadVideoMattingModel()`](/docs/video-matting/download-video-matting-model) first.
-Call it before [`separateVideoLayers()`](/docs/video-matting/separate-video-layers).
+[`separateVideoLayers()`](/docs/video-matting/separate-video-layers) loads the model automatically; call `loadVideoMattingModel()` when you want to initialize it before processing.
```ts twoslash title="load-model.ts"
import {downloadVideoMattingModel, loadVideoMattingModel} from '@remotion/video-matting';
diff --git a/packages/docs/docs/video-matting/separate-video-layers.mdx b/packages/docs/docs/video-matting/separate-video-layers.mdx
index 4eaeecf9ca..82958a130e 100644
--- a/packages/docs/docs/video-matting/separate-video-layers.mdx
+++ b/packages/docs/docs/video-matting/separate-video-layers.mdx
@@ -8,6 +8,8 @@ crumb: '@remotion/video-matting'
Separates a video into an opaque base WebM and a foreground WebM with alpha.
+The downloaded model is loaded automatically if needed.
+
```ts twoslash title="separate-video.ts"
import {downloadVideoMattingModel, separateVideoLayers} from '@remotion/video-matting';
diff --git a/packages/docs/docs/whisper-webgpu/dispose-whisper-model.mdx b/packages/docs/docs/whisper-webgpu/dispose-whisper-model.mdx
index 247e04da72..da56e194e4 100644
--- a/packages/docs/docs/whisper-webgpu/dispose-whisper-model.mdx
+++ b/packages/docs/docs/whisper-webgpu/dispose-whisper-model.mdx
@@ -8,6 +8,8 @@ crumb: '@remotion/whisper-webgpu'
Releases the memory used by initialized Whisper pipelines. Persistently cached model files are not deleted.
+Use `await using` with [`loadWhisperModel()`](/docs/whisper-webgpu/load-whisper-model) for cleanup at the end of a scope; call `disposeWhisperModel()` when you want to release a model loaded automatically.
+
```ts twoslash title="dispose.ts"
import {disposeWhisperModel} from '@remotion/whisper-webgpu';
diff --git a/packages/docs/docs/whisper-webgpu/index.mdx b/packages/docs/docs/whisper-webgpu/index.mdx
index 14e8a86df0..6e35a6db7d 100644
--- a/packages/docs/docs/whisper-webgpu/index.mdx
+++ b/packages/docs/docs/whisper-webgpu/index.mdx
@@ -17,26 +17,26 @@ import {TableOfContents} from './table-of-contents';
## Example
```ts twoslash title="transcribe.ts"
-import {clearStaleModels, downloadWhisperModel, resampleTo16Khz, toCaptions, transcribe} from '@remotion/whisper-webgpu';
-
-await clearStaleModels();
-await downloadWhisperModel({model: 'small.en'});
-
-const file = new File([], 'audio.wav');
-const channelWaveform = await resampleTo16Khz({file});
-
-const transcription = await transcribe({
- channelWaveform,
- model: 'small.en',
- language: 'en',
-});
-
-const {captions} = toCaptions({whisperWebGpuOutput: transcription});
-console.log(captions);
+import {clearStaleModels, downloadWhisperModel, loadWhisperModel, resampleTo16Khz, toCaptions, transcribe} from '@remotion/whisper-webgpu';
+
+export const transcribeFile = async (file: File) => {
+ await clearStaleModels();
+ await downloadWhisperModel({model: 'small.en'});
+ await using modelHandle = await loadWhisperModel({model: 'small.en'});
+
+ const channelWaveform = await resampleTo16Khz({file});
+ const transcription = await transcribe({
+ channelWaveform,
+ model: 'small.en',
+ language: 'en',
+ });
+
+ const {captions} = toCaptions({whisperWebGpuOutput: transcription});
+ return captions;
+};
```
-[`downloadWhisperModel()`](/docs/whisper-webgpu/download-whisper-model) stores model files in the persistent cache.
-Call [`loadWhisperModel()`](/docs/whisper-webgpu/load-whisper-model) when you want to initialize the model explicitly.
+[`downloadWhisperModel()`](/docs/whisper-webgpu/download-whisper-model) stores model files in the persistent cache. [`transcribe()`](/docs/whisper-webgpu/transcribe) loads the model automatically; use [`loadWhisperModel()`](/docs/whisper-webgpu/load-whisper-model) with `await using` when you want to initialize it before transcription and release it when the scope ends. Call [`disposeWhisperModel()`](/docs/whisper-webgpu/dispose-whisper-model) when you want to release a model loaded automatically.
## Model hosting
@@ -55,7 +55,7 @@ See [`@remotion/whisper-webgpu` in Node.js](/docs/whisper-webgpu/node) for a com
## Requirements
You obviously need a GPU.
-Use [`canUseWhisperWebGpu()`](/docs/whisper-webgpu/can-use-whisper-webgpu) to determine if it is supported.
+Use [`canUseWhisperWebGpu()`](/docs/whisper-webgpu/can-use-whisper-webgpu) to determine if it is supported.
## License
diff --git a/packages/docs/docs/whisper-webgpu/load-whisper-model.mdx b/packages/docs/docs/whisper-webgpu/load-whisper-model.mdx
index 71e4872683..9ad3fda824 100644
--- a/packages/docs/docs/whisper-webgpu/load-whisper-model.mdx
+++ b/packages/docs/docs/whisper-webgpu/load-whisper-model.mdx
@@ -8,6 +8,8 @@ crumb: '@remotion/whisper-webgpu'
Initializes a previously downloaded Whisper model on WebGPU. Call [`downloadWhisperModel()`](/docs/whisper-webgpu/download-whisper-model) first.
+[`transcribe()`](/docs/whisper-webgpu/transcribe) loads the model automatically; call `loadWhisperModel()` when you want to initialize it before transcription.
+
```ts twoslash title="load-model.ts"
import {downloadWhisperModel, loadWhisperModel} from '@remotion/whisper-webgpu';
diff --git a/packages/docs/docs/whisper-webgpu/transcribe.mdx b/packages/docs/docs/whisper-webgpu/transcribe.mdx
index 56f06323e0..f393532730 100644
--- a/packages/docs/docs/whisper-webgpu/transcribe.mdx
+++ b/packages/docs/docs/whisper-webgpu/transcribe.mdx
@@ -8,6 +8,8 @@ crumb: '@remotion/whisper-webgpu'
Transcribes a 16kHz mono waveform and returns words with start and end timestamps.
+The downloaded model is loaded automatically if needed.
+
```ts twoslash title="transcribe.ts"
import {downloadWhisperModel, resampleTo16Khz, transcribe} from '@remotion/whisper-webgpu';