🎥 Make videos programmatically with React
Remove nonexistent video matting cache migration
JonnyBurger12c91c7b2af2
diff --git a/packages/docs/docs/video-matting/clear-stale-video-matting-models.mdx b/packages/docs/docs/video-matting/clear-stale-video-matting-models.mdxindex 69282d6a61..b40e50cc3e 100644--- a/packages/docs/docs/video-matting/clear-stale-video-matting-models.mdx+++ b/packages/docs/docs/video-matting/clear-stale-video-matting-models.mdx@@ -8,12 +8,10 @@ crumb: '@remotion/video-matting'Removes cached model files that are no longer returned by [`getAvailableVideoMattingModels()`](/docs/video-matting/get-available-video-matting-models).-It also removes legacy entries for the pinned Hugging Face revisions that were used before models moved to `remotion.media`.+There are no stale models in the current version, so the function resolves without changing the cache.Call this function after upgrading `@remotion/video-matting` to remove files for models discontinued by a newer version.-Only known legacy video-matting entries are removed. Current files from `remotion.media` and cache entries used by unrelated Transformers.js workflows are preserved.-```ts twoslash title="clear-stale-models.ts"import {clearStaleVideoMattingModels} from '@remotion/video-matting';diff --git a/packages/docs/docs/video-matting/is-video-matting-model-cached.mdx b/packages/docs/docs/video-matting/is-video-matting-model-cached.mdxindex 59614d4e5c..2ba9cfad63 100644--- a/packages/docs/docs/video-matting/is-video-matting-model-cached.mdx+++ b/packages/docs/docs/video-matting/is-video-matting-model-cached.mdx@@ -26,8 +26,6 @@ One of the names returned by [`getAvailableVideoMattingModels()`](/docs/video-maA `Promise<boolean>` resolving to `true` if every required model file is cached.-Legacy model files cached from Hugging Face do not satisfy this check. Loading the model downloads and caches the current byte-identical files from their immutable `remotion.media` paths.-## Compatibility<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering player studio hideServers />diff --git a/packages/docs/docs/video-matting/load-video-matting-model.mdx b/packages/docs/docs/video-matting/load-video-matting-model.mdxindex 0d6df92dab..3c2b2c6b5f 100644--- a/packages/docs/docs/video-matting/load-video-matting-model.mdx+++ b/packages/docs/docs/video-matting/load-video-matting-model.mdx@@ -63,7 +63,7 @@ Whether the same model was already initialized in memory.The browser manages the persistent [Transformers.js](https://huggingface.co/docs/transformers.js) cache. This function also retains the initialized model in memory until [`disposeVideoMattingModel()`](/docs/video-matting/dispose-video-matting-model) is called or the page closes.-The hosted files are byte-identical to files from the pinned upstream Hugging Face revision. Legacy Hugging Face downloads use different cache entries and are downloaded once more from `remotion.media`.+The hosted files are byte-identical to files from the pinned upstream Hugging Face revision.## Compatibilitydiff --git a/packages/video-matting/src/clear-stale-video-matting-models.ts b/packages/video-matting/src/clear-stale-video-matting-models.tsindex 22ad2cc327..0a54dbd1c3 100644--- a/packages/video-matting/src/clear-stale-video-matting-models.ts+++ b/packages/video-matting/src/clear-stale-video-matting-models.ts@@ -1,34 +1,4 @@-import {getVideoMattingModelInfo, VIDEO_MATTING_MODELS} from './models';--const legacyModelUrlPrefixes = VIDEO_MATTING_MODELS.map((model) => {- const {modelId, revision} = getVideoMattingModelInfo(model);- return `https://huggingface.co/${modelId}/resolve/${revision}/`;-});--export const clearStaleVideoMattingModels = async (): Promise<void> => {- if (typeof caches === 'undefined') {- return;- }-- const {env} = await import('@huggingface/transformers');- let cache: Cache;- let requests: readonly Request[];- try {- cache = await caches.open(env.cacheKey);- requests = await cache.keys();- } catch {- return;- }-- await Promise.all(- requests.map((request) => {- if (- legacyModelUrlPrefixes.some((prefix) => request.url.startsWith(prefix))- ) {- return cache.delete(request);- }-- return Promise.resolve(false);- }),- );-};+// Transformers.js owns the persistent model cache. There are no stale models+// because this is the first release of the package.+export const clearStaleVideoMattingModels = (): Promise<void> =>+ Promise.resolve();diff --git a/packages/video-matting/src/test/model-runtime.test.ts b/packages/video-matting/src/test/model-runtime.test.tsindex 0d715f530a..e043e66410 100644--- a/packages/video-matting/src/test/model-runtime.test.ts+++ b/packages/video-matting/src/test/model-runtime.test.ts@@ -182,66 +182,6 @@ beforeEach(async () => {Object.assign(transformersEnvironment, originalTransformersEnvironment);});-test('removes only legacy pinned Hugging Face models from the shared browser cache', async () => {- const originalCaches = Object.getOwnPropertyDescriptor(globalThis, 'caches');- const cacheEnvironment =- transformersEnvironment as typeof transformersEnvironment & {- cacheKey: string;- };- cacheEnvironment.cacheKey = 'custom-transformers-cache';- const legacyModnet = new Request(- 'https://huggingface.co/Xenova/modnet/resolve/fa2fa546052fba4c08921230a26cc69a333fca12/config.json',- );- const legacyBen2 = new Request(- 'https://huggingface.co/onnx-community/BEN2-ONNX/resolve/c552aa82688edce09f0ac9d2e31ad53d9d629010/onnx/model_fp16.onnx',- );- const sameModelDifferentRevision = new Request(- 'https://huggingface.co/Xenova/modnet/resolve/main/config.json',- );- const currentHostedModel = new Request(- 'https://remotion.media/models/modnet-v1/config.json',- );- const unrelatedModel = new Request(- 'https://huggingface.co/onnx-community/background-removal/resolve/main/config.json',- );- const deleted: string[] = [];- Object.defineProperty(globalThis, 'caches', {- configurable: true,- value: {- open: (cacheKey: string) => {- expect(cacheKey).toBe('custom-transformers-cache');- return Promise.resolve({- delete: (request: Request) => {- deleted.push(request.url);- return Promise.resolve(true);- },- keys: () =>- Promise.resolve([- legacyModnet,- legacyBen2,- sameModelDifferentRevision,- currentHostedModel,- unrelatedModel,- ]),- });- },- } as unknown as CacheStorage,- });-- try {- const {clearStaleVideoMattingModels} = await import('../index');- await clearStaleVideoMattingModels();- expect(deleted).toEqual([legacyModnet.url, legacyBen2.url]);- } finally {- Reflect.deleteProperty(cacheEnvironment, 'cacheKey');- if (originalCaches) {- Object.defineProperty(globalThis, 'caches', originalCaches);- } else {- Reflect.deleteProperty(globalThis, 'caches');- }- }-});-test('coalesces initialization and defers disposal until active work is done', async () => {const {disposeVideoMattingModel,