🎥 Make videos programmatically with React
show progress
Jonny Burgercc05c272a345
diff --git a/packages/cli/src/editor/components/RenderQueue/CircularProgress.tsx b/packages/cli/src/editor/components/RenderQueue/CircularProgress.tsxindex 28cb831684..187c29c26b 100644--- a/packages/cli/src/editor/components/RenderQueue/CircularProgress.tsx+++ b/packages/cli/src/editor/components/RenderQueue/CircularProgress.tsx@@ -31,9 +31,8 @@ export const CircularProgress: React.FC<{cy={RENDER_STATUS_INDICATOR_SIZE / 2}strokeDasharray={`${circumference} ${circumference}`}strokeMiterlimit={0}- strokeDashoffset={progress * circumference}+ strokeDashoffset={(1 - progress) * circumference}/>- {progress}</svg>);};diff --git a/packages/cli/src/progress-bar.ts b/packages/cli/src/progress-bar.tsindex 06eaec2bcc..e8bacc599f 100644--- a/packages/cli/src/progress-bar.ts+++ b/packages/cli/src/progress-bar.ts@@ -28,7 +28,13 @@ export const createProgressBar = (return createOverwriteableCliOutput(quiet);};-export const createOverwriteableCliOutput = (quiet: boolean) => {+export type OverwriteableCliOutput = {+ update: (up: string) => boolean;+};++export const createOverwriteableCliOutput = (+ quiet: boolean+): OverwriteableCliOutput => {if (quiet) {return {update: () => false,@@ -198,20 +204,32 @@ export type DownloadProgress = {downloaded: number;};+export type AggregateRenderProgress = {+ rendering: RenderingProgressInput | null;+ stitching: StitchingProgressInput | null;+ downloads: DownloadProgress[];+ bundling: number;+};+export const makeRenderingAndStitchingProgress = ({rendering,stitching,downloads,-}: {- rendering: RenderingProgressInput;- stitching: StitchingProgressInput | null;- downloads: DownloadProgress[];-}) => {- return [- makeRenderingProgress(rendering),+ bundling,+}: AggregateRenderProgress) => {+ const output = [+ rendering ? makeRenderingProgress(rendering) : null,makeMultiDownloadProgress(downloads),stitching === null ? null : makeStitchingProgress(stitching),].filter(truthy).join('\n');+ const renderProgress = rendering+ ? rendering.frames / rendering.totalFrames+ : 0;++ // TODO: Factor in stitching progress+ const progress = bundling * 0.3 + renderProgress * 0.7;++ return {output, progress};};diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.tsindex a8553862e1..db7472f08c 100644--- a/packages/cli/src/render-flows/still.ts+++ b/packages/cli/src/render-flows/still.ts@@ -25,7 +25,11 @@ import {getCompositionWithDimensionOverride} from '../get-composition-with-dimenimport {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 type {+ AggregateRenderProgress,+ DownloadProgress,+ OverwriteableCliOutput,+} from '../progress-bar';import {createOverwriteableCliOutput,makeRenderingAndStitchingProgress,@@ -92,6 +96,25 @@ export const renderStillFlow = async ({onProgress: JobProgressCallback;}) => {const startTime = Date.now();+ const downloads: DownloadProgress[] = [];++ const aggregate: AggregateRenderProgress = {+ rendering: null,+ downloads,+ stitching: null,+ bundling: 1,+ };+ let renderProgress: OverwriteableCliOutput | null = null;++ const updateProgress = () => {+ const {output, progress} = makeRenderingAndStitchingProgress(aggregate);+ if (renderProgress) {+ renderProgress.update(output);+ }++ // TODO: Better message than Rendering...+ onProgress({progress, message: 'Rendering...'});+ };Log.verbose('Browser executable: ', browserExecutable);const shouldDumpIo = RenderInternals.isEqualOrBelowLogLevel(@@ -118,16 +141,12 @@ export const renderStillFlow = async ({steps,publicDir,onProgress: (progress) => {- onProgress({message: 'Bundling...', progress});+ aggregate.bundling = progress;+ updateProgress();},});- onProgress({- message: 'Opening browser',- progress: 0,- });-const puppeteerInstance = await browserInstance;const downloadMap = RenderInternals.makeDownloadMap();@@ -184,27 +203,15 @@ export const renderStillFlow = async ({));- const renderProgress = createOverwriteableCliOutput(quietFlagProvided());+ renderProgress = createOverwriteableCliOutput(quietFlagProvided());const renderStart = Date.now();- const downloads: DownloadProgress[] = [];- let frames = 0;- const totalFrames = 1;-- const updateProgress = () => {- renderProgress.update(- makeRenderingAndStitchingProgress({- rendering: {- frames,- concurrency: 1,- doneIn: frames === totalFrames ? Date.now() - renderStart : null,- steps,- totalFrames,- },- downloads,- stitching: null,- })- );+ aggregate.rendering = {+ frames: 0,+ concurrency: 1,+ doneIn: null,+ steps,+ totalFrames: 1,};updateProgress();@@ -248,7 +255,13 @@ export const renderStillFlow = async ({downloadMap,});- frames = 1;+ aggregate.rendering = {+ frames: 1,+ concurrency: 1,+ doneIn: Date.now() - renderStart,+ steps,+ totalFrames: 1,+ };updateProgress();Log.info();diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 3ddbcc3018..5b5291a995 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -229,28 +229,28 @@ export const render = async (remotionRoot: string, args: string[]) => {throw new Error('totalFrames should not be 0');}- return renderProgress.update(- makeRenderingAndStitchingProgress({- rendering: {- frames: renderedFrames,- totalFrames: totalFrames.length,- concurrency: RenderInternals.getActualConcurrency(concurrency),- doneIn: renderedDoneIn,- steps,- },- stitching: shouldOutputImageSequence- ? null- : {- doneIn: encodedDoneIn,- frames: encodedFrames,- stage: stitchStage,- steps,- totalFrames: totalFrames.length,- codec,- },- downloads,- })- );+ const {output} = makeRenderingAndStitchingProgress({+ rendering: {+ frames: renderedFrames,+ totalFrames: totalFrames.length,+ concurrency: RenderInternals.getActualConcurrency(concurrency),+ doneIn: renderedDoneIn,+ steps,+ },+ stitching: shouldOutputImageSequence+ ? null+ : {+ doneIn: encodedDoneIn,+ frames: encodedFrames,+ stage: stitchStage,+ steps,+ totalFrames: totalFrames.length,+ codec,+ },+ downloads,+ bundling: 1,+ });+ return renderProgress.update(output);};const imageFormat = getImageFormat(