🎥 Make videos programmatically with React
Remove unused insertVideoLayers codemod
Jonny Burger24e5ba109a97
diff --git a/packages/browser-studio/src/browser-studio-operations.ts b/packages/browser-studio/src/browser-studio-operations.tsindex 2dad608138..c217990d10 100644--- a/packages/browser-studio/src/browser-studio-operations.ts+++ b/packages/browser-studio/src/browser-studio-operations.ts@@ -80,7 +80,6 @@ const {getRootFileForProject,insertBasicCaptions: insertBasicCaptionsCodemod,insertJsxElementIntoProjectWithNodePathRemappings,- insertVideoLayers: insertVideoLayersCodemod,replaceVideoSource: replaceVideoSourceCodemod,JsxElementIdentityMismatchError,JsxElementNotFoundAtLocationError,@@ -2001,50 +2000,6 @@ export const createBrowserStudioOperations = ({}};- const insertVideoLayers: BrowserStudioOperations['insertVideoLayers'] = ({- fileName,- nodePath,- baseSrc,- foregroundSrc,- }) => {- try {- const project = getProject();- const absolutePath = findProjectFile({filePath: fileName, project});- const result = insertVideoLayersCodemod({- input: project.files[absolutePath],- nodePath,- baseSrc,- foregroundSrc,- });- const nodePathMutation = controller.applyMutation({- undoRedoNavigation: null,- timelineSelection: null,- fileName: absolutePath,- mutate: () => ({- ...project,- files: {...project.files, [absolutePath]: result.output},- }),- nodePathMutationFiles: [- {- absolutePath,- remappings: result.nodePathRemappings,- },- ],- });- if (nodePathMutation === null) {- throw new Error('Could not insert separated video layers');- }-- return Promise.resolve({success: true as const, nodePathMutation});- } catch (error) {- return Promise.resolve({- success: false as const,- reason: error instanceof Error ? error.message : String(error),- stack: error instanceof Error && error.stack ? error.stack : '',- });- }- };-const replaceVideoSource: BrowserStudioOperations['replaceVideoSource'] = ({fileName,nodePath,@@ -2542,7 +2497,6 @@ export const createBrowserStudioOperations = ({},splitVideoFromAudio,insertBasicCaptions,- insertVideoLayers,replaceVideoSource,subscribeToDefaultProps: ({clientId, compositionId}) => {const clients =diff --git a/packages/browser-studio/src/test/browser-studio-operations.test.ts b/packages/browser-studio/src/test/browser-studio-operations.test.tsindex e3bbeb5a6e..d6841283f5 100644--- a/packages/browser-studio/src/test/browser-studio-operations.test.ts+++ b/packages/browser-studio/src/test/browser-studio-operations.test.ts@@ -304,7 +304,7 @@ export const Root = () => <Composition id="MyComp" component={Component} duratio).toBe(false);});-test('splits video audio, inserts video layers and captions with remappings and undo', async () => {+test('splits video audio and inserts captions with remappings and undo', async () => {const fileName = '/project/src/Composition.tsx';const initialSource = `import {Video} from '@remotion/media';export const Component = () => <Video src="video.mp4" from={10} durationInFrames={20} volume={0.5} style={{opacity: 0.5}} />;`;@@ -382,34 +382,6 @@ registerRoot(Root);`,expect(undoResult.success).toBe(true);expect(currentProject.files[fileName]).toBe(initialSource);- events.length = 0;- const videoLayersResult = await operations.insertVideoLayers({- fileName: 'src/Composition.tsx',- nodePath: subscription.nodePath.nodePath,- baseSrc: 'video-base.webm',- foregroundSrc: 'video-foreground.webm',- });- if (!videoLayersResult.success) {- throw new Error(videoLayersResult.reason);- }-- const videoLayersOutput = currentProject.files[fileName].replace(/\s+/g, ' ');- expect(currentProject.files[fileName]).toContain(- `import {staticFile} from 'remotion';`,- );- expect(videoLayersOutput).toContain(- "<Video src={staticFile('video-base.webm')} from={10} durationInFrames={20} volume={0.5} style={{opacity: 0.5}} />",- );- expect(videoLayersOutput).toContain(- "<Video src={staticFile('video-foreground.webm')} from={10} durationInFrames={20} volume={0.5} style={{opacity: 0.5, position: 'absolute', top: 0, left: 0}} />",- );- expect(events).toContainEqual({- type: 'sequence-node-paths-remapped',- mutation: videoLayersResult.nodePathMutation,- });- expect((await operations.undo()).success).toBe(true);- expect(currentProject.files[fileName]).toBe(initialSource);-events.length = 0;const captionsResult = await operations.insertBasicCaptions({fileName: 'src/Composition.tsx',diff --git a/packages/codemods/src/index.ts b/packages/codemods/src/index.tsindex 9e3df70272..a7ca0f2e2b 100644--- a/packages/codemods/src/index.ts+++ b/packages/codemods/src/index.ts@@ -11,7 +11,6 @@ import {resolveCompositionComponent,resolveCompositionComponentWithFile,} from './insert-jsx-element';-import {insertVideoLayers} from './insert-video-layers';import {computeCanUpdateDefaultPropsFromContent,findProjectFile,@@ -176,7 +175,6 @@ export const CodemodsInternals = {insertBasicCaptions,insertJsxElementIntoComposition,insertJsxElementIntoProjectWithNodePathRemappings,- insertVideoLayers,replaceVideoSource,pasteEffects,resolveCompositionComponent,diff --git a/packages/codemods/src/insert-video-layers.ts b/packages/codemods/src/insert-video-layers.tsdeleted file mode 100644index ba6d7d26ae..0000000000--- a/packages/codemods/src/insert-video-layers.ts+++ /dev/null@@ -1,431 +0,0 @@-import type {- JSXAttribute,- JSXElement,- JSXExpressionContainer,- JSXFragment,-} from '@babel/types';-import type {SequenceNodePathRemapping} from '@remotion/studio-shared';-import * as recast from 'recast';-import type {SequenceNodePath} from 'remotion';-import {findJsxElementPathForDeletion} from './delete-jsx-nodes-internal';-import {- captureJsxNodePaths,- getNodePathRemappings,-} from './get-node-path-remappings';-import {indentInsertedJsx} from './print-jsx';-import {recastLocToOffset} from './recast-loc-to-offset';-import {ensureNamedImport, getImportedName} from './sequence-props/imports';-import {parseAst} from './sequence-props/parse-ast';-import {- applySourceEdits,- captureImportSnapshots,- getAdjacentJsxInsertionSourceEdit,- getInsertImportSourceEdits,- type SourceEdit,-} from './source-edits';-import {- getEndOfLine,- getIndentationUnit,- getLineIndent,- getPreferredQuote,- indentContinuationLines,-} from './source-style';--const b = recast.types.builders;--const makeStaticFileSource = ({- input,- localName,- prettierConfigOverride,- src,-}: {- input: string;- localName: string;- prettierConfigOverride: Record<string, unknown> | null;- src: string;-}) => {- const stringLiteral = recast.prettyPrint(b.stringLiteral(src), {- quote: getPreferredQuote(input, prettierConfigOverride),- }).code;- return `{${localName}(${stringLiteral})}`;-};--const replaceSrcInElementSource = ({- element,- input,- srcAttribute,- srcSource,- styleEdit,-}: {- element: JSXElement;- input: string;- srcAttribute: JSXAttribute;- srcSource: string;- styleEdit: SourceEdit | null;-}) => {- if (!element.loc || !srcAttribute.value?.loc) {- throw new Error('Could not locate the selected video source');- }-- const elementStart = recastLocToOffset(input, element.loc.start);- const elementEnd = recastLocToOffset(input, element.loc.end);- const valueStart = recastLocToOffset(input, srcAttribute.value.loc.start);- const valueEnd = recastLocToOffset(input, srcAttribute.value.loc.end);- const originalIndent = getLineIndent({input, offset: elementStart});- const elementSource = applySourceEdits({- input: input.slice(elementStart, elementEnd),- edits: [- {- start: valueStart - elementStart,- end: valueEnd - elementStart,- replacement: srcSource,- },- ...(styleEdit- ? [- {- start: styleEdit.start - elementStart,- end: styleEdit.end - elementStart,- replacement: styleEdit.replacement,- },- ]- : []),- ],- });-- return elementSource- .split(/\r?\n/)- .map((line, index) => {- if (index === 0) {- return line;- }-- return line.startsWith(originalIndent)- ? line.slice(originalIndent.length)- : line.trimStart();- })- .join(getEndOfLine(input));-};--const parseVideoElement = (source: string): JSXElement => {- const statement = parseAst(`const element = (${source});`).program.body[0];- if (- statement?.type !== 'VariableDeclaration' ||- statement.declarations[0]?.init?.type !== 'JSXElement'- ) {- throw new Error('Could not generate the separated video layer');- }-- return statement.declarations[0].init;-};--export const insertVideoLayers = ({- input,- nodePath,- baseSrc,- foregroundSrc,- prettierConfigOverride = null,-}: {- input: string;- nodePath: SequenceNodePath;- baseSrc: string;- foregroundSrc: string;- prettierConfigOverride?: Record<string, unknown> | null;-}): {- output: string;- logLine: number;- nodePathRemappings: SequenceNodePathRemapping[];-} => {- const ast = parseAst(input);- const captured = captureJsxNodePaths(ast);- const importSnapshots = captureImportSnapshots(ast);- const videoPath = findJsxElementPathForDeletion(ast, nodePath);- if (!videoPath) {- throw new Error('Could not find the selected video element');- }-- const video = videoPath.node as JSXElement;- if (video.openingElement.name.type !== 'JSXIdentifier') {- throw new Error('The selected video tag cannot be separated');- }-- const tagName = video.openingElement.name.name;- const importedVideo = ast.program.body.some(- (statement) =>- statement.type === 'ImportDeclaration' &&- statement.importKind !== 'type' &&- (statement.source.value === 'remotion' ||- statement.source.value === '@remotion/media') &&- statement.specifiers.some(- (specifier) =>- specifier.type === 'ImportSpecifier' &&- specifier.local.name === tagName &&- [- 'Video',- 'Html5Video',- 'OffthreadVideo',- 'experimental_Video',- ].includes(getImportedName(specifier)),- ),- );- if (!importedVideo) {- throw new Error('The selected element is not a Remotion Video');- }-- const srcAttribute = video.openingElement.attributes.find(- (attribute): attribute is JSXAttribute =>- attribute.type === 'JSXAttribute' &&- attribute.name.type === 'JSXIdentifier' &&- attribute.name.name === 'src',- );- if (!srcAttribute?.value) {- throw new Error(`<${tagName}> has no src attribute`);- }-- if (!srcAttribute.value.loc) {- throw new Error('Could not locate the selected video source');- }-- const srcValueStart = recastLocToOffset(input, srcAttribute.value.loc.start);- const srcValueEnd = recastLocToOffset(input, srcAttribute.value.loc.end);-- let staticFileLocalName = 'staticFile';- let suffix = 1;- while (new RegExp(`\\b${staticFileLocalName}\\b`).test(input)) {- staticFileLocalName = `remotionStaticFile${suffix++}`;- }-- staticFileLocalName = ensureNamedImport({- ast,- importedName: 'staticFile',- localName: staticFileLocalName,- sourcePath: 'remotion',- });- const baseSrcSource = makeStaticFileSource({- input,- localName: staticFileLocalName,- prettierConfigOverride,- src: baseSrc,- });- const foregroundSrcSource = makeStaticFileSource({- input,- localName: staticFileLocalName,- prettierConfigOverride,- src: foregroundSrc,- });- const styleAttribute = video.openingElement.attributes.find(- (attribute): attribute is JSXAttribute =>- attribute.type === 'JSXAttribute' &&- attribute.name.type === 'JSXIdentifier' &&- attribute.name.name === 'style',- );- const quote =- getPreferredQuote(input, prettierConfigOverride) === 'single' ? "'" : '"';- const positioning = `position: ${quote}absolute${quote}, top: 0, left: 0`;- let foregroundStyleEdit: SourceEdit;- if (styleAttribute) {- const {value} = styleAttribute;- if (value?.type !== 'JSXExpressionContainer' || !value.loc) {- throw new Error(- 'Could not add positioning to the foreground video style',- );- }-- const {expression} = value;- if (!expression.loc) {- throw new Error('Could not locate the foreground video style');- }-- const expressionStart = recastLocToOffset(input, expression.loc.start);- const expressionEnd = recastLocToOffset(input, expression.loc.end);- const expressionSource = input.slice(expressionStart, expressionEnd);- const hasPositioning =- expression.type === 'ObjectExpression' &&- expression.properties.some(- (property) =>- property.type === 'ObjectProperty' &&- !property.computed &&- ['position', 'top', 'left', 'inset'].includes(- property.key.type === 'Identifier'- ? property.key.name- : property.key.type === 'StringLiteral'- ? property.key.value- : '',- ),- );- if (- expression.type === 'ObjectExpression' &&- !hasPositioning &&- !expressionSource.includes('//') &&- !expressionSource.includes('/*')- ) {- const body = expressionSource.slice(1, -1);- const trimmedBody = body.trimEnd();- const separator =- expression.properties.length === 0 || trimmedBody.endsWith(',')- ? ''- : ',';- const closingIndent = body.match(/\r?\n([\t ]*)$/)?.[1];- const lastProperty = expression.properties.at(-1);- const propertyIndent = lastProperty?.loc- ? getLineIndent({- input,- offset: recastLocToOffset(input, lastProperty.loc.start),- })- : `${closingIndent ?? ''}${getIndentationUnit(input, prettierConfigOverride)}`;- const replacement =- closingIndent === undefined- ? `{${trimmedBody}${separator}${trimmedBody ? ' ' : ''}${positioning}${body.slice(trimmedBody.length)}}`- : `{${trimmedBody}${separator}${getEndOfLine(input)}${propertyIndent}${positioning},${getEndOfLine(input)}${closingIndent}}`;- foregroundStyleEdit = {- start: expressionStart,- end: expressionEnd,- replacement,- };- } else {- foregroundStyleEdit = {- start: recastLocToOffset(input, value.loc.start),- end: recastLocToOffset(input, value.loc.end),- replacement: `{{top: 0, left: 0, ...(${expressionSource}), position: ${quote}absolute${quote}}}`,- };- }- } else {- if (!video.openingElement.loc) {- throw new Error('Could not locate the foreground video opening tag');- }-- const closingStart =- recastLocToOffset(input, video.openingElement.loc.end) -- (video.openingElement.selfClosing ? 2 : 1);- const closingLineStart = input.lastIndexOf('\n', closingStart - 1) + 1;- const closingLinePrefix = input.slice(closingLineStart, closingStart);- if (/^[\t ]*$/.test(closingLinePrefix)) {- const lastAttribute = video.openingElement.attributes.at(-1);- const attributeIndent = lastAttribute?.loc- ? getLineIndent({- input,- offset: recastLocToOffset(input, lastAttribute.loc.start),- })- : closingLinePrefix + getIndentationUnit(input, prettierConfigOverride);- foregroundStyleEdit = {- start: closingLineStart,- end: closingLineStart,- replacement: `${attributeIndent}style={{${positioning}}}${getEndOfLine(input)}`,- };- } else {- foregroundStyleEdit = {- start: closingStart,- end: closingStart,- replacement: `${/\s/.test(input[closingStart - 1] ?? '') ? '' : ' '}style={{${positioning}}}${video.openingElement.selfClosing ? ' ' : ''}`,- };- }- }-- const baseVideoSource = replaceSrcInElementSource({- element: video,- input,- srcAttribute,- srcSource: baseSrcSource,- styleEdit: null,- });- const foregroundVideoSource = replaceSrcInElementSource({- element: video,- input,- srcAttribute,- srcSource: foregroundSrcSource,- styleEdit: foregroundStyleEdit,- });- const foregroundVideo = parseVideoElement(foregroundVideoSource);-- srcAttribute.value = b.jsxExpressionContainer(- b.callExpression(b.identifier(staticFileLocalName), [- b.stringLiteral(baseSrc),- ]),- ) as unknown as JSXExpressionContainer;-- const parent = videoPath.parentPath?.node;- if (!parent) {- throw new Error('Could not locate the video element parent');- }-- let sourceEdit;- if (- (parent.type === 'JSXElement' || parent.type === 'JSXFragment') &&- parent.children.includes(video)- ) {- const index = parent.children.indexOf(video);- parent.children.splice(index + 1, 0, foregroundVideo);- sourceEdit = [- {- start: srcValueStart,- end: srcValueEnd,- replacement: baseSrcSource,- },- getAdjacentJsxInsertionSourceEdit({- input,- insertion: foregroundVideoSource,- position: 'after',- target: video,- }),- ];- } else {- const fragment: JSXFragment = {- type: 'JSXFragment',- openingFragment: {type: 'JSXOpeningFragment'},- closingFragment: {type: 'JSXClosingFragment'},- children: [video, foregroundVideo],- };- videoPath.replace(fragment);- if (!video.loc) {- throw new Error('Could not locate the video element in source');- }-- const start = recastLocToOffset(input, video.loc.start);- const end = recastLocToOffset(input, video.loc.end);- const indent = getLineIndent({input, offset: start});- const unit = getIndentationUnit(input, prettierConfigOverride);- const eol = getEndOfLine(input);- sourceEdit = [- {- start,- end,- replacement: indentContinuationLines({- indent,- input,- printed: [- '<>',- indentInsertedJsx({indent: unit, insertion: baseVideoSource}),- indentInsertedJsx({- indent: unit,- insertion: foregroundVideoSource,- }),- '</>',- ].join(eol),- }),- },- ];- }-- const output = applySourceEdits({- input,- edits: [- ...getInsertImportSourceEdits({- ast,- input,- prettierConfigOverride,- snapshots: importSnapshots,- }),- ...sourceEdit,- ],- });- const {nodePathRemappings} = getNodePathRemappings({- ast,- captured,- output,- });-- return {- output,- logLine: video.openingElement.loc?.start.line ?? 1,- nodePathRemappings,- };-};diff --git a/packages/docs/docs/ai/webmcp.mdx b/packages/docs/docs/ai/webmcp.mdxindex 6d2a824ac6..a85f1605c0 100644--- a/packages/docs/docs/ai/webmcp.mdx+++ b/packages/docs/docs/ai/webmcp.mdx@@ -25,7 +25,7 @@ Agents can:- See, add and remove guides- Install packages into the current project- Transcribe audio and video assets-- Separate video assets into background and foreground layers+- Remove the background from video assets- Restart or shut down the Studio server## Requirements@@ -117,19 +117,18 @@ This tool is always exposed. If `@remotion/whisper-webgpu` is not installed, itCall `install_package` with the returned package name and retry. Studio also installs the recommended `@huggingface/transformers` version.-### `separate_video_layers`<AvailableFrom v="4.0.523" />+### `remove_video_background`<AvailableFrom v="4.0.523" />-Separates a video asset from the `public/` folder into background and foreground WebM files and adds the work to the Jobs queue.+Removes a video asset's background and saves a transparent WebM file in the `public/` folder. The work is added to the Jobs queue.If `assetPath` is omitted, the video asset currently open in the Studio is used.```ts title="Input"{assetPath?: string;- baseOutputPath?: string;- foregroundOutputPath?: string;+ outputPath?: string;model?: string;- audio?: 'base' | 'foreground' | 'both' | 'none';+ audio?: 'keep' | 'none';videoBitrate?:| 'very-low'| 'low'@@ -140,14 +139,13 @@ If `assetPath` is omitted, the video asset currently open in the Studio is used.}```-The default model is `ben2-base`, audio is kept in the background layer, and video quality defaults to `very-high`. Output names default to `<asset>-base.webm` and `<asset>-foreground.webm`.+The default model is `ben2-base`, the input audio is kept, and video quality defaults to `very-high`. The output name defaults to `<asset>-no-background.webm`.```ts title="Output"{success: true;jobId: string;- baseOutputPath: string;- foregroundOutputPath: string;+ outputPath: string;}```@@ -729,7 +727,7 @@ You can ask a browser agent:- "Add a vertical guide at 640 pixels."- "Mute the preview."- "Transcribe the audio asset that is currently open."-- "Separate `product-shot.mp4` into background and foreground layers."+- "Remove the background from `product-shot.mp4`."The agent chooses and invokes the matching tools. Tool calls affect the open Studio tab immediately.diff --git a/packages/studio-server/src/codemods/insert-video-layers.ts b/packages/studio-server/src/codemods/insert-video-layers.tsdeleted file mode 100644index 63a485b201..0000000000--- a/packages/studio-server/src/codemods/insert-video-layers.ts+++ /dev/null@@ -1,3 +0,0 @@-import {CodemodsInternals} from '@remotion/codemods';--export const {insertVideoLayers} = CodemodsInternals;diff --git a/packages/studio-server/src/preview-server/api-routes.ts b/packages/studio-server/src/preview-server/api-routes.tsindex 061ecca2d3..bee575245c 100644--- a/packages/studio-server/src/preview-server/api-routes.ts+++ b/packages/studio-server/src/preview-server/api-routes.ts@@ -28,7 +28,6 @@ import {findInFileHandler} from './routes/find-in-file';import {insertBasicCaptionsHandler} from './routes/insert-basic-captions';import {insertElementHandler} from './routes/insert-element';import {insertJsxElementHandler} from './routes/insert-jsx-element';-import {insertVideoLayersHandler} from './routes/insert-video-layers';import {installRemotionSkillHandler,removeRemotionSkillHandler,@@ -132,7 +131,6 @@ export const allApiRoutes: {'/api/split-jsx-sequence': splitJsxSequenceHandler,'/api/split-video-from-audio': splitVideoFromAudioHandler,'/api/insert-basic-captions': insertBasicCaptionsHandler,- '/api/insert-video-layers': insertVideoLayersHandler,'/api/replace-video-source': replaceVideoSourceHandler,'/api/update-available': handleUpdate,'/api/release-notes': getReleaseNotesHandler,diff --git a/packages/studio-server/src/preview-server/routes/insert-video-layers.ts b/packages/studio-server/src/preview-server/routes/insert-video-layers.tsdeleted file mode 100644index 6078375661..0000000000--- a/packages/studio-server/src/preview-server/routes/insert-video-layers.ts+++ /dev/null@@ -1,91 +0,0 @@-import {readFileSync} from 'node:fs';-import {RenderInternals} from '@remotion/renderer';-import type {- InsertVideoLayersRequest,- InsertVideoLayersResponse,-} from '@remotion/studio-shared';-import {insertVideoLayers} from '../../codemods/insert-video-layers';-import {writeFileAndNotifyFileWatchers} from '../../file-watcher';-import {resolveFileInsideProject} from '../../helpers/resolve-file-inside-project';-import type {ApiHandler} from '../api-types';-import {formatLogFileLocation} from '../format-log-file-location';-import {broadcastSequenceNodePathMutation} from '../sequence-node-path-mutation';-import {- printUndoHint,- pushToUndoStack,- suppressUndoStackInvalidation,-} from '../undo-stack';-import {- getCodemodTimingPrefix,- withSourceFileWriteQueue,-} from './source-file-write-queue';--export const insertVideoLayersHandler: ApiHandler<- InsertVideoLayersRequest,- InsertVideoLayersResponse-> = ({- input: {fileName, nodePath, baseSrc, foregroundSrc},- remotionRoot,- logLevel,-}) =>- withSourceFileWriteQueue<InsertVideoLayersResponse>(() => {- try {- const {absolutePath} = resolveFileInsideProject({- remotionRoot,- fileName,- action: 'modify',- });- const fileContents = readFileSync(absolutePath, 'utf-8');- const {output, logLine, nodePathRemappings} = insertVideoLayers({- input: fileContents,- nodePath,- baseSrc,- foregroundSrc,- });- const nodePathMutation = broadcastSequenceNodePathMutation(- [{absolutePath, remappings: nodePathRemappings}],- null,- );-- pushToUndoStack({- filePath: absolutePath,- oldContents: fileContents,- newContents: null,- logLevel,- remotionRoot,- logLine,- description: {- undoMessage: '↩️ Insertion of separated video layers',- redoMessage: '↪️ Insertion of separated video layers',- },- entryType: 'insert-video-layers',- suppressHmrOnFileRestore: false,- nodePathRemappings,- });- suppressUndoStackInvalidation(absolutePath);- writeFileAndNotifyFileWatchers({- file: absolutePath,- content: output,- originatorClientId: undefined,- metadata: {skipSequencePropsUpdate: true},- });-- const locationLabel = formatLogFileLocation({- remotionRoot,- absolutePath,- line: logLine,- });- RenderInternals.Log.info(- {indent: false, logLevel},- `${getCodemodTimingPrefix(logLevel)}${RenderInternals.chalk.blueBright(locationLabel)} Inserted separated video layers`,- );- printUndoHint(logLevel);- return Promise.resolve({success: true as const, nodePathMutation});- } catch (error) {- return Promise.resolve({- success: false,- reason: (error as Error).message,- stack: (error as Error).stack ?? '',- } as const);- }- });diff --git a/packages/studio-server/src/preview-server/undo-stack.ts b/packages/studio-server/src/preview-server/undo-stack.tsindex 783bb83c77..70d079e9b6 100644--- a/packages/studio-server/src/preview-server/undo-stack.ts+++ b/packages/studio-server/src/preview-server/undo-stack.ts@@ -43,7 +43,6 @@ type UndoEntryType =| 'split-jsx-sequence'| 'split-video-from-audio'| 'insert-basic-captions'- | 'insert-video-layers'| 'replace-video-source'| 'insert-jsx-element'| 'delete-composition'diff --git a/packages/studio-server/src/test/insert-video-layers.test.ts b/packages/studio-server/src/test/insert-video-layers.test.tsdeleted file mode 100644index 7c4888055a..0000000000--- a/packages/studio-server/src/test/insert-video-layers.test.ts+++ /dev/null@@ -1,115 +0,0 @@-import {expect, test} from 'bun:test';-import {mkdtempSync, readFileSync, rmSync, writeFileSync} from 'node:fs';-import {tmpdir} from 'node:os';-import path from 'node:path';-import {- createFileWatcherRegistry,- setFileWatcherRegistry,-} from '../file-watcher';-import {setLiveEventsListener} from '../preview-server/live-events';-import {insertVideoLayersHandler} from '../preview-server/routes/insert-video-layers';-import {getUndoStack} from '../preview-server/undo-stack';-import {lineContainingToNodePath} from './test-utils';--test('video matting inserts base and foreground videos through the Studio route', async () => {- const remotionRoot = mkdtempSync(path.join(tmpdir(), 'remotion-matting-'));- const entryPoint = path.join(remotionRoot, 'Root.tsx');- const cleanupFileWatcher = setFileWatcherRegistry(- createFileWatcherRegistry(),- );- const cleanupLiveEvents = setLiveEventsListener({- sendEventToClient: () => undefined,- sendEventToClientId: () => true,- router: () => Promise.resolve(),- closeConnections: () => Promise.resolve(),- addNewClientListener: () => () => undefined,- });- const input = `import {Video as Clip} from '@remotion/media';--const source = 'input.mp4';-const untouched = {keep : 'spacing'};--export const Comp = () => (- <Clip- src={source}- from={10}- style={{opacity: 0.5}}- />-);-`;-- try {- (getUndoStack() as unknown as unknown[]).length = 0;- for (const {source, base, foreground} of [- {- source: input,- base: "<Clip src={staticFile('input-base.webm')} from={10} style={{opacity: 0.5}} />",- foreground:- "<Clip src={staticFile('input-foreground.webm')} from={10} style={{opacity: 0.5, position: 'absolute', top: 0, left: 0}} />",- },- {- source: input.replace('\t\tstyle={{opacity: 0.5}}\n', ''),- base: "<Clip src={staticFile('input-base.webm')} from={10} />",- foreground:- "<Clip src={staticFile('input-foreground.webm')} from={10} style={{position: 'absolute', top: 0, left: 0}} />",- },- {- source: input.replace(- 'style={{opacity: 0.5}}',- 'style={{\n\t\t\topacity: 0.5,\n\t\t}}',- ),- base: "<Clip src={staticFile('input-base.webm')} from={10} style={{ opacity: 0.5, }} />",- foreground:- "<Clip src={staticFile('input-foreground.webm')} from={10} style={{ opacity: 0.5, position: 'absolute', top: 0, left: 0, }} />",- },- {- source: input.replace(- 'style={{opacity: 0.5}}',- "style={{position: 'absolute', top: 10, left: 20, opacity: 0.5}}",- ),- base: "<Clip src={staticFile('input-base.webm')} from={10} style={{position: 'absolute', top: 10, left: 20, opacity: 0.5}} />",- foreground:- "<Clip src={staticFile('input-foreground.webm')} from={10} style={{top: 0, left: 0, ...({position: 'absolute', top: 10, left: 20, opacity: 0.5}), position: 'absolute'}} />",- },- ]) {- writeFileSync(entryPoint, source);- const result = await insertVideoLayersHandler({- input: {- fileName: entryPoint,- nodePath: lineContainingToNodePath(source, '<Clip'),- baseSrc: 'input-base.webm',- foregroundSrc: 'input-foreground.webm',- },- entryPoint,- remotionRoot,- request: {} as never,- response: {} as never,- logLevel: 'error',- methods: {- removeJob: () => undefined,- cancelJob: () => undefined,- addJob: () => undefined,- },- publicDir: remotionRoot,- binariesDirectory: null,- configFile: null,- getDefaultCodingAgent: () => null,- getDefaultEditor: () => null,- });-- expect(result.success).toBe(true);- const written = readFileSync(entryPoint, 'utf-8');- const singleLine = written.replace(/\s+/g, ' ');- expect(written).toContain(`import {staticFile} from 'remotion';`);- expect(singleLine).toContain(base);- expect(singleLine).toContain(foreground);- expect(written).toContain("const untouched = {keep : 'spacing'};");- }-- expect(getUndoStack()).toHaveLength(4);- } finally {- cleanupFileWatcher();- cleanupLiveEvents();- rmSync(remotionRoot, {recursive: true, force: true});- }-});diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.tsindex f01708ce84..d9811264a3 100644--- a/packages/studio-shared/src/api-requests.ts+++ b/packages/studio-shared/src/api-requests.ts@@ -940,24 +940,15 @@ export type InsertBasicCaptionsResponse =| {success: true; nodePathMutation: SequenceNodePathMutation}| {success: false; reason: string; stack: string};-export type InsertVideoLayersRequest = {- fileName: string;- nodePath: SequenceNodePath;- baseSrc: string;- foregroundSrc: string;-};--export type InsertVideoLayersResponse =- | {success: true; nodePathMutation: SequenceNodePathMutation}- | {success: false; reason: string; stack: string};-export type ReplaceVideoSourceRequest = {fileName: string;nodePath: SequenceNodePath;src: string;};-export type ReplaceVideoSourceResponse = InsertVideoLayersResponse;+export type ReplaceVideoSourceResponse =+ | {success: true; nodePathMutation: SequenceNodePathMutation}+ | {success: false; reason: string; stack: string};export type InsertableCompositionElement =| {@@ -1457,10 +1448,6 @@ export type ApiRoutes = {InsertBasicCaptionsRequest,InsertBasicCaptionsResponse>;- '/api/insert-video-layers': ReqAndRes<- InsertVideoLayersRequest,- InsertVideoLayersResponse- >;'/api/replace-video-source': ReqAndRes<ReplaceVideoSourceRequest,ReplaceVideoSourceResponsediff --git a/packages/studio-shared/src/browser-studio-operations.ts b/packages/studio-shared/src/browser-studio-operations.tsindex 573de4ec7c..bc2d83e4f2 100644--- a/packages/studio-shared/src/browser-studio-operations.ts+++ b/packages/studio-shared/src/browser-studio-operations.ts@@ -62,8 +62,6 @@ import type {SplitVideoFromAudioResponse,InsertBasicCaptionsRequest,InsertBasicCaptionsResponse,- InsertVideoLayersRequest,- InsertVideoLayersResponse,ReplaceVideoSourceRequest,ReplaceVideoSourceResponse,SubscribeToDefaultPropsRequest,@@ -231,9 +229,6 @@ export type BrowserStudioOperations = {insertBasicCaptions: (request: InsertBasicCaptionsRequest,) => Promise<InsertBasicCaptionsResponse>;- insertVideoLayers: (- request: InsertVideoLayersRequest,- ) => Promise<InsertVideoLayersResponse>;replaceVideoSource?: (request: ReplaceVideoSourceRequest,) => Promise<ReplaceVideoSourceResponse>;diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.tsindex ec12529ec9..887b3dff2b 100644--- a/packages/studio-shared/src/index.ts+++ b/packages/studio-shared/src/index.ts@@ -75,8 +75,6 @@ export {InsertElementFileConflict,InsertBasicCaptionsRequest,InsertBasicCaptionsResponse,- InsertVideoLayersRequest,- InsertVideoLayersResponse,ReplaceVideoSourceRequest,ReplaceVideoSourceResponse,InsertElementRequest,diff --git a/packages/studio/src/components/RenderQueue/VideoMattingQueueItem.tsx b/packages/studio/src/components/RenderQueue/VideoMattingQueueItem.tsxindex 2d4365e090..7c9fe0a9de 100644--- a/packages/studio/src/components/RenderQueue/VideoMattingQueueItem.tsx+++ b/packages/studio/src/components/RenderQueue/VideoMattingQueueItem.tsx@@ -68,11 +68,7 @@ const Status: React.FC<{readonly job: VideoMattingJob}> = ({job}) => {<divstyle={statusIcon}role="progressbar"- aria-label={- 'outName' in job- ? 'Background removal progress'- : 'Video matting progress'- }+ aria-label="Background removal progress"aria-valuemin={0}aria-valuemax={100}aria-valuenow={Math.round(job.progress.value * 100)}@@ -125,11 +121,7 @@ export const VideoMattingQueueItem: React.FC<{);const messages =job.status === 'idle'- ? [- 'outName' in job- ? 'Queued for background removal'- : 'Queued for video matting',- ]+ ? ['Queued for background removal']: job.status === 'running' || job.status === 'saving'? [job.progress.message, job.progress.detail].filter((message): message is string => message !== null,@@ -138,9 +130,7 @@ export const VideoMattingQueueItem: React.FC<{? [job.error.message]: job.status === 'cancelled'? ['Cancelled']- : 'outName' in job- ? [job.outName]- : [job.baseOutName, job.foregroundOutName];+ : [job.outName];const tooltip = messages.join('\n');const revealAsset = useCallback((assetName: string) => {@@ -149,7 +139,7 @@ export const VideoMattingQueueItem: React.FC<{},[selectAsset],);- const outputName = 'outName' in job ? job.outName : job.foregroundOutName;+ const outputName = job.outName;const onClick = useCallback(() => {if (!done) return;revealAsset(outputName);@@ -207,11 +197,7 @@ export const VideoMattingQueueItem: React.FC<{) : job.status === 'failed' ? (<QueueJobErrorerror={job.error}- modalTitle={- 'outName' in job- ? 'Background removal failed'- : 'Video matting failed'- }+ modalTitle="Background removal failed"/>) : (messages.map((message) => (diff --git a/packages/studio/src/components/RenderQueue/VideoMattingQueueProcessor.tsx b/packages/studio/src/components/RenderQueue/VideoMattingQueueProcessor.tsxindex b789c76d7c..771bb52149 100644--- a/packages/studio/src/components/RenderQueue/VideoMattingQueueProcessor.tsx+++ b/packages/studio/src/components/RenderQueue/VideoMattingQueueProcessor.tsx@@ -5,7 +5,6 @@ import {isVideoMattingModelCached,loadVideoMattingModel,removeVideoBackground,- separateVideoLayers,type RemoveVideoBackgroundResult,type SeparateVideoLayersProgress,} from '@remotion/video-matting';@@ -31,10 +30,7 @@ export const VideoMattingQueueProcessor: React.FC = () => {const processJob = useCallback(async (job: VideoMattingJob) => {const {signal} = getAbortController(job.id);- let outputs:- | Awaited<ReturnType<typeof separateVideoLayers>>- | RemoveVideoBackgroundResult- | null = null;+ let output: RemoveVideoBackgroundResult | null = null;let processingError: Error | null = null;try {signal.throwIfAborted();@@ -84,18 +80,16 @@ export const VideoMattingQueueProcessor: React.FC = () => {message:progress.stage === 'finalizing'? 'Finalizing video...'- : 'outName' in job- ? 'Removing background...'- : 'Separating foreground...',+ : 'Removing background...',value: 0.2 + (progress.progress ?? 1) * 0.65,});},};- outputs =- 'outName' in job- ? await removeVideoBackground({...mattingOptions, audio: job.audio})- : await separateVideoLayers({...mattingOptions, audio: job.audio});- if (outputs === null) {+ output = await removeVideoBackground({+ ...mattingOptions,+ audio: job.audio,+ });+ if (output === null) {throw new Error('Video matting produced no output.');}@@ -105,32 +99,14 @@ export const VideoMattingQueueProcessor: React.FC = () => {message: 'Saving video...',value: 0.88,});- const foreground = await (- 'video' in outputs ? outputs.video : outputs.foreground- ).getBlob();- const base = 'base' in outputs ? await outputs.base.getBlob() : null;+ const video = await output.video.getBlob();signal.throwIfAborted();markVideoMattingJobSaving(job.id);- if ('outName' in job) {- await foreground- .arrayBuffer()- .then((contents) =>- writeStaticFile({contents, filePath: job.outName}),- );- } else {- await Promise.all([- base!- .arrayBuffer()- .then((contents) =>- writeStaticFile({contents, filePath: job.baseOutName}),- ),- foreground- .arrayBuffer()- .then((contents) =>- writeStaticFile({contents, filePath: job.foregroundOutName}),- ),- ]);- }+ await video+ .arrayBuffer()+ .then((contents) =>+ writeStaticFile({contents, filePath: job.outName}),+ );if (job.target !== null) {updateVideoMattingJobProgress(job.id, {@@ -139,38 +115,21 @@ export const VideoMattingQueueProcessor: React.FC = () => {value: 0.97,});const browserStudioOperations = getBrowserStudioOperations();- if ('outName' in job) {- const request = {- fileName: job.target.fileName,- nodePath: job.target.nodePath.nodePath,- src: job.outName,- };- const replaceSource = browserStudioOperations?.replaceVideoSource;- if (browserStudioOperations && !replaceSource) {- throw new Error(- 'Browser Studio cannot replace the video source.',- );- }+ const request = {+ fileName: job.target.fileName,+ nodePath: job.target.nodePath.nodePath,+ src: job.outName,+ };+ const replaceSource = browserStudioOperations?.replaceVideoSource;+ if (browserStudioOperations && !replaceSource) {+ throw new Error('Browser Studio cannot replace the video source.');+ }- const response = replaceSource- ? await replaceSource(request)- : await callApi('/api/replace-video-source', request);- if (!response.success) {- throw new Error(response.reason);- }- } else {- const request = {- fileName: job.target.fileName,- nodePath: job.target.nodePath.nodePath,- baseSrc: job.baseOutName,- foregroundSrc: job.foregroundOutName,- };- const response = browserStudioOperations- ? await browserStudioOperations.insertVideoLayers(request)- : await callApi('/api/insert-video-layers', request);- if (!response.success) {- throw new Error(response.reason);- }+ const response = replaceSource+ ? await replaceSource(request)+ : await callApi('/api/replace-video-source', request);+ if (!response.success) {+ throw new Error(response.reason);}}} catch (error) {@@ -178,13 +137,8 @@ export const VideoMattingQueueProcessor: React.FC = () => {error instanceof Error ? error : new Error(String(error));}- if (outputs) {- await Promise.allSettled([- 'base' in outputs ? outputs.base.dispose() : null,- 'video' in outputs- ? outputs.video.dispose()- : outputs.foreground.dispose(),- ]);+ if (output) {+ await Promise.allSettled([output.video.dispose()]);}try {diff --git a/packages/studio/src/components/RenderQueue/index.tsx b/packages/studio/src/components/RenderQueue/index.tsxindex a9b5c68319..160a7437bc 100644--- a/packages/studio/src/components/RenderQueue/index.tsx+++ b/packages/studio/src/components/RenderQueue/index.tsx@@ -100,10 +100,7 @@ export const RenderQueue: React.FC = () => {if (isVideoMattingJob(job) &&job.status === 'done' &&- ('outName' in job- ? canvasContent.asset === job.outName- : canvasContent.asset === job.baseOutName ||- canvasContent.asset === job.foregroundOutName)+ canvasContent.asset === job.outName) {return i;}diff --git a/packages/studio/src/components/RenderQueue/video-matting-job-types.ts b/packages/studio/src/components/RenderQueue/video-matting-job-types.tsindex d9e691894f..390d3d4bb6 100644--- a/packages/studio/src/components/RenderQueue/video-matting-job-types.ts+++ b/packages/studio/src/components/RenderQueue/video-matting-job-types.ts@@ -1,5 +1,4 @@import type {- VideoLayerAudio,VideoMattingBitrate,VideoMattingModel,} from '@remotion/video-matting';@@ -23,24 +22,15 @@ type VideoMattingJobCommon = {displayName: string;model: VideoMattingModel;videoBitrate: VideoMattingBitrate;+ outName: string;+ audio: 'keep' | 'none';target: {fileName: string;nodePath: SequencePropsSubscriptionKey;} | null;};-export type AddVideoMattingJobParams = VideoMattingJobCommon &- (- | {- outName: string;- audio: 'keep' | 'none';- }- | {- baseOutName: string;- foregroundOutName: string;- audio: VideoLayerAudio;- }- );+export type AddVideoMattingJobParams = VideoMattingJobCommon;export type VideoMattingJob = AddVideoMattingJobParams & {id: string;diff --git a/packages/studio/src/components/VideoMatting/VideoMattingModal.tsx b/packages/studio/src/components/VideoMatting/VideoMattingModal.tsxindex 0ce16fea6f..e17a9c8b10 100644--- a/packages/studio/src/components/VideoMatting/VideoMattingModal.tsx+++ b/packages/studio/src/components/VideoMatting/VideoMattingModal.tsx@@ -161,11 +161,7 @@ export const VideoMattingModal: React.FC<VideoMattingModalState> = ({job.status === 'running' ||job.status === 'saving',)- .flatMap((job) =>- 'outName' in job- ? [job.outName]- : [job.baseOutName, job.foregroundOutName],- )+ .map((job) => job.outName).map((name) => name.normalize('NFC').toLowerCase()),);const outputError =diff --git a/packages/studio/src/test/make-browser-studio-operations.ts b/packages/studio/src/test/make-browser-studio-operations.tsindex 5c803b9f94..f3b81af641 100644--- a/packages/studio/src/test/make-browser-studio-operations.ts+++ b/packages/studio/src/test/make-browser-studio-operations.ts@@ -54,7 +54,6 @@ export const makeBrowserStudioOperations = (splitJsxSequence: () => unusedOperation('splitJsxSequence'),splitVideoFromAudio: () => unusedOperation('splitVideoFromAudio'),insertBasicCaptions: () => unusedOperation('insertBasicCaptions'),- insertVideoLayers: () => unusedOperation('insertVideoLayers'),subscribeToDefaultProps: () => unusedOperation('subscribeToDefaultProps'),subscribeToEvent: () => unusedOperation('subscribeToEvent'),subscribeToSequenceProps: () => unusedOperation('subscribeToSequenceProps'),diff --git a/packages/studio/src/test/queue-job-errors.test.tsx b/packages/studio/src/test/queue-job-errors.test.tsxindex 1a904e7033..a3ca0fbf7c 100644--- a/packages/studio/src/test/queue-job-errors.test.tsx+++ b/packages/studio/src/test/queue-job-errors.test.tsx@@ -66,10 +66,9 @@ const mattingJob: VideoMattingJob = {startedAt: 0,src: '/video.mp4',displayName: 'video.mp4',- baseOutName: 'video-base.webm',- foregroundOutName: 'video-foreground.webm',+ outName: 'video-no-background.webm',model: 'ben2-base',- audio: 'base',+ audio: 'keep',videoBitrate: 'medium',target: null,status: 'failed',@@ -142,7 +141,7 @@ test('opens and copies transcription and video matting errors', async () => {fireEvent.click(screen.getByRole('button', {name: mattingJob.error.message}));const mattingDialog = screen.getByRole('dialog', {- name: 'Video matting failed',+ name: 'Background removal failed',});expect(mattingDialog.textContent).toContain(`${mattingJob.error.message}\n${mattingJob.error.stack}`,diff --git a/packages/studio/src/test/render-queue-scheduler.test.tsx b/packages/studio/src/test/render-queue-scheduler.test.tsxindex c8a575d643..bae68d360d 100644--- a/packages/studio/src/test/render-queue-scheduler.test.tsx+++ b/packages/studio/src/test/render-queue-scheduler.test.tsx@@ -60,10 +60,9 @@ const makeStillParams = (compositionId: string): AddClientStillJobParams => ({});const videoMattingParams: AddVideoMattingJobParams = {- audio: 'base',- baseOutName: 'video-base.webm',+ audio: 'keep',displayName: 'video.mp4',- foregroundOutName: 'video-foreground.webm',+ outName: 'video-no-background.webm',model: 'ben2-base',src: '/video.mp4',target: null,diff --git a/packages/studio/src/test/video-matting-queue-processor.test.tsx b/packages/studio/src/test/video-matting-queue-processor.test.tsxindex 62741db160..0c7db37a1b 100644--- a/packages/studio/src/test/video-matting-queue-processor.test.tsx+++ b/packages/studio/src/test/video-matting-queue-processor.test.tsx@@ -27,7 +27,7 @@ mock.module('@remotion/video-matting', () => ({calls.push('load-model');return Promise.resolve({alreadyLoaded: false});},- separateVideoLayers: ({+ removeVideoBackground: ({onProgress,}: {onProgress: (progress: {@@ -36,15 +36,11 @@ mock.module('@remotion/video-matting', () => ({processedFrames: number;}) => void;}) => {- calls.push('separate');+ calls.push('remove-background');onProgress({stage: 'processing', progress: 0.5, processedFrames: 42});return Promise.resolve({- base: {- getBlob: () => Promise.resolve(new Blob(['base'])),- dispose: () => Promise.resolve(),- },- foreground: {- getBlob: () => Promise.resolve(new Blob(['foreground'])),+ video: {+ getBlob: () => Promise.resolve(new Blob(['video'])),dispose: () => Promise.resolve(),},});@@ -61,7 +57,7 @@ afterEach(() => {processJob = null;});-test('writes both layers and inserts them into the selected video source', async () => {+test('writes the transparent video and replaces the selected video source', async () => {const originalBrowserStudio = Object.getOwnPropertyDescriptor(window,'remotion_browserStudio',@@ -69,10 +65,8 @@ test('writes both layers and inserts them into the selected video source', asyncObject.defineProperty(window, 'remotion_browserStudio', {configurable: true,value: makeBrowserStudioOperations({- insertVideoLayers: ({baseSrc, foregroundSrc, fileName, nodePath}) => {- calls.push(- `insert:${fileName}:${nodePath.join('.')}:${baseSrc}:${foregroundSrc}`,- );+ replaceVideoSource: ({src, fileName, nodePath}) => {+ calls.push(`replace:${fileName}:${nodePath.join('.')}:${src}`);return Promise.resolve({success: true,nodePathMutation: {} as never,@@ -124,10 +118,9 @@ test('writes both layers and inserts them into the selected video source', asyncstartedAt: 1,src: '/input.webm',displayName: 'input.webm',- baseOutName: 'input-base.webm',- foregroundOutName: 'input-foreground.webm',+ outName: 'input-no-background.webm',model: 'modnet',- audio: 'base',+ audio: 'keep',target: {fileName: '/project/Composition.tsx',nodePath: {@@ -147,10 +140,9 @@ test('writes both layers and inserts them into the selected video source', asyncexpect(calls).toEqual(['download-model','load-model',- 'separate',- 'write:input-base.webm',- 'write:input-foreground.webm',- 'insert:/project/Composition.tsx:Comp.0:input-base.webm:input-foreground.webm',+ 'remove-background',+ 'write:input-no-background.webm',+ 'replace:/project/Composition.tsx:Comp.0:input-no-background.webm','dispose-model',]);expect(progress).toContainEqual({@@ -160,7 +152,7 @@ test('writes both layers and inserts them into the selected video source', async});expect(progress).toContainEqual({detail: 'Processed 42 frames · 50%',- message: 'Separating foreground...',+ message: 'Removing background...',value: 0.525,});if (originalBrowserStudio) {