Skip to content

🎥 Make videos programmatically with React

display progress

Jonny Burger08dc56ad5b24
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.ts
index 88bea67ec3..f3e519fe14 100644
--- a/packages/cli/src/benchmark.ts
+++ b/packages/cli/src/benchmark.ts
@@ -188,6 +188,7 @@ export const benchmarkCommand = async (
publicDir,
remotionRoot,
steps: ['bundling'],
+ onProgress: () => undefined,
});
const puppeteerInstance = await browserInstance;
diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.ts
index 6dfb2a89e9..835f533e6f 100644
--- a/packages/cli/src/compositions.ts
+++ b/packages/cli/src/compositions.ts
@@ -54,6 +54,7 @@ export const listCompositionsCommand = async (
fullPath,
steps: ['bundling'],
publicDir,
+ onProgress: () => undefined,
});
const compositions = await getCompositions(bundled, {
diff --git a/packages/cli/src/editor/components/RenderQueue/RenderQueueItemStatus.tsx b/packages/cli/src/editor/components/RenderQueue/RenderQueueItemStatus.tsx
index 51c0a20928..8a0908ee5f 100644
--- a/packages/cli/src/editor/components/RenderQueue/RenderQueueItemStatus.tsx
+++ b/packages/cli/src/editor/components/RenderQueue/RenderQueueItemStatus.tsx
@@ -50,8 +50,7 @@ export const RenderQueueItemStatus: React.FC<{
}
if (job.status === 'running') {
- // TODO: Put job progress
- return <CircularProgress progress={0.5} />;
+ return <CircularProgress progress={job.progress} />;
}
throw new Error('Unknown job status');
diff --git a/packages/cli/src/preview-server/render-queue/job.ts b/packages/cli/src/preview-server/render-queue/job.ts
index 5d4fb02c30..e0100c09ed 100644
--- a/packages/cli/src/preview-server/render-queue/job.ts
+++ b/packages/cli/src/preview-server/render-queue/job.ts
@@ -6,6 +6,8 @@ type RenderJobDynamicStatus =
}
| {
status: 'running';
+ progress: number;
+ message: string;
}
| {
status: 'idle';
@@ -18,6 +20,11 @@ type RenderJobDynamicStatus =
};
};
+export type JobProgressCallback = (options: {
+ progress: number;
+ message: string;
+}) => void;
+
type RenderJobDynamicFields =
| {
type: 'still';
diff --git a/packages/cli/src/preview-server/render-queue/process-still.ts b/packages/cli/src/preview-server/render-queue/process-still.ts
index 84a5d90e08..190f92899a 100644
--- a/packages/cli/src/preview-server/render-queue/process-still.ts
+++ b/packages/cli/src/preview-server/render-queue/process-still.ts
@@ -1,16 +1,18 @@
import {convertEntryPointToServeUrl} from '../../convert-entry-point-to-serve-url';
import {getCliOptions} from '../../get-cli-options';
import {renderStillFlow} from '../../render-flows/still';
-import type {RenderJob} from './job';
+import type {JobProgressCallback, RenderJob} from './job';
export const processStill = async ({
job,
remotionRoot,
entryPoint,
+ onProgress,
}: {
job: RenderJob;
remotionRoot: string;
entryPoint: string;
+ onProgress: JobProgressCallback;
}) => {
if (job.type !== 'still') {
throw new Error('Expected still job');
@@ -62,8 +64,8 @@ export const processStill = async ({
imageFormatFromUi: job.imageFormat,
configFileImageFormat,
logLevel,
+ onProgress,
});
- // TODO: Write download progress to CLI
// TODO: Allow cancel signal
// TODO: Accept CLI options
};
diff --git a/packages/cli/src/preview-server/render-queue/queue.ts b/packages/cli/src/preview-server/render-queue/queue.ts
index ecf5b141c6..f25abb7bef 100644
--- a/packages/cli/src/preview-server/render-queue/queue.ts
+++ b/packages/cli/src/preview-server/render-queue/queue.ts
@@ -1,7 +1,7 @@
import {installFileWatcher} from '../../file-watcher';
import {Log} from '../../log';
import {waitForLiveEventsListener} from '../live-events';
-import type {RenderJob, RenderJobWithCleanup} from './job';
+import type {JobProgressCallback, RenderJob, RenderJobWithCleanup} from './job';
import {processStill} from './process-still';
let jobQueue: RenderJobWithCleanup[] = [];
@@ -40,13 +40,15 @@ export const processJob = async ({
job,
remotionRoot,
entryPoint,
+ onProgress,
}: {
job: RenderJob;
remotionRoot: string;
entryPoint: string;
+ onProgress: JobProgressCallback;
}) => {
if (job.type === 'still') {
- await processStill({job, remotionRoot, entryPoint});
+ await processStill({job, remotionRoot, entryPoint, onProgress});
}
};
@@ -99,9 +101,25 @@ export const processJobIfPossible = async ({
return {
...job,
status: 'running',
+ progress: 0,
+ message: 'Starting job...',
};
});
- await processJob({job: nextJob, entryPoint, remotionRoot});
+ await processJob({
+ job: nextJob,
+ entryPoint,
+ remotionRoot,
+ onProgress: ({message, progress}) => {
+ updateJob(nextJob.id, (job) => {
+ return {
+ ...job,
+ status: 'running',
+ progress,
+ message,
+ };
+ });
+ },
+ });
const {unwatch} = installFileWatcher({
file: nextJob.outputLocation,
onChange: (type) => {
diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.ts
index 640ec05ac6..a8553862e1 100644
--- a/packages/cli/src/render-flows/still.ts
+++ b/packages/cli/src/render-flows/still.ts
@@ -24,6 +24,7 @@ import {getAndValidateAbsoluteOutputFile} from '../get-cli-options';
import {getCompositionWithDimensionOverride} from '../get-composition-with-dimension-override';
import {Log} from '../log';
import {parsedCli, quietFlagProvided} from '../parse-command-line';
+import type {JobProgressCallback} from '../preview-server/render-queue/job';
import type {DownloadProgress} from '../progress-bar';
import {
createOverwriteableCliOutput,
@@ -62,6 +63,7 @@ export const renderStillFlow = async ({
imageFormatFromUi,
logLevel,
configFileImageFormat,
+ onProgress,
}: {
remotionRoot: string;
fullEntryPoint: string;
@@ -87,6 +89,7 @@ export const renderStillFlow = async ({
imageFormatFromUi: StillImageFormat | null;
logLevel: LogLevel;
configFileImageFormat: ImageFormat | undefined;
+ onProgress: JobProgressCallback;
}) => {
const startTime = Date.now();
@@ -109,9 +112,22 @@ export const renderStillFlow = async ({
].filter(truthy);
const {cleanup: cleanupBundle, urlOrBundle} = await bundleOnCliOrTakeServeUrl(
- {fullPath: fullEntryPoint, remotionRoot, steps, publicDir}
+ {
+ fullPath: fullEntryPoint,
+ remotionRoot,
+ steps,
+ publicDir,
+ onProgress: (progress) => {
+ onProgress({message: 'Bundling...', progress});
+ },
+ }
);
+ onProgress({
+ message: 'Opening browser',
+ progress: 0,
+ });
+
const puppeteerInstance = await browserInstance;
const downloadMap = RenderInternals.makeDownloadMap();
@@ -137,6 +153,7 @@ export const renderStillFlow = async ({
args: remainingArgs,
compositionIdFromUi,
});
+
const {format: imageFormat, source} = determineFinalImageFormat({
cliFlag: parsedCli['image-format'] ?? null,
configImageFormat: configFileImageFormat ?? null,
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 921829079b..3ddbcc3018 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -125,6 +125,7 @@ export const render = async (remotionRoot: string, args: string[]) => {
remotionRoot,
steps,
publicDir,
+ onProgress: () => undefined,
}
);
diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.ts
index f8a132e284..fcb8df2c31 100644
--- a/packages/cli/src/setup-cache.ts
+++ b/packages/cli/src/setup-cache.ts
@@ -20,11 +20,13 @@ export const bundleOnCliOrTakeServeUrl = async ({
remotionRoot,
steps,
publicDir,
+ onProgress,
}: {
fullPath: string;
remotionRoot: string;
steps: RenderStep[];
publicDir: string | null;
+ onProgress: (prog: number) => void;
}): Promise<{
urlOrBundle: string;
cleanup: () => Promise<void>;
@@ -36,7 +38,13 @@ export const bundleOnCliOrTakeServeUrl = async ({
};
}
- const bundled = await bundleOnCli({fullPath, remotionRoot, steps, publicDir});
+ const bundled = await bundleOnCli({
+ fullPath,
+ remotionRoot,
+ steps,
+ publicDir,
+ onProgress,
+ });
return {
urlOrBundle: bundled,
@@ -49,11 +57,13 @@ export const bundleOnCli = async ({
steps,
remotionRoot,
publicDir,
+ onProgress: progCallback,
}: {
fullPath: string;
steps: RenderStep[];
remotionRoot: string;
publicDir: string | null;
+ onProgress: (prog: number) => void;
}) => {
const shouldCache = ConfigInternals.getWebpackCaching();
@@ -74,6 +84,7 @@ export const bundleOnCli = async ({
symLinks: symlinkState,
})
);
+ progCallback(progress / 100);
};
let copyingState: CopyingState = {
diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.ts
index a43f885cee..7899720bbe 100644
--- a/packages/cli/src/still.ts
+++ b/packages/cli/src/still.ts
@@ -80,5 +80,6 @@ export const still = async (remotionRoot: string, args: string[]) => {
imageFormatFromUi: null,
configFileImageFormat,
logLevel,
+ onProgress: () => undefined,
});
};