Skip to content

🎥 Make videos programmatically with React

add new options

Jonny Burgere83c592ec6b3
diff --git a/packages/cloudrun/src/api/render-media-on-cloudrun.ts b/packages/cloudrun/src/api/render-media-on-cloudrun.ts
index 2662fd527e..5556a419bb 100644
--- a/packages/cloudrun/src/api/render-media-on-cloudrun.ts
+++ b/packages/cloudrun/src/api/render-media-on-cloudrun.ts
@@ -1,4 +1,10 @@
-import type {ChromiumOptions, FrameRange, LogLevel} from '@remotion/renderer';
+import {ConfigInternals} from '@remotion/cli/src/config';
+import {
+ ChromiumOptions,
+ FrameRange,
+ LogLevel,
+ RenderInternals,
+} from '@remotion/renderer';
import type {
CloudRunPayloadType,
ErrorResponsePayload,
@@ -58,6 +64,11 @@ export type RenderMediaOnCloudrunInput = {
forceWidth?: number | null;
forceHeight?: number | null;
logLevel?: LogLevel;
+ delayRenderTimeoutInMilliseconds?: number;
+ dumpBrowserLogs?: boolean;
+ concurrency?: number | string | null;
+ enforceAudioTrack?: boolean;
+ preferLossless?: boolean;
};
/**
@@ -125,6 +136,11 @@ export const renderMediaOnCloudrun = async ({
forceWidth,
forceHeight,
logLevel,
+ delayRenderTimeoutInMilliseconds,
+ dumpBrowserLogs,
+ concurrency,
+ enforceAudioTrack,
+ preferLossless,
}: RenderMediaOnCloudrunInput): Promise<RenderMediaOnCloudrunOutput> => {
const actualCodec = validateCloudrunCodec(codec);
validateServeUrl(serveUrl);
@@ -139,26 +155,31 @@ export const renderMediaOnCloudrun = async ({
region,
});
+ const verbose = RenderInternals.isEqualOrBelowLogLevel(
+ ConfigInternals.Logging.getLogLevel(),
+ 'verbose'
+ );
+
const data: CloudRunPayloadType = {
composition,
serveUrl,
codec: actualCodec,
- inputProps,
- jpegQuality,
- audioCodec,
- audioBitrate,
- videoBitrate,
- crf,
- pixelFormat,
- imageFormat,
- scale,
- proResProfile,
- everyNthFrame,
- numberOfGifLoops,
- frameRange,
- envVariables,
+ inputProps: inputProps ?? {},
+ jpegQuality: jpegQuality ?? RenderInternals.DEFAULT_JPEG_QUALITY,
+ audioCodec: audioCodec ?? null,
+ audioBitrate: audioBitrate ?? null,
+ videoBitrate: videoBitrate ?? null,
+ crf: crf ?? null,
+ pixelFormat: pixelFormat ?? RenderInternals.DEFAULT_PIXEL_FORMAT,
+ imageFormat: imageFormat ?? RenderInternals.DEFAULT_VIDEO_IMAGE_FORMAT,
+ scale: scale ?? 1,
+ proResProfile: proResProfile ?? null,
+ everyNthFrame: everyNthFrame ?? 1,
+ numberOfGifLoops: numberOfGifLoops ?? null,
+ frameRange: frameRange ?? null,
+ envVariables: envVariables ?? {},
chromiumOptions,
- muted,
+ muted: muted ?? false,
outputBucket,
privacy,
outName,
@@ -166,6 +187,12 @@ export const renderMediaOnCloudrun = async ({
forceHeight,
type: 'media',
logLevel: logLevel ?? 'info',
+ delayRenderTimeoutInMilliseconds:
+ delayRenderTimeoutInMilliseconds ?? RenderInternals.DEFAULT_TIMEOUT,
+ dumpBrowserLogs: dumpBrowserLogs ?? verbose,
+ concurrency: concurrency ?? null,
+ enforceAudioTrack: enforceAudioTrack ?? false,
+ preferLossless: preferLossless ?? false,
};
const client = await getAuthClientForUrl(cloudRunEndpoint);
diff --git a/packages/cloudrun/src/api/render-still-on-cloudrun.ts b/packages/cloudrun/src/api/render-still-on-cloudrun.ts
index a5d1524b50..ba544f2a1c 100644
--- a/packages/cloudrun/src/api/render-still-on-cloudrun.ts
+++ b/packages/cloudrun/src/api/render-still-on-cloudrun.ts
@@ -1,6 +1,7 @@
-import type {
+import {
ChromiumOptions,
LogLevel,
+ RenderInternals,
StillImageFormat,
} from '@remotion/renderer';
import type {
@@ -33,6 +34,8 @@ export type RenderStillOnCloudrunInput = {
forceWidth?: number | null;
forceHeight?: number | null;
logLevel?: LogLevel;
+ delayRenderTimeoutInMilliseconds?: number;
+ dumpBrowserLogs?: boolean;
};
/**
@@ -78,6 +81,8 @@ export const renderStillOnCloudrun = async ({
forceWidth,
forceHeight,
logLevel,
+ delayRenderTimeoutInMilliseconds,
+ dumpBrowserLogs,
}: RenderStillOnCloudrunInput): Promise<RenderStillOnCloudrunOutput> => {
validateServeUrl(serveUrl);
if (privacy) validatePrivacy(privacy);
@@ -94,20 +99,23 @@ export const renderStillOnCloudrun = async ({
const data: CloudRunPayloadType = {
composition,
serveUrl,
- inputProps,
+ inputProps: inputProps ?? {},
outputBucket,
outName,
- privacy,
+ privacy: privacy ?? 'public',
imageFormat,
- envVariables,
+ envVariables: envVariables ?? {},
jpegQuality,
chromiumOptions,
- scale,
+ scale: scale ?? 1,
forceWidth,
forceHeight,
frame: frame ?? 0,
type: 'still',
logLevel: logLevel ?? 'info',
+ delayRenderTimeoutInMilliseconds:
+ delayRenderTimeoutInMilliseconds ?? RenderInternals.DEFAULT_TIMEOUT,
+ dumpBrowserLogs: dumpBrowserLogs ?? false,
};
const client = await getAuthClientForUrl(cloudRunEndpoint);
diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.ts
index 7097d0a99f..adac8063d4 100644
--- a/packages/cloudrun/src/cli/commands/render/index.ts
+++ b/packages/cloudrun/src/cli/commands/render/index.ts
@@ -56,13 +56,16 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
width,
browserExecutable,
port,
+ enforceAudioTrack,
} = await CliInternals.getCliOptions({
type: 'series',
isLambda: true,
remotionRoot,
});
+ const verbose = RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose');
let composition: string = args[1];
+
if (!composition) {
Log.info('No compositions passed. Fetching compositions...');
@@ -73,7 +76,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
indent: false,
port,
remotionRoot,
- verbose: RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose'),
+ verbose,
webpackConfigOrServeUrl: serveUrl,
});
@@ -179,6 +182,13 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
forceBucketName,
updateRenderProgress,
logLevel: ConfigInternals.Logging.getLogLevel(),
+ // Special case: Should not use default local concurrency, or from
+ // config file, just when explicitly set
+ concurrency: CliInternals.parsedCli.concurrency ?? null,
+ delayRenderTimeoutInMilliseconds: puppeteerTimeout,
+ dumpBrowserLogs: verbose,
+ enforceAudioTrack,
+ preferLossless: false,
});
renderProgress.doneIn = Date.now() - renderStart;
updateProgress();
diff --git a/packages/cloudrun/src/cli/commands/still.ts b/packages/cloudrun/src/cli/commands/still.ts
index 51a71382f6..a78e1818ff 100644
--- a/packages/cloudrun/src/cli/commands/still.ts
+++ b/packages/cloudrun/src/cli/commands/still.ts
@@ -24,7 +24,6 @@ export const stillCommand = async (args: string[], remotionRoot: string) => {
chromiumOptions,
envVariables,
inputProps,
- logLevel,
puppeteerTimeout,
jpegQuality,
stillFrame,
@@ -33,12 +32,15 @@ export const stillCommand = async (args: string[], remotionRoot: string) => {
width,
browserExecutable,
port,
+ logLevel,
} = await CliInternals.getCliOptions({
type: 'still',
isLambda: true,
remotionRoot,
});
+ const verbose = RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose');
+
let composition = args[1];
if (!composition) {
Log.info('No compositions passed. Fetching compositions...');
@@ -49,7 +51,7 @@ export const stillCommand = async (args: string[], remotionRoot: string) => {
indent: false,
port,
remotionRoot,
- verbose: RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose'),
+ verbose,
webpackConfigOrServeUrl: serveUrl,
});
@@ -59,7 +61,7 @@ export const stillCommand = async (args: string[], remotionRoot: string) => {
compositionIdFromUi: null,
indent: false,
serveUrlOrWebpackUrl: serveUrl,
- verbose: RenderInternals.isEqualOrBelowLogLevel(logLevel, 'verbose'),
+ verbose,
browserExecutable,
chromiumOptions,
envVariables,
@@ -142,6 +144,8 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
forceBucketName,
outName,
logLevel: ConfigInternals.Logging.getLogLevel(),
+ delayRenderTimeoutInMilliseconds: puppeteerTimeout,
+ dumpBrowserLogs: verbose,
});
doneIn = Date.now() - renderStart;
updateProgress(true);
diff --git a/packages/cloudrun/src/functions/helpers/payloads.ts b/packages/cloudrun/src/functions/helpers/payloads.ts
index c260e1c924..501faddedc 100644
--- a/packages/cloudrun/src/functions/helpers/payloads.ts
+++ b/packages/cloudrun/src/functions/helpers/payloads.ts
@@ -7,7 +7,7 @@ const audioCodec = z.enum(RenderInternals.validAudioCodecs);
const pixelFormat = z.enum(RenderInternals.validPixelFormats);
const videoImageFormat = z.enum(RenderInternals.validVideoImageFormats);
const stillImageFormat = z.enum(RenderInternals.validStillImageFormats);
-const proResProfile = z.enum(BrowserSafeApis.proResProfileOptions);
+const proResProfile = z.enum(BrowserSafeApis.proResProfileOptions).nullable();
const chromiumOptions = z.object({
ignoreCertificateErrors: z.boolean().optional(),
disableWebSecurity: z.boolean().optional(),
@@ -25,26 +25,31 @@ export const CloudRunPayload = z.discriminatedUnion('type', [
forceHeight: z.number().optional().nullable(),
forceWidth: z.number().optional().nullable(),
codec,
- inputProps: z.record(z.string(), z.unknown()).or(z.undefined()),
- jpegQuality: z.number().optional(),
- audioCodec: audioCodec.optional().nullable(),
- audioBitrate: z.string().optional().nullable(),
- videoBitrate: z.string().optional().nullable(),
- crf: z.number().optional().nullable(),
- pixelFormat: pixelFormat.optional(),
- imageFormat: videoImageFormat.optional(),
- scale: z.number().optional(),
- proResProfile: proResProfile.optional(),
- everyNthFrame: z.number().optional(),
- numberOfGifLoops: z.number().optional().nullable(),
- frameRange: z.tuple([z.number(), z.number()]).or(z.number()).optional(),
- envVariables: z.record(z.string()).optional(),
+ inputProps: z.record(z.string(), z.unknown()),
+ jpegQuality: z.number(),
+ audioCodec: audioCodec.nullable(),
+ audioBitrate: z.string().nullable(),
+ videoBitrate: z.string().nullable(),
+ crf: z.number().nullable(),
+ pixelFormat,
+ imageFormat: videoImageFormat,
+ scale: z.number(),
+ proResProfile,
+ everyNthFrame: z.number(),
+ numberOfGifLoops: z.number().nullable(),
+ frameRange: z.tuple([z.number(), z.number()]).or(z.number()).nullable(),
+ envVariables: z.record(z.string()),
chromiumOptions: chromiumOptions.optional(),
- muted: z.boolean().optional(),
+ muted: z.boolean(),
outputBucket: z.string(),
outName: z.string().optional(),
privacy: z.enum(['public', 'private']).optional(),
logLevel,
+ delayRenderTimeoutInMilliseconds: z.number(),
+ dumpBrowserLogs: z.boolean(),
+ concurrency: z.number().or(z.string()).nullable(),
+ enforceAudioTrack: z.boolean(),
+ preferLossless: z.boolean(),
}),
z.object({
type: z.literal('still'),
@@ -52,17 +57,19 @@ export const CloudRunPayload = z.discriminatedUnion('type', [
composition: z.string(),
forceHeight: z.number().optional().nullable(),
forceWidth: z.number().optional().nullable(),
- inputProps: z.record(z.string(), z.unknown()).or(z.undefined()),
+ inputProps: z.record(z.string(), z.unknown()),
jpegQuality: z.number().optional(),
- imageFormat: stillImageFormat.optional(),
- scale: z.number().optional(),
- privacy: z.enum(['public', 'private']).optional(),
- envVariables: z.record(z.string()).optional(),
+ imageFormat: stillImageFormat,
+ scale: z.number(),
+ privacy: z.enum(['public', 'private']),
+ envVariables: z.record(z.string()),
chromiumOptions: chromiumOptions.optional(),
outputBucket: z.string(),
outName: z.string().optional(),
frame: z.number(),
+ delayRenderTimeoutInMilliseconds: z.number(),
logLevel,
+ dumpBrowserLogs: z.boolean(),
}),
]);
diff --git a/packages/cloudrun/src/functions/render-media-single-thread.ts b/packages/cloudrun/src/functions/render-media-single-thread.ts
index 6fb162ae71..3e737609b9 100644
--- a/packages/cloudrun/src/functions/render-media-single-thread.ts
+++ b/packages/cloudrun/src/functions/render-media-single-thread.ts
@@ -1,7 +1,7 @@
import type * as ff from '@google-cloud/functions-framework';
import {Storage} from '@google-cloud/storage';
import type {ChromiumOptions, RenderMediaOnProgress} from '@remotion/renderer';
-import {RenderInternals, renderMedia} from '@remotion/renderer';
+import {RenderInternals} from '@remotion/renderer';
import {randomHash} from '../shared/random-hash';
import {getCompositionFromBody} from './helpers/get-composition-from-body';
import type {
@@ -40,7 +40,7 @@ export const renderMediaSingleThread = async (
gl: body.chromiumOptions?.gl ?? 'swangle',
};
- await renderMedia({
+ await RenderInternals.internalRenderMedia({
composition: {
...composition,
height: body.forceHeight ?? composition.height,
@@ -58,7 +58,7 @@ export const renderMediaSingleThread = async (
pixelFormat: body.pixelFormat,
imageFormat: body.imageFormat,
scale: body.scale,
- proResProfile: body.proResProfile,
+ proResProfile: body.proResProfile ?? undefined,
everyNthFrame: body.everyNthFrame,
numberOfGifLoops: body.numberOfGifLoops,
onProgress,
@@ -67,6 +67,24 @@ export const renderMediaSingleThread = async (
chromiumOptions: actualChromiumOptions,
muted: body.muted,
verbose: RenderInternals.isEqualOrBelowLogLevel(body.logLevel, 'verbose'),
+ browserExecutable: null,
+ timeoutInMilliseconds: body.delayRenderTimeoutInMilliseconds,
+ cancelSignal: undefined,
+ concurrency: body.concurrency,
+ disallowParallelEncoding: false,
+ dumpBrowserLogs: body.dumpBrowserLogs,
+ enforceAudioTrack: body.enforceAudioTrack,
+ ffmpegOverride: undefined,
+ indent: false,
+ onBrowserLog: null,
+ onCtrlCExit: () => undefined,
+ onDownload: () => undefined,
+ onStart: () => undefined,
+ overwrite: true,
+ port: null,
+ preferLossless: body.preferLossless,
+ puppeteerInstance: undefined,
+ server: undefined,
});
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 bae8d46cfc..736723ed85 100644
--- a/packages/cloudrun/src/functions/render-still-single-thread.ts
+++ b/packages/cloudrun/src/functions/render-still-single-thread.ts
@@ -1,10 +1,6 @@
import type * as ff from '@google-cloud/functions-framework';
import {Storage} from '@google-cloud/storage';
-import {
- ChromiumOptions,
- RenderInternals,
- renderStill,
-} from '@remotion/renderer';
+import {ChromiumOptions, RenderInternals} from '@remotion/renderer';
import {Log} from '../cli/log';
import {randomHash} from '../shared/random-hash';
import {getCompositionFromBody} from './helpers/get-composition-from-body';
@@ -39,7 +35,7 @@ export const renderStillSingleThread = async (
gl: body.chromiumOptions?.gl ?? 'swangle',
};
- await renderStill({
+ await RenderInternals.internalRenderStill({
composition: {
...composition,
height: body.forceHeight ?? composition.height,
@@ -48,13 +44,24 @@ export const renderStillSingleThread = async (
serveUrl: body.serveUrl,
output: tempFilePath,
inputProps: body.inputProps,
- jpegQuality: body.jpegQuality,
+ jpegQuality: body.jpegQuality ?? RenderInternals.DEFAULT_JPEG_QUALITY,
imageFormat: body.imageFormat,
scale: body.scale,
envVariables: body.envVariables,
chromiumOptions: actualChromiumOptions,
frame: body.frame,
verbose: RenderInternals.isEqualOrBelowLogLevel(body.logLevel, 'verbose'),
+ browserExecutable: null,
+ cancelSignal: null,
+ dumpBrowserLogs: body.dumpBrowserLogs,
+ indent: false,
+ timeoutInMilliseconds: body.delayRenderTimeoutInMilliseconds,
+ onBrowserLog: null,
+ onDownload: null,
+ overwrite: true,
+ port: null,
+ puppeteerInstance: null,
+ server: undefined,
});
Log.info('Still rendered');
diff --git a/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar b/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar
index 6c567fcf80..b62adf7a23 100644
Binary files a/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar and b/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar differ