Skip to content

🎥 Make videos programmatically with React

wip - passing through all CLI vars to cloudrun rendering

Matt McGillivray07c98c8ff432
diff --git a/packages/cloudrun/src/api/render-media-on-cloudrun.ts b/packages/cloudrun/src/api/render-media-on-cloudrun.ts
index cb0b2ffd20..6b09d01bec 100644
--- a/packages/cloudrun/src/api/render-media-on-cloudrun.ts
+++ b/packages/cloudrun/src/api/render-media-on-cloudrun.ts
@@ -1,3 +1,4 @@
+import type {ChromiumOptions, FrameRange} from '@remotion/renderer';
import got from 'got/dist/source';
import {validateCloudRunUrl} from '../shared/validate-cloudrun-url';
import type {CloudrunCodec} from '../shared/validate-gcp-codec';
@@ -24,8 +25,8 @@ export type RenderMediaOnCloudrunInput = {
updateRenderProgress?: (progress: number) => void;
jpegQuality?: number;
audioCodec?: 'mp3' | 'aac' | 'pcm-16' | 'opus';
- audioBitrate?: string;
- videoBitrate?: string;
+ audioBitrate?: string | null;
+ videoBitrate?: string | null;
proResProfile?:
| '4444-xq'
| '4444'
@@ -34,7 +35,7 @@ export type RenderMediaOnCloudrunInput = {
| 'light'
| 'proxy'
| undefined;
- crf?: number;
+ crf?: number | undefined;
pixelFormat?:
| 'yuv420p'
| 'yuva420p'
@@ -47,7 +48,13 @@ export type RenderMediaOnCloudrunInput = {
imageFormat?: 'png' | 'jpeg' | 'none';
scale?: number;
everyNthFrame?: number;
- numberOfGifLoops?: number;
+ numberOfGifLoops?: number | null;
+ frameRange?: FrameRange;
+ envVariables?: Record<string, string>;
+ chromiumOptions?: ChromiumOptions;
+ muted?: boolean;
+ forceWidth?: number | null;
+ forceHeight?: number | null;
};
export type RenderMediaOnCloudrunOutput = {
@@ -103,6 +110,12 @@ export const renderMediaOnCloudrun = async ({
scale,
everyNthFrame,
numberOfGifLoops,
+ frameRange,
+ envVariables,
+ chromiumOptions,
+ muted,
+ forceWidth,
+ forceHeight,
}: RenderMediaOnCloudrunInput): Promise<RenderMediaOnCloudrunOutput> => {
const actualCodec = validateCloudrunCodec(codec);
validateServeUrl(serveUrl);
@@ -146,6 +159,12 @@ export const renderMediaOnCloudrun = async ({
scale,
everyNthFrame,
numberOfGifLoops,
+ frameRange,
+ envVariables,
+ chromiumOptions,
+ muted,
+ forceWidth,
+ forceHeight,
};
if (authenticatedRequest) {
diff --git a/packages/cloudrun/src/api/render-still-on-cloudrun.ts b/packages/cloudrun/src/api/render-still-on-cloudrun.ts
index 91bbdb873f..1e10ddd6d0 100644
--- a/packages/cloudrun/src/api/render-still-on-cloudrun.ts
+++ b/packages/cloudrun/src/api/render-still-on-cloudrun.ts
@@ -1,3 +1,4 @@
+import type {ChromiumOptions, StillImageFormat} from '@remotion/renderer';
import got from 'got';
import {validateCloudRunUrl} from '../shared/validate-cloudrun-url';
import {validatePrivacy} from '../shared/validate-privacy';
@@ -18,6 +19,14 @@ export type RenderStillOnCloudrunInput = {
outputBucket: string;
privacy?: string;
outputFile?: string;
+ imageFormat: StillImageFormat;
+ envVariables?: Record<string, string>;
+ frame?: number;
+ jpegQuality?: number;
+ chromiumOptions?: ChromiumOptions;
+ scale?: number;
+ forceWidth?: number | null;
+ forceHeight?: number | null;
};
export type RenderStillOnCloudrunOutput = {
@@ -58,6 +67,14 @@ export const renderStillOnCloudrun = async ({
outputBucket,
privacy,
outputFile,
+ imageFormat,
+ envVariables,
+ frame,
+ jpegQuality,
+ chromiumOptions,
+ scale,
+ forceWidth,
+ forceHeight,
}: RenderStillOnCloudrunInput): Promise<RenderStillOnCloudrunOutput> => {
validateServeUrl(serveUrl);
if (privacy) validatePrivacy(privacy);
@@ -88,6 +105,14 @@ export const renderStillOnCloudrun = async ({
outputBucket,
outputFile,
privacy,
+ imageFormat,
+ envVariables,
+ frame,
+ jpegQuality,
+ chromiumOptions,
+ scale,
+ forceWidth,
+ forceHeight,
};
if (authenticatedRequest) {
diff --git a/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts b/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts
index 87d27d55b9..fa39453ac3 100644
--- a/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts
+++ b/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts
@@ -67,9 +67,30 @@ export const renderArgsCheck = async (
uiCodec: null,
});
- const {inputProps} = await CliInternals.getCliOptions({
+ const {
+ chromiumOptions,
+ crf,
+ envVariables,
+ frameRange,
+ inputProps,
+ logLevel,
+ pixelFormat,
+ proResProfile,
+ puppeteerTimeout,
+ jpegQuality,
+ scale,
+ everyNthFrame,
+ numberOfGifLoops,
+ muted,
+ overwrite,
+ audioBitrate,
+ videoBitrate,
+ height,
+ width,
+ stillFrame,
+ } = await CliInternals.getCliOptions({
type: 'series',
- isLambda: true, // TODO: what do I need to do with this?
+ isLambda: true,
remotionRoot,
});
@@ -119,28 +140,10 @@ export const renderArgsCheck = async (
const authenticatedRequest = !parsedCloudrunCli['unauthenticated-request'];
- const jpegQuality = parsedCloudrunCli['jpeg-quality'];
-
const audioCodec = parsedCloudrunCli['audio-codec'];
- const audioBitrate = parsedCloudrunCli['audio-bitrate'];
-
- const videoBitrate = parsedCloudrunCli['video-bitrate'];
-
- const proResProfile = parsedCloudrunCli['prores-profile'];
-
- const {crf} = parsedCloudrunCli;
-
- const pixelFormat = parsedCloudrunCli['pixel-format'];
-
const imageFormat = parsedCloudrunCli['image-format'];
- const {scale} = parsedCloudrunCli;
-
- const everyNthFrame = parsedCloudrunCli['every-nth-frame'];
-
- const numberOfGifLoops = parsedCloudrunCli['number-of-gif-loops'];
-
return {
serveUrl,
cloudRunUrl,
@@ -164,5 +167,15 @@ export const renderArgsCheck = async (
scale,
everyNthFrame,
numberOfGifLoops,
+ frameRange,
+ envVariables,
+ chromiumOptions,
+ logLevel,
+ puppeteerTimeout,
+ muted,
+ overwrite,
+ height,
+ width,
+ stillFrame,
};
};
diff --git a/packages/cloudrun/src/cli/commands/render/renderMedia.ts b/packages/cloudrun/src/cli/commands/render/renderMedia.ts
index 57563dc9ec..700276d7f3 100644
--- a/packages/cloudrun/src/cli/commands/render/renderMedia.ts
+++ b/packages/cloudrun/src/cli/commands/render/renderMedia.ts
@@ -36,6 +36,12 @@ export const renderMediaSubcommand = async (
scale,
everyNthFrame,
numberOfGifLoops,
+ frameRange,
+ envVariables,
+ chromiumOptions,
+ muted,
+ height,
+ width,
} = await renderArgsCheck(RENDER_MEDIA_SUBCOMMAND, args, remotionRoot);
// Todo: Check cloudRunUrl is valid, as the error message is obtuse
@@ -90,27 +96,33 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
};
const res = await renderMediaOnCloudrun({
- authenticatedRequest,
cloudRunUrl,
serveUrl,
- composition,
inputProps,
codec: codec as CloudrunCodec,
- outputBucket,
+ imageFormat,
+ crf: crf ?? undefined,
+ envVariables,
+ pixelFormat,
+ proResProfile,
+ jpegQuality,
+ composition,
privacy,
+ frameRange: frameRange ?? undefined,
outputFile: outName,
- updateRenderProgress,
- jpegQuality,
- audioCodec,
- audioBitrate,
- videoBitrate,
- proResProfile,
- crf,
- pixelFormat,
- imageFormat,
+ chromiumOptions,
scale,
- everyNthFrame,
numberOfGifLoops,
+ everyNthFrame,
+ muted,
+ audioBitrate,
+ videoBitrate,
+ forceHeight: height,
+ forceWidth: width,
+ audioCodec,
+ authenticatedRequest,
+ outputBucket,
+ updateRenderProgress,
});
renderProgress.doneIn = Date.now() - renderStart;
updateProgress();
diff --git a/packages/cloudrun/src/cli/commands/render/renderStill.ts b/packages/cloudrun/src/cli/commands/render/renderStill.ts
index 55edb9e113..f514837947 100644
--- a/packages/cloudrun/src/cli/commands/render/renderStill.ts
+++ b/packages/cloudrun/src/cli/commands/render/renderStill.ts
@@ -1,4 +1,5 @@
import {CliInternals} from '@remotion/cli';
+import {ConfigInternals} from '@remotion/cli/config';
import {downloadFile} from '../../../api/download-file';
import type {RenderStillOnCloudrunOutput} from '../../../api/render-still-on-cloudrun';
import {renderStillOnCloudrun} from '../../../api/render-still-on-cloudrun';
@@ -21,8 +22,25 @@ export const renderStillSubcommand = async (
privacy,
authenticatedRequest,
downloadName,
+ envVariables,
+ stillFrame,
+ jpegQuality,
+ chromiumOptions,
+ scale,
+ height,
+ width,
} = await renderArgsCheck(RENDER_STILL_SUBCOMMAND, args, remotionRoot);
+ const {format: imageFormat, source: imageFormatReason} =
+ CliInternals.determineFinalStillImageFormat({
+ downloadName,
+ outName: outName ?? null,
+ cliFlag: CliInternals.parsedCli['image-format'] ?? null,
+ isLambda: true,
+ fromUi: null,
+ configImageFormat:
+ ConfigInternals.getUserPreferredStillImageFormat() ?? null,
+ });
// Todo: Check cloudRunUrl is valid, as the error message is obtuse
CliInternals.Log.info(
CliInternals.chalk.gray(
@@ -62,13 +80,21 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
};
const res = await renderStillOnCloudrun({
- authenticatedRequest,
cloudRunUrl,
serveUrl,
- composition,
inputProps,
- outputBucket,
+ imageFormat,
+ composition,
privacy,
+ envVariables,
+ frame: stillFrame,
+ jpegQuality,
+ chromiumOptions,
+ scale,
+ forceHeight: height,
+ forceWidth: width,
+ authenticatedRequest,
+ outputBucket,
outputFile: outName,
});
doneIn = Date.now() - renderStart;
@@ -89,6 +115,7 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
Bucket Name = ${success.bucketName}
Privacy = ${success.privacy}
Render ID = ${success.renderId}
+ Image Format = ${imageFormat} (${imageFormatReason})
`.trim()
)
);
diff --git a/packages/cloudrun/src/functions/render-media-single-thread.ts b/packages/cloudrun/src/functions/render-media-single-thread.ts
index 6b7398e603..4a9e1791a9 100644
--- a/packages/cloudrun/src/functions/render-media-single-thread.ts
+++ b/packages/cloudrun/src/functions/render-media-single-thread.ts
@@ -44,6 +44,8 @@ export const renderMediaSingleThread = async (
everyNthFrame: req.body.everyNthFrame,
numberOfGifLoops: req.body.numberOfGifLoops,
onProgress,
+ frameRange: req.body.frameRange,
+ envVariables: req.body.envVariables,
});
const storage = new Storage();
diff --git a/packages/cloudrun/src/functions/render-still-single-thread.ts b/packages/cloudrun/src/functions/render-still-single-thread.ts
index 4198f82189..2827c378eb 100644
--- a/packages/cloudrun/src/functions/render-still-single-thread.ts
+++ b/packages/cloudrun/src/functions/render-still-single-thread.ts
@@ -24,6 +24,7 @@ export const renderStillSingleThread = async (
jpegQuality: req.body.jpegQuality,
imageFormat: req.body.imageFormat,
scale: req.body.scale,
+ envVariables: req.body.envVariables,
});
const storage = new Storage();
diff --git a/packages/docs/docs/cloudrun/cli/render.md b/packages/docs/docs/cloudrun/cli/render.md
index af5e46041f..6f9db2403e 100644
--- a/packages/docs/docs/cloudrun/cli/render.md
+++ b/packages/docs/docs/cloudrun/cli/render.md
@@ -78,10 +78,6 @@ One of:
Specify a location for a dotenv file. Default `.env`.
-### `--frames`
-
-[Render a subset of a video](/docs/config#setframerange). Example: `--frames=0-9` to select the first 10 frames. To render a still, use the [`still`](/docs/cloudrun/cli/still) command.
-
### `--out-name`
The file name of the media output as stored in the Cloud Storage bucket. By default, it is `out` plus the appropriate file extension, for example: `out.mp4`. Must match `/([0-9a-zA-Z-!_.*'()/]+)/g`.
@@ -137,3 +133,7 @@ For example only every second frame, every third frame and so on. Only works for
### `--number-of-gif-loops`
[Set the looping behavior.](/docs/config#setnumberofgifloops) This option may only be set when rendering GIFs. [See here for more details.](/docs/render-as-gif#changing-the-number-of-loops)
+
+### `--frames`
+
+[Render a subset of a video](/docs/config#setframerange). Example: `--frames=0-9` to select the first 10 frames. To render a still, use the [`still`](/docs/lambda/cli/still) command.