Skip to content

🎥 Make videos programmatically with React

cool artifacts

Jonny Burger2fc2eb9ab431
diff --git a/packages/cli/src/on-artifact.ts b/packages/cli/src/on-artifact.ts
index 715d025cd5..c93f287faa 100644
--- a/packages/cli/src/on-artifact.ts
+++ b/packages/cli/src/on-artifact.ts
@@ -4,9 +4,10 @@ import {writeFileSync} from 'fs';
import path from 'path';
export const handleOnArtifact = (
+ artifactState: ArtifactProgress,
onProgress: (artifact: ArtifactProgress) => void,
) => {
- const progress: ArtifactProgress = {received: []};
+ const initialProgress = {...artifactState};
const onArtifact: OnArtifact = (artifact) => {
// TODO: Normalize backslashes on Windows
@@ -16,17 +17,16 @@ export const handleOnArtifact = (
);
writeFileSync(artifact.filename, artifact.content);
- progress.received.push({
+ initialProgress.received.push({
absoluteOutputDestination,
filename: artifact.filename,
sizeInBytes: artifact.content.length,
});
};
- onProgress(progress);
+ onProgress(initialProgress);
return {
onArtifact,
- initialProgress: progress,
};
};
diff --git a/packages/cli/src/progress-bar.ts b/packages/cli/src/progress-bar.ts
index cc57ecd88e..20cc2ca1b1 100644
--- a/packages/cli/src/progress-bar.ts
+++ b/packages/cli/src/progress-bar.ts
@@ -8,6 +8,7 @@ import type {
StitchingProgressInput,
} from '@remotion/studio-server';
import {StudioServerInternals} from '@remotion/studio-server';
+import {formatBytes, type ArtifactProgress} from '@remotion/studio-shared';
import {chalk} from './chalk';
import {
getFileSizeDownloadBar,
@@ -192,6 +193,30 @@ const makeRenderingProgress = ({
.join(' ');
};
+const makeArtifactProgress = (artifactState: ArtifactProgress) => {
+ const {received} = artifactState;
+ if (received.length === 0) {
+ return null;
+ }
+
+ return received
+ .map((artifact) => {
+ return [
+ chalk.blue('+'.padEnd(LABEL_WIDTH)),
+ chalk.blue(
+ makeHyperlink({
+ url: 'file://' + artifact.absoluteOutputDestination,
+ fallback: artifact.filename,
+ text: artifact.filename,
+ }),
+ ),
+ chalk.gray(`${formatBytes(artifact.sizeInBytes)}`),
+ ].join(' ');
+ })
+ .filter(truthy)
+ .join('\n');
+};
+
export const getRightLabelWidth = (totalFrames: number) => {
return `${totalFrames}/${totalFrames}`.length;
};
@@ -237,7 +262,7 @@ export const makeRenderingAndStitchingProgress = ({
progress: number;
message: string;
} => {
- const {rendering, stitching, downloads, bundling} = prog;
+ const {rendering, stitching, downloads, bundling, artifactState} = prog;
const output = [
rendering ? makeRenderingProgress(rendering) : null,
makeMultiDownloadProgress(downloads, rendering?.totalFrames ?? 0),
@@ -247,6 +272,7 @@ export const makeRenderingAndStitchingProgress = ({
stitchingProgress: stitching,
isUsingParallelEncoding,
}),
+ makeArtifactProgress(artifactState),
]
.filter(truthy)
.join('\n');
diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.ts
index 82c8260085..89983aeb57 100644
--- a/packages/cli/src/render-flows/render.ts
+++ b/packages/cli/src/render-flows/render.ts
@@ -28,6 +28,7 @@ import type {
RenderingProgressInput,
StitchingProgressInput,
} from '@remotion/studio-server';
+import type {ArtifactProgress} from '@remotion/studio-shared';
import fs, {existsSync} from 'node:fs';
import os from 'node:os';
import path from 'node:path';
@@ -220,12 +221,7 @@ export const renderVideoFlow = async ({
doneIn: null,
};
- let {onArtifact, initialProgress: artifactState} = handleOnArtifact(
- (progress) => {
- artifactState = progress;
- updateRenderProgress({newline: false, printToConsole: true});
- },
- );
+ let artifactState: ArtifactProgress = {received: []};
const updateRenderProgress = ({
newline,
@@ -254,6 +250,11 @@ export const renderVideoFlow = async ({
}
};
+ const {onArtifact} = handleOnArtifact(artifactState, (progress) => {
+ artifactState = progress;
+ updateRenderProgress({newline: false, printToConsole: true});
+ });
+
const {urlOrBundle, cleanup: cleanupBundle} = await bundleOnCliOrTakeServeUrl(
{
fullPath: fullEntryPoint,