Skip to content

🎥 Make videos programmatically with React

Show detailed video matting progress

JonnyBurgerf9b16a301801
diff --git a/packages/studio/src/components/RenderQueue/VideoMattingQueueItem.tsx b/packages/studio/src/components/RenderQueue/VideoMattingQueueItem.tsx
index cee5bd4407..4f21f070e1 100644
--- a/packages/studio/src/components/RenderQueue/VideoMattingQueueItem.tsx
+++ b/packages/studio/src/components/RenderQueue/VideoMattingQueueItem.tsx
@@ -40,6 +40,11 @@ const subtitle: React.CSSProperties = {
...renderQueueItemSubtitleStyle,
cursor: 'default',
};
+const subtitles: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'column',
+ overflow: 'hidden',
+};
const statusIcon: React.CSSProperties = {
height: RENDER_STATUS_INDICATOR_SIZE,
width: RENDER_STATUS_INDICATOR_SIZE,
@@ -102,14 +107,17 @@ export const VideoMattingQueueItem: React.FC<{
}),
[done, hovered, selected],
);
- const message =
+ const messages =
job.status === 'idle'
- ? 'Queued for video matting'
+ ? ['Queued for video matting']
: job.status === 'running'
- ? job.progress.message
+ ? [job.progress.message, job.progress.detail].filter(
+ (message): message is string => message !== null,
+ )
: job.status === 'failed'
- ? job.error.message
- : `${job.baseOutName} · ${job.foregroundOutName}`;
+ ? [job.error.message]
+ : [job.baseOutName, job.foregroundOutName];
+ const tooltip = messages.join('\n');
const onClick = useCallback(() => {
if (!done) return;
selectAsset(job.foregroundOutName);
@@ -146,9 +154,13 @@ export const VideoMattingQueueItem: React.FC<{
<Spacing x={1} />
<div style={right}>
<div style={title}>{job.displayName}</div>
- <span style={subtitle} title={message}>
- {message}
- </span>
+ <div style={subtitles} title={tooltip}>
+ {messages.map((message) => (
+ <span key={message} style={subtitle}>
+ {message}
+ </span>
+ ))}
+ </div>
</div>
<Spacing x={1} />
{job.status === 'running' ? null : (
diff --git a/packages/studio/src/components/RenderQueue/VideoMattingQueueProcessor.tsx b/packages/studio/src/components/RenderQueue/VideoMattingQueueProcessor.tsx
index 05cf3afce5..8063683a57 100644
--- a/packages/studio/src/components/RenderQueue/VideoMattingQueueProcessor.tsx
+++ b/packages/studio/src/components/RenderQueue/VideoMattingQueueProcessor.tsx
@@ -26,6 +26,7 @@ export const VideoMattingQueueProcessor: React.FC = () => {
let processingError: Error | null = null;
try {
updateVideoMattingJobProgress(job.id, {
+ detail: null,
message: 'Checking WebGPU support...',
value: 0,
});
@@ -45,7 +46,10 @@ export const VideoMattingQueueProcessor: React.FC = () => {
onProgress: (progress) => onProgress(progress.progress),
}),
updateProgress: (progress) =>
- updateVideoMattingJobProgress(job.id, progress),
+ updateVideoMattingJobProgress(job.id, {
+ ...progress,
+ detail: null,
+ }),
});
outputs = await separateVideoLayers({
@@ -55,16 +59,21 @@ export const VideoMattingQueueProcessor: React.FC = () => {
videoBitrate: job.videoBitrate,
onProgress: (progress) => {
updateVideoMattingJobProgress(job.id, {
+ detail:
+ progress.stage === 'finalizing'
+ ? `Processed ${progress.processedFrames} ${progress.processedFrames === 1 ? 'frame' : 'frames'}`
+ : `Processed ${progress.processedFrames} ${progress.processedFrames === 1 ? 'frame' : 'frames'} · ${Math.round(progress.progress * 100)}%`,
message:
progress.stage === 'finalizing'
? 'Finalizing video layers...'
- : `Processed ${progress.processedFrames} ${progress.processedFrames === 1 ? 'frame' : 'frames'} · ${Math.round(progress.progress * 100)}%`,
+ : 'Separating foreground...',
value: 0.2 + (progress.progress ?? 1) * 0.65,
});
},
});
updateVideoMattingJobProgress(job.id, {
+ detail: null,
message: 'Saving video layers...',
value: 0.88,
});
diff --git a/packages/studio/src/components/RenderQueue/context.tsx b/packages/studio/src/components/RenderQueue/context.tsx
index 83b3adade3..9366fe4fab 100644
--- a/packages/studio/src/components/RenderQueue/context.tsx
+++ b/packages/studio/src/components/RenderQueue/context.tsx
@@ -244,7 +244,11 @@ export const RenderQueueContextProvider: React.FC<{
? {
...job,
status: 'running',
- progress: {message: 'Starting video matting...', value: 0},
+ progress: {
+ detail: null,
+ message: 'Starting video matting...',
+ value: 0,
+ },
}
: job,
),
diff --git a/packages/studio/src/components/RenderQueue/video-matting-job-types.ts b/packages/studio/src/components/RenderQueue/video-matting-job-types.ts
index 0c4fa18e53..7ecd97d7c4 100644
--- a/packages/studio/src/components/RenderQueue/video-matting-job-types.ts
+++ b/packages/studio/src/components/RenderQueue/video-matting-job-types.ts
@@ -5,6 +5,7 @@ import type {
} from '@remotion/video-matting';
export type VideoMattingJobProgress = {
+ detail: string | null;
message: string;
value: number;
};
diff --git a/packages/studio/src/test/video-matting-queue-processor.test.tsx b/packages/studio/src/test/video-matting-queue-processor.test.tsx
index 6b2fe0af8b..aa1cf3c2d2 100644
--- a/packages/studio/src/test/video-matting-queue-processor.test.tsx
+++ b/packages/studio/src/test/video-matting-queue-processor.test.tsx
@@ -2,7 +2,10 @@ import {afterEach, expect, mock, test} from 'bun:test';
import {act, cleanup, render, waitFor} from '@testing-library/react';
import type {ContextType} from 'react';
import {RenderQueueContext} from '../components/RenderQueue/context';
-import type {VideoMattingJob} from '../components/RenderQueue/video-matting-job-types';
+import type {
+ VideoMattingJob,
+ VideoMattingJobProgress,
+} from '../components/RenderQueue/video-matting-job-types';
import {makeBrowserStudioOperations} from './make-browser-studio-operations';
const calls: string[] = [];
@@ -68,15 +71,18 @@ test('loads the model, separates the layers and writes both outputs', async () =
},
}),
});
- const progress: string[] = [];
+ const progress: VideoMattingJobProgress[] = [];
let done = false;
let failed: Error | null = null;
const value = {
setProcessVideoMattingJobCallback: (callback: typeof processJob) => {
processJob = callback;
},
- updateVideoMattingJobProgress: (_id: string, update: {message: string}) => {
- progress.push(update.message);
+ updateVideoMattingJobProgress: (
+ _id: string,
+ update: VideoMattingJobProgress,
+ ) => {
+ progress.push(update);
},
markVideoMattingJobDone: () => {
done = true;
@@ -120,8 +126,16 @@ test('loads the model, separates the layers and writes both outputs', async () =
'write:input-foreground.webm',
'dispose-model',
]);
- expect(progress).toContain('Downloading modnet 100%');
- expect(progress).toContain('Processed 42 frames · 50%');
+ expect(progress).toContainEqual({
+ detail: null,
+ message: 'Downloading modnet 100%',
+ value: 0.2,
+ });
+ expect(progress).toContainEqual({
+ detail: 'Processed 42 frames · 50%',
+ message: 'Separating foreground...',
+ value: 0.525,
+ });
if (originalBrowserStudio) {
Object.defineProperty(
window,