Skip to content

🎥 Make videos programmatically with React

artifact state

Jonny Burgerfcbcac71bd28
diff --git a/packages/cli/src/on-artifact.ts b/packages/cli/src/on-artifact.ts
index 869d7d40f3..715d025cd5 100644
--- a/packages/cli/src/on-artifact.ts
+++ b/packages/cli/src/on-artifact.ts
@@ -1,6 +1,32 @@
import type {OnArtifact} from '@remotion/renderer';
+import type {ArtifactProgress} from '@remotion/studio-shared';
import {writeFileSync} from 'fs';
+import path from 'path';
-export const onArtifactOnCli: OnArtifact = (artifact) => {
- writeFileSync(artifact.filename, artifact.content);
+export const handleOnArtifact = (
+ onProgress: (artifact: ArtifactProgress) => void,
+) => {
+ const progress: ArtifactProgress = {received: []};
+
+ const onArtifact: OnArtifact = (artifact) => {
+ // TODO: Normalize backslashes on Windows
+ const absoluteOutputDestination = path.join(
+ process.cwd(),
+ artifact.filename,
+ );
+ writeFileSync(artifact.filename, artifact.content);
+
+ progress.received.push({
+ absoluteOutputDestination,
+ filename: artifact.filename,
+ sizeInBytes: artifact.content.length,
+ });
+ };
+
+ onProgress(progress);
+
+ return {
+ onArtifact,
+ initialProgress: progress,
+ };
};
diff --git a/packages/cli/src/progress-types.ts b/packages/cli/src/progress-types.ts
index 58fe3bb4a5..497f4d0766 100644
--- a/packages/cli/src/progress-types.ts
+++ b/packages/cli/src/progress-types.ts
@@ -12,4 +12,7 @@ export const initialAggregateRenderProgress = (): AggregateRenderProgress => ({
bytes: 0,
doneIn: null,
},
+ artifactState: {
+ received: [],
+ },
});
diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.ts
index bbb22fbe55..82c8260085 100644
--- a/packages/cli/src/render-flows/render.ts
+++ b/packages/cli/src/render-flows/render.ts
@@ -42,7 +42,7 @@ import {makeHyperlink} from '../hyperlinks/make-link';
import {getVideoImageFormat} from '../image-formats';
import {Log} from '../log';
import {makeOnDownload} from '../make-on-download';
-import {onArtifactOnCli} from '../on-artifact';
+import {handleOnArtifact} from '../on-artifact';
import {parsedCli, quietFlagProvided} from '../parsed-cli';
import {
LABEL_WIDTH,
@@ -220,6 +220,13 @@ export const renderVideoFlow = async ({
doneIn: null,
};
+ let {onArtifact, initialProgress: artifactState} = handleOnArtifact(
+ (progress) => {
+ artifactState = progress;
+ updateRenderProgress({newline: false, printToConsole: true});
+ },
+ );
+
const updateRenderProgress = ({
newline,
printToConsole,
@@ -233,6 +240,7 @@ export const renderVideoFlow = async ({
downloads,
bundling: bundlingProgress,
copyingState,
+ artifactState,
};
const {output, message, progress} = makeRenderingAndStitchingProgress({
@@ -430,6 +438,7 @@ export const renderVideoFlow = async ({
codec: shouldOutputImageSequence ? undefined : codec,
uiImageFormat,
});
+
if (shouldOutputImageSequence) {
fs.mkdirSync(absoluteOutputFile, {
recursive: true,
@@ -492,7 +501,7 @@ export const renderVideoFlow = async ({
compositionStart: 0,
forSeamlessAacConcatenation,
onBrowserDownload,
- onArtifact: onArtifactOnCli,
+ onArtifact,
});
Log.info({indent, logLevel}, chalk.blue(`â–¶ ${absoluteOutputFile}`));
@@ -582,7 +591,7 @@ export const renderVideoFlow = async ({
forSeamlessAacConcatenation,
compositionStart: 0,
onBrowserDownload,
- onArtifact: onArtifactOnCli,
+ onArtifact,
});
if (!updatesDontOverwrite) {
updateRenderProgress({newline: true, printToConsole: true});
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index 11bf724e0d..7e66eac107 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -49,10 +49,12 @@ export {ProjectInfo} from './project-info';
export type {RenderDefaults} from './render-defaults';
export {
AggregateRenderProgress,
+ ArtifactProgress,
BundlingState,
CopyingState,
DownloadProgress,
JobProgressCallback,
+ ReceivedAsset,
RenderJob,
RenderJobWithCleanup,
RenderingProgressInput,
diff --git a/packages/studio-shared/src/render-job.ts b/packages/studio-shared/src/render-job.ts
index 6ff3b0c1f8..86eefd9e7e 100644
--- a/packages/studio-shared/src/render-job.ts
+++ b/packages/studio-shared/src/render-job.ts
@@ -56,6 +56,17 @@ export type AggregateRenderProgress = {
downloads: DownloadProgress[];
bundling: BundlingState;
copyingState: CopyingState;
+ artifactState: ArtifactProgress;
+};
+
+export type ReceivedAsset = {
+ filename: string;
+ absoluteOutputDestination: string;
+ sizeInBytes: number;
+};
+
+export type ArtifactProgress = {
+ received: ReceivedAsset[];
};
export type JobProgressCallback = (