Skip to content

🎥 Make videos programmatically with React

Install Transformers as an AI package peer

JonnyBurgerc9b504317fc8
diff --git a/bun.lock b/bun.lock
index 59c64a430e..5f3b6bb794 100644
--- a/bun.lock
+++ b/bun.lock
@@ -832,8 +832,10 @@
"@remotion/tailwind-v4": "workspace:*",
"@remotion/three": "workspace:*",
"@remotion/transitions": "workspace:*",
+ "@remotion/video-matting": "workspace:*",
"@remotion/webcodecs": "workspace:*",
"@remotion/whisper-web": "workspace:*",
+ "@remotion/whisper-webgpu": "4.0.522",
"@remotion/zod-types": "workspace:*",
"@remotion/zod-types-v3": "workspace:*",
"@shopify/react-native-skia": "2.0.0",
@@ -1803,7 +1805,6 @@
"name": "@remotion/studio",
"version": "4.0.522",
"dependencies": {
- "@huggingface/transformers": "catalog:",
"@jridgewell/trace-mapping": "0.3.31",
"@remotion/canvas": "workspace:*",
"@remotion/captions": "workspace:*",
@@ -1988,6 +1989,7 @@
"@remotion/media": "workspace:*",
"@remotion/media-parser": "workspace:*",
"@remotion/media-utils": "workspace:*",
+ "@remotion/whisper-webgpu": "4.0.522",
"@remotion/zod-types": "workspace:*",
"react": "19.2.3",
"react-dom": "19.2.3",
diff --git a/packages/bundler/src/optional-dependencies.ts b/packages/bundler/src/optional-dependencies.ts
index eb38542474..b5ffccfe14 100644
--- a/packages/bundler/src/optional-dependencies.ts
+++ b/packages/bundler/src/optional-dependencies.ts
@@ -9,7 +9,10 @@ const OPTIONAL_DEPENDENCIES = [
'react-native-reanimated/package.json',
];
-const STUDIO_OPTIONAL_DEPENDENCIES = ['@remotion/whisper-webgpu'];
+const STUDIO_OPTIONAL_DEPENDENCIES = [
+ '@remotion/whisper-webgpu',
+ '@remotion/video-matting',
+];
const SOURCE_MAP_IGNORE = ['path', 'fs'];
diff --git a/packages/bundler/src/test/optional-dependencies.test.ts b/packages/bundler/src/test/optional-dependencies.test.ts
index d6ff9b9eec..f66275f11b 100644
--- a/packages/bundler/src/test/optional-dependencies.test.ts
+++ b/packages/bundler/src/test/optional-dependencies.test.ts
@@ -1,27 +1,40 @@
import {expect, test} from 'bun:test';
import {AllowOptionalDependenciesPlugin} from '../optional-dependencies';
-const missingWhisperError = (issuer: string) => {
+const missingOptionalPackageError = (packageName: string, issuer: string) => {
return Object.assign(
- new Error("Can't resolve '@remotion/whisper-webgpu' in '/project'"),
+ new Error(`Can't resolve '${packageName}' in '/project'`),
{module: {resource: issuer}},
);
};
-test('allows Studio to omit its optional Whisper WebGPU capability', () => {
+test('allows Studio to omit its optional AI capabilities', () => {
const plugin = new AllowOptionalDependenciesPlugin();
- expect(
- plugin.filter(
- missingWhisperError(
- '/project/node_modules/@remotion/studio/dist/esm/chunk.js',
+ for (const packageName of [
+ '@remotion/whisper-webgpu',
+ '@remotion/video-matting',
+ ]) {
+ expect(
+ plugin.filter(
+ missingOptionalPackageError(
+ packageName,
+ '/project/node_modules/@remotion/studio/dist/esm/chunk.js',
+ ),
),
- ),
- ).toBe(false);
+ ).toBe(false);
+ }
});
-test('does not hide missing Whisper WebGPU imports in user code', () => {
+test('does not hide missing optional AI package imports in user code', () => {
const plugin = new AllowOptionalDependenciesPlugin();
- expect(plugin.filter(missingWhisperError('/project/src/Video.tsx'))).toBe(
- true,
- );
+ for (const packageName of [
+ '@remotion/whisper-webgpu',
+ '@remotion/video-matting',
+ ]) {
+ expect(
+ plugin.filter(
+ missingOptionalPackageError(packageName, '/project/src/Video.tsx'),
+ ),
+ ).toBe(true);
+ }
});
diff --git a/packages/studio/bundle.ts b/packages/studio/bundle.ts
index 703788137a..f0fc881340 100644
--- a/packages/studio/bundle.ts
+++ b/packages/studio/bundle.ts
@@ -1,7 +1,6 @@
import {buildPackage} from '../.monorepo/builder';
const external = [
- '@huggingface/transformers',
'react',
'remotion',
'@remotion/canvas',
diff --git a/packages/studio/package.json b/packages/studio/package.json
index 86010c4e49..004094d680 100644
--- a/packages/studio/package.json
+++ b/packages/studio/package.json
@@ -34,7 +34,6 @@
}
},
"dependencies": {
- "@huggingface/transformers": "catalog:",
"@tanstack/react-virtual": "3.14.9",
"@remotion/canvas": "workspace:*",
"@remotion/studio-protocol": "workspace:*",
diff --git a/packages/studio/src/api/install-package.ts b/packages/studio/src/api/install-package.ts
index 3cad3ce127..e2a7995e75 100644
--- a/packages/studio/src/api/install-package.ts
+++ b/packages/studio/src/api/install-package.ts
@@ -5,6 +5,7 @@ import type {
import {getRemotionEnvironment} from 'remotion';
import {callApi} from '../components/call-api';
import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';
+import {withRequiredAuxiliaryPackages} from '../helpers/optional-package-dependencies';
export const installPackages = async (
dependencies: readonly PackageInstallSpec[],
@@ -13,11 +14,14 @@ export const installPackages = async (
throw new Error('installPackages() is only available in the Studio');
}
+ const dependenciesWithAuxiliaryPackages =
+ withRequiredAuxiliaryPackages(dependencies);
+
const browserStudioOperations = getBrowserStudioOperations();
if (browserStudioOperations !== null) {
const response =
await browserStudioOperations.packageInstallation.installPackages({
- dependencies: [...dependencies],
+ dependencies: dependenciesWithAuxiliaryPackages,
});
if (!response.success) {
const error = new Error(response.reason);
@@ -33,6 +37,6 @@ export const installPackages = async (
}
return callApi('/api/install-package', {
- dependencies: [...dependencies],
+ dependencies: dependenciesWithAuxiliaryPackages,
});
};
diff --git a/packages/studio/src/components/ModelsSettings.tsx b/packages/studio/src/components/ModelsSettings.tsx
index 70eaf25b90..89fdd35d42 100644
--- a/packages/studio/src/components/ModelsSettings.tsx
+++ b/packages/studio/src/components/ModelsSettings.tsx
@@ -1,5 +1,6 @@
import React, {Suspense, useCallback, useState} from 'react';
import {BLUE, LIGHT_TEXT, WARNING_COLOR, WHITE} from '../helpers/colors';
+import {TRANSFORMERS_PACKAGE} from '../helpers/optional-package-dependencies';
import {Button} from './Button';
import {sectionHeader} from './InspectorPanel/styles';
import {
@@ -138,7 +139,8 @@ const OptionalModelPackage: React.FC<{
) : (
<>
<p style={missingDescription}>
- Install the package to download and manage its models.
+ Install the package and {TRANSFORMERS_PACKAGE} to download and
+ manage its models.
</p>
{installState.type === 'error' ? (
<p style={errorStyle}>{installState.message}</p>
diff --git a/packages/studio/src/components/OptionalPackageModal.tsx b/packages/studio/src/components/OptionalPackageModal.tsx
index aa8f75e60b..cc578d80be 100644
--- a/packages/studio/src/components/OptionalPackageModal.tsx
+++ b/packages/studio/src/components/OptionalPackageModal.tsx
@@ -1,6 +1,7 @@
import React, {useCallback, useContext, useEffect, useState} from 'react';
import {installPackages} from '../api/install-package';
import {LIGHT_TEXT, WARNING_COLOR, WHITE} from '../helpers/colors';
+import {withRequiredAuxiliaryPackages} from '../helpers/optional-package-dependencies';
import {SetSelectedModalContext} from '../state/modals';
import {Button} from './Button';
import {Flex, Row, Spacing} from './layout';
@@ -68,8 +69,13 @@ export const markOptionalPackageInstalled = (packageName: string) => {
};
export const installOptionalPackage = async (packageName: string) => {
- await installPackages([{name: packageName, version: null}]);
- markOptionalPackageInstalled(packageName);
+ const dependencies = withRequiredAuxiliaryPackages([
+ {name: packageName, version: null},
+ ]);
+ await installPackages(dependencies);
+ for (const dependency of dependencies) {
+ markOptionalPackageInstalled(dependency.name);
+ }
};
export const useOptionalPackageInstalled = (packageName: string) => {
@@ -104,6 +110,10 @@ export const OptionalPackageModal: React.FC<{
type: 'idle',
});
const busy = installState.type === 'installing';
+ const packageNames = withRequiredAuxiliaryPackages([
+ {name: packageName, version: null},
+ ]).map((dependency) => dependency.name);
+ const packagesLabel = packageNames.join(' and ');
const dismiss = useCallback(() => {
if (!busy) {
@@ -136,12 +146,18 @@ export const OptionalPackageModal: React.FC<{
{busy ? (
<div style={statusStyle}>
<Spinner duration={0.5} size={18} />
- {`Installing ${packageName}…`}
+ {`Installing ${packagesLabel}…`}
</div>
) : (
<>
This requires installing{' '}
- <code style={codeStyle}>{packageName}</code>.{' Continue?'}
+ {packageNames.map((name, index) => (
+ <React.Fragment key={name}>
+ {index > 0 ? ' and ' : null}
+ <code style={codeStyle}>{name}</code>
+ </React.Fragment>
+ ))}
+ . Continue?
{installState.type === 'error' ? (
<div style={errorStyle}>{installState.error.message}</div>
) : null}
diff --git a/packages/studio/src/helpers/optional-package-dependencies.ts b/packages/studio/src/helpers/optional-package-dependencies.ts
new file mode 100644
index 0000000000..0b7644a948
--- /dev/null
+++ b/packages/studio/src/helpers/optional-package-dependencies.ts
@@ -0,0 +1,33 @@
+import {extraPackages, type PackageInstallSpec} from '@remotion/studio-shared';
+
+export const TRANSFORMERS_PACKAGE = '@huggingface/transformers';
+
+const packagesRequiringTransformers = new Set([
+ '@remotion/whisper-webgpu',
+ '@remotion/video-matting',
+]);
+
+export const withRequiredAuxiliaryPackages = (
+ dependencies: readonly PackageInstallSpec[],
+): PackageInstallSpec[] => {
+ if (
+ !dependencies.some((dependency) =>
+ packagesRequiringTransformers.has(dependency.name),
+ ) ||
+ dependencies.some((dependency) => dependency.name === TRANSFORMERS_PACKAGE)
+ ) {
+ return [...dependencies];
+ }
+
+ const transformers = extraPackages.find(
+ (pkg) => pkg.name === TRANSFORMERS_PACKAGE,
+ );
+ if (!transformers) {
+ throw new Error(`No recommended version found for ${TRANSFORMERS_PACKAGE}`);
+ }
+
+ return [
+ ...dependencies,
+ {name: transformers.name, version: transformers.version},
+ ];
+};
diff --git a/packages/studio/src/test/browser-studio-package-installation.test.ts b/packages/studio/src/test/browser-studio-package-installation.test.ts
index 50d23d0e6d..22da4910a5 100644
--- a/packages/studio/src/test/browser-studio-package-installation.test.ts
+++ b/packages/studio/src/test/browser-studio-package-installation.test.ts
@@ -1,7 +1,11 @@
import {afterEach, expect, test} from 'bun:test';
-import type {BrowserStudioPackageInstallationOperations} from '@remotion/studio-shared';
+import type {
+ BrowserStudioPackageInstallationOperations,
+ PackageInstallSpec,
+} from '@remotion/studio-shared';
import {installPackages} from '../api/install-package';
import {canInstallPackages} from '../helpers/browser-studio-operations';
+import {TRANSFORMERS_PACKAGE} from '../helpers/optional-package-dependencies';
import {makeBrowserStudioOperations} from './make-browser-studio-operations';
const originalWindowDescriptor = Object.getOwnPropertyDescriptor(
@@ -19,10 +23,10 @@ afterEach(() => {
});
test('routes package installation through the explicit Browser Studio capability', async () => {
- const requests: string[][] = [];
+ const requests: PackageInstallSpec[][] = [];
const packageInstallation: BrowserStudioPackageInstallationOperations = {
installPackages: ({dependencies}) => {
- requests.push(dependencies.map((dependency) => dependency.name));
+ requests.push(dependencies);
return Promise.resolve({success: true});
},
};
@@ -42,7 +46,16 @@ test('routes package installation through the explicit Browser Studio capability
expect(
await installPackages([{name: '@remotion/google-fonts', version: null}]),
).toEqual({});
- expect(requests).toEqual([['@remotion/google-fonts']]);
+ expect(
+ await installPackages([{name: '@remotion/video-matting', version: null}]),
+ ).toEqual({});
+ expect(requests).toEqual([
+ [{name: '@remotion/google-fonts', version: null}],
+ [
+ {name: '@remotion/video-matting', version: null},
+ {name: TRANSFORMERS_PACKAGE, version: '4.2.0'},
+ ],
+ ]);
});
test('surfaces structured Browser Studio package installation failures', async () => {
diff --git a/packages/studio/src/test/models-settings.test.tsx b/packages/studio/src/test/models-settings.test.tsx
index 6186d390ac..bddbf28e41 100644
--- a/packages/studio/src/test/models-settings.test.tsx
+++ b/packages/studio/src/test/models-settings.test.tsx
@@ -3,6 +3,7 @@ import {cleanup, fireEvent, render, waitFor} from '@testing-library/react';
import {ModelsSettings} from '../components/ModelsSettings';
import {WHISPER_WEBGPU_PACKAGE} from '../components/Transcription/whisper-webgpu-capability';
import {VIDEO_MATTING_PACKAGE} from '../components/VideoMatting/video-matting-capability';
+import {TRANSFORMERS_PACKAGE} from '../helpers/optional-package-dependencies';
const originalInstalledPackages = window.remotion_installedPackages;
const originalIsStudio = window.remotion_isStudio;
@@ -37,6 +38,7 @@ test('offers to install missing model packages and loads models in place', async
expect(window.remotion_installedPackages).not.toContain(
VIDEO_MATTING_PACKAGE,
);
+ expect(window.remotion_installedPackages).toContain(TRANSFORMERS_PACKAGE);
expect(getAllByRole('button', {name: 'Install'})).toHaveLength(1);
expect(fetchSpy).toHaveBeenCalledTimes(1);
} finally {
diff --git a/packages/studio/src/test/sequenced-timeline.test.ts b/packages/studio/src/test/sequenced-timeline.test.ts
index 845d182e27..65c690de39 100644
--- a/packages/studio/src/test/sequenced-timeline.test.ts
+++ b/packages/studio/src/test/sequenced-timeline.test.ts
@@ -145,8 +145,6 @@ test('Should calculate sequences correctly', () => {
nodePathInfo: null,
sequence: {
type: 'video',
- audioStreamIndex: null,
- requestInit: null,
src: 'http://localhost:5000/codep1-2.mp4',
id: '0.640722264073593',
duration: 486,
@@ -209,8 +207,6 @@ test('Should calculate sequences correctly', () => {
sequence: {
loopDisplay: undefined,
type: 'video',
- audioStreamIndex: null,
- requestInit: null,
src: 'http://localhost:5000/screen3.mp4',
id: '0.5529201074994525',
duration: 486,
@@ -291,8 +287,6 @@ const sequences: TSequence[] = [
},
{
type: 'video',
- audioStreamIndex: null,
- requestInit: null,
src: 'http://localhost:5000/codep1-2.mp4',
id: '0.640722264073593',
duration: 10736,
@@ -346,8 +340,6 @@ const sequences: TSequence[] = [
},
{
type: 'video',
- audioStreamIndex: null,
- requestInit: null,
src: 'http://localhost:5000/screen3.mp4',
id: '0.5529201074994525',
duration: 23066,
diff --git a/packages/studio/src/test/timeline.test.ts b/packages/studio/src/test/timeline.test.ts
index 1792aabcca..c805592eee 100644
--- a/packages/studio/src/test/timeline.test.ts
+++ b/packages/studio/src/test/timeline.test.ts
@@ -244,8 +244,6 @@ test('Should inherit loop display from parent for media tracks', () => {
showInTimeline: true,
timelineOrder: null,
type: 'video',
- audioStreamIndex: null,
- requestInit: null,
getStack,
refForOutline: null,
isInsideSeries: false,
@@ -379,8 +377,6 @@ test('Should account for a parent Sequence trimBefore in video thumbnails', () =
showInTimeline: true,
timelineOrder: null,
type: 'video',
- audioStreamIndex: null,
- requestInit: null,
getStack,
refForOutline: null,
isInsideSeries: false,
diff --git a/packages/studio/src/test/whisper-webgpu-capability.test.tsx b/packages/studio/src/test/whisper-webgpu-capability.test.tsx
index 78238fbcb0..6e862ac3fa 100644
--- a/packages/studio/src/test/whisper-webgpu-capability.test.tsx
+++ b/packages/studio/src/test/whisper-webgpu-capability.test.tsx
@@ -8,6 +8,10 @@ import {
} from '../components/Transcription/whisper-webgpu-capability';
import {VIDEO_MATTING_PACKAGE} from '../components/VideoMatting/video-matting-capability';
import {VideoMattingModalWithOptionalPackage} from '../components/VideoMatting/VideoMattingModalWithOptionalPackage';
+import {
+ TRANSFORMERS_PACKAGE,
+ withRequiredAuxiliaryPackages,
+} from '../helpers/optional-package-dependencies';
const originalInstalledPackages = window.remotion_installedPackages;
@@ -23,6 +27,17 @@ test('detects whether Whisper WebGPU is installed in the project', () => {
expect(isWhisperWebGpuInstalled()).toBe(true);
});
+test('adds the pinned Transformers version to AI package installations', () => {
+ for (const packageName of [WHISPER_WEBGPU_PACKAGE, VIDEO_MATTING_PACKAGE]) {
+ expect(
+ withRequiredAuxiliaryPackages([{name: packageName, version: null}]),
+ ).toEqual([
+ {name: packageName, version: null},
+ {name: TRANSFORMERS_PACKAGE, version: '4.2.0'},
+ ]);
+ }
+});
+
test('asks before installing Whisper for transcription', () => {
window.remotion_installedPackages = [];
const {container, getByRole} = render(
@@ -40,7 +55,7 @@ test('asks before installing Whisper for transcription', () => {
);
expect(container.textContent).toContain(
- 'This requires installing @remotion/whisper-webgpu. Continue?',
+ 'This requires installing @remotion/whisper-webgpu and @huggingface/transformers. Continue?',
);
expect(getByRole('button', {name: 'Continue'})).toBeDefined();
});
@@ -60,7 +75,7 @@ test('uses the same install confirmation for video matting', () => {
);
expect(container.textContent).toContain(
- `This requires installing ${VIDEO_MATTING_PACKAGE}. Continue?`,
+ `This requires installing ${VIDEO_MATTING_PACKAGE} and ${TRANSFORMERS_PACKAGE}. Continue?`,
);
expect(getByRole('button', {name: 'Continue'})).toBeDefined();
});
@@ -96,7 +111,9 @@ test('opens transcription after installing Whisper without restarting', async ()
);
fireEvent.click(getByRole('button', {name: 'Continue'}));
- const installing = getByText(`Installing ${WHISPER_WEBGPU_PACKAGE}…`);
+ const installing = getByText(
+ `Installing ${WHISPER_WEBGPU_PACKAGE} and ${TRANSFORMERS_PACKAGE}…`,
+ );
expect(getComputedStyle(installing).fontFamily).toBe('sans-serif');
expect(getComputedStyle(installing).fontSize).toBe('14px');
expect(getComputedStyle(installing).lineHeight).toBe('1.5');
@@ -108,6 +125,14 @@ test('opens transcription after installing Whisper without restarting', async ()
expect(container.textContent).toContain('Output in public/');
});
expect(fetchSpy).toHaveBeenCalledTimes(1);
+ const requestInit = fetchSpy.mock.calls[0]?.[1];
+ expect(JSON.parse(String(requestInit?.body))).toEqual({
+ dependencies: [
+ {name: WHISPER_WEBGPU_PACKAGE, version: null},
+ {name: TRANSFORMERS_PACKAGE, version: '4.2.0'},
+ ],
+ });
+ expect(window.remotion_installedPackages).toContain(TRANSFORMERS_PACKAGE);
} finally {
fetchSpy.mockRestore();
window.remotion_isStudio = originalIsStudio;