Skip to content

🎥 Make videos programmatically with React

support input props and env variables for getCompositions in cloudrun

Jonny Burgera65c5ed4a6f0
diff --git a/packages/cloudrun/src/functions/helpers/get-composition-from-body.ts b/packages/cloudrun/src/functions/helpers/get-composition-from-body.ts
index dc27700bcd..cfd4ab6e7c 100644
--- a/packages/cloudrun/src/functions/helpers/get-composition-from-body.ts
+++ b/packages/cloudrun/src/functions/helpers/get-composition-from-body.ts
@@ -1,15 +1,30 @@
-import {getCompositions} from '@remotion/renderer';
+import {RenderInternals} from '@remotion/renderer';
+import type {CloudRunPayloadType} from './payloads';
-export const getCompositionFromBody = async (
- serveUrl: string,
- compositionName: string
-) => {
- const comps = await getCompositions(serveUrl);
- const composition = comps.find((comp) => comp.id === compositionName);
+export const getCompositionFromBody = async (body: CloudRunPayloadType) => {
+ const {metadata, propsSize} = await RenderInternals.internalSelectComposition(
+ {
+ serveUrl: body.serveUrl,
+ browserExecutable: null,
+ chromiumOptions: body.chromiumOptions ?? {},
+ envVariables: body.envVariables ?? {},
+ id: body.composition,
+ indent: false,
+ inputProps: body.inputProps ?? {},
+ logLevel: body.logLevel,
+ onBrowserLog: () => null,
+ port: null,
+ puppeteerInstance: undefined,
+ server: undefined,
+ timeoutInMilliseconds: body.delayRenderTimeoutInMilliseconds,
+ }
+ );
- if (composition) {
- return composition;
+ if (propsSize > 10_000_000) {
+ RenderInternals.Log.warn(
+ `The props of your composition are large (${propsSize} bytes). This may cause slowdown.`
+ );
}
- throw new Error(`Composition not found: ${compositionName}`);
+ return metadata;
};
diff --git a/packages/cloudrun/src/functions/render-media-single-thread.ts b/packages/cloudrun/src/functions/render-media-single-thread.ts
index 0dafbfdfea..2467d4df51 100644
--- a/packages/cloudrun/src/functions/render-media-single-thread.ts
+++ b/packages/cloudrun/src/functions/render-media-single-thread.ts
@@ -17,10 +17,7 @@ export const renderMediaSingleThread = async (
throw new Error('expected type media');
}
- const composition = await getCompositionFromBody(
- body.serveUrl,
- body.composition
- );
+ const composition = await getCompositionFromBody(body);
const tempFilePath = '/tmp/output.mp4';
const renderId = randomHash({randomInTests: true});
diff --git a/packages/cloudrun/src/functions/render-still-single-thread.ts b/packages/cloudrun/src/functions/render-still-single-thread.ts
index 2408c35ed1..1019b29c24 100644
--- a/packages/cloudrun/src/functions/render-still-single-thread.ts
+++ b/packages/cloudrun/src/functions/render-still-single-thread.ts
@@ -20,10 +20,7 @@ export const renderStillSingleThread = async (
Log.verbose('Rendering still frame', body);
- const composition = await getCompositionFromBody(
- body.serveUrl,
- body.composition
- );
+ const composition = await getCompositionFromBody(body);
Log.verbose('Composition loaded', composition);