π₯ Make videos programmatically with React
emit to out/[composition-id]/artifact
Jonny Burger5d734ca2b405
diff --git a/packages/cli/src/on-artifact.ts b/packages/cli/src/on-artifact.tsindex 595d3d946f..0ed587898e 100644--- a/packages/cli/src/on-artifact.ts+++ b/packages/cli/src/on-artifact.ts@@ -1,26 +1,45 @@import type {OnArtifact} from '@remotion/renderer';import type {ArtifactProgress} from '@remotion/studio-shared';-import {writeFileSync} from 'fs';+import {existsSync, mkdirSync, writeFileSync} from 'fs';import path from 'path';-export const handleOnArtifact = (- artifactState: ArtifactProgress,- onProgress: (artifact: ArtifactProgress) => void,-) => {+export const handleOnArtifact = ({+ artifactState,+ onProgress,+ compositionId,+}: {+ artifactState: ArtifactProgress;+ onProgress: (artifact: ArtifactProgress) => void;+ compositionId: string;+}) => {const initialProgress = {...artifactState};const onArtifact: OnArtifact = (artifact) => {- const absoluteOutputDestination = path.join(- process.cwd(),+ // It would be nice in the future to customize the artifact output destination++ const relativeOutputDestination = path.join(+ 'out',+ compositionId,artifact.filename.replace('/', path.sep),);+ const defaultOutName = path.join(process.cwd(), relativeOutputDestination);++ if (!existsSync(path.dirname(defaultOutName))) {+ mkdirSync(path.dirname(defaultOutName), {+ recursive: true,+ });+ }++ const alreadyExisted = existsSync(defaultOutName);- writeFileSync(artifact.filename, artifact.content);+ writeFileSync(defaultOutName, artifact.content);initialProgress.received.push({- absoluteOutputDestination,+ absoluteOutputDestination: defaultOutName,filename: artifact.filename,sizeInBytes: artifact.content.length,+ alreadyExisted,+ relativeOutputDestination,});};diff --git a/packages/cli/src/progress-bar.ts b/packages/cli/src/progress-bar.tsindex 20cc2ca1b1..8a15af1fcc 100644--- a/packages/cli/src/progress-bar.ts+++ b/packages/cli/src/progress-bar.ts@@ -202,12 +202,12 @@ const makeArtifactProgress = (artifactState: ArtifactProgress) => {return received.map((artifact) => {return [- chalk.blue('+'.padEnd(LABEL_WIDTH)),+ chalk.blue((artifact.alreadyExisted ? 'β' : '+').padEnd(LABEL_WIDTH)),chalk.blue(makeHyperlink({url: 'file://' + artifact.absoluteOutputDestination,- fallback: artifact.filename,- text: artifact.filename,+ fallback: artifact.absoluteOutputDestination,+ text: artifact.relativeOutputDestination,}),),chalk.gray(`${formatBytes(artifact.sizeInBytes)}`),diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.tsindex 89983aeb57..b657c9e260 100644--- a/packages/cli/src/render-flows/render.ts+++ b/packages/cli/src/render-flows/render.ts@@ -250,11 +250,6 @@ export const renderVideoFlow = async ({}};- const {onArtifact} = handleOnArtifact(artifactState, (progress) => {- artifactState = progress;- updateRenderProgress({newline: false, printToConsole: true});- });-const {urlOrBundle, cleanup: cleanupBundle} = await bundleOnCliOrTakeServeUrl({fullPath: fullEntryPoint,@@ -332,6 +327,15 @@ export const renderVideoFlow = async ({onBrowserDownload,});+ const {onArtifact} = handleOnArtifact({+ artifactState,+ onProgress: (progress) => {+ artifactState = progress;+ updateRenderProgress({newline: false, printToConsole: true});+ },+ compositionId,+ });+const {value: codec, source: codecReason} =BrowserSafeApis.options.videoCodecOption.getValue({diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.tsindex 8ffa426fa5..f538dc667f 100644--- a/packages/cli/src/render-flows/still.ts+++ b/packages/cli/src/render-flows/still.ts@@ -318,13 +318,17 @@ export const renderStillFlow = async ({isUsingParallelEncoding: false,});- const {onArtifact} = handleOnArtifact(aggregate.artifactState, (progress) => {- aggregate.artifactState = progress;+ const {onArtifact} = handleOnArtifact({+ artifactState: aggregate.artifactState,+ compositionId,+ onProgress: (progress) => {+ aggregate.artifactState = progress;- updateRenderProgress({- newline: false,- printToConsole: true,- });+ updateRenderProgress({+ newline: false,+ printToConsole: true,+ });+ },});await RenderInternals.internalRenderStill({diff --git a/packages/studio-shared/src/render-job.ts b/packages/studio-shared/src/render-job.tsindex a849a9547c..d22740d133 100644--- a/packages/studio-shared/src/render-job.ts+++ b/packages/studio-shared/src/render-job.ts@@ -62,7 +62,9 @@ export type AggregateRenderProgress = {export type ReceivedArtifact = {filename: string;absoluteOutputDestination: string;+ relativeOutputDestination: string;sizeInBytes: number;+ alreadyExisted: boolean;};export type ArtifactProgress = {