Skip to content

🎥 Make videos programmatically with React

`@remotion/lambda`: make internal renderMediaOnLambda() API and fix surfaced bugs

Jonny Burgerac0473e62404
diff --git a/packages/it-tests/src/monorepo/go-package.test.ts b/packages/it-tests/src/monorepo/go-package.test.ts
index 729a166069..d7b54fd5c1 100644
--- a/packages/it-tests/src/monorepo/go-package.test.ts
+++ b/packages/it-tests/src/monorepo/go-package.test.ts
@@ -34,6 +34,40 @@ test("Go package should create the same payload as normal Lambda package", async
functionName: "remotion-render",
serveUrl: "testbed",
codec: "h264",
+ audioBitrate: null,
+ audioCodec: null,
+ chromiumOptions: {},
+ colorSpace: "default",
+ concurrencyPerLambda: 1,
+ crf: undefined,
+ deleteAfter: null,
+ downloadBehavior: { type: "play-in-browser" },
+ envVariables: {},
+ everyNthFrame: 1,
+ forceBucketName: null,
+ forceHeight: null,
+ forceWidth: null,
+ frameRange: null,
+ framesPerLambda: null,
+ imageFormat: "jpeg",
+ jpegQuality: 80,
+ logLevel: "info",
+ maxRetries: 1,
+ muted: false,
+ numberOfGifLoops: 0,
+ offthreadVideoCacheSizeInBytes: null,
+ outName: null,
+ overwrite: false,
+ pixelFormat: undefined,
+ privacy: "public",
+ proResProfile: undefined,
+ rendererFunctionName: null,
+ scale: 1,
+ timeoutInMilliseconds: 30000,
+ videoBitrate: null,
+ webhook: null,
+ x264Preset: null,
+ inputProps: {},
});
expect(removeUndefined(parsed)).toEqual(removeUndefined(nativeVersion));
diff --git a/packages/it-tests/src/monorepo/php-package.test.ts b/packages/it-tests/src/monorepo/php-package.test.ts
index c7d8408a79..74d1a47877 100644
--- a/packages/it-tests/src/monorepo/php-package.test.ts
+++ b/packages/it-tests/src/monorepo/php-package.test.ts
@@ -65,6 +65,39 @@ test("PHP package should create the same renderMedia payload as normal Lambda pa
inputProps: {
hi: "there",
},
+ audioBitrate: null,
+ audioCodec: null,
+ chromiumOptions: {},
+ colorSpace: "default",
+ concurrencyPerLambda: 1,
+ crf: undefined,
+ deleteAfter: null,
+ downloadBehavior: { type: "play-in-browser" },
+ envVariables: {},
+ everyNthFrame: 1,
+ forceBucketName: null,
+ forceHeight: null,
+ forceWidth: null,
+ frameRange: null,
+ framesPerLambda: null,
+ imageFormat: "jpeg",
+ jpegQuality: 80,
+ logLevel: "info",
+ maxRetries: 1,
+ muted: false,
+ numberOfGifLoops: 0,
+ offthreadVideoCacheSizeInBytes: null,
+ outName: null,
+ overwrite: false,
+ pixelFormat: undefined,
+ privacy: "public",
+ proResProfile: undefined,
+ rendererFunctionName: null,
+ scale: 1,
+ timeoutInMilliseconds: 30000,
+ videoBitrate: null,
+ webhook: null,
+ x264Preset: null,
});
const jsonOutput = toParse.substring(0, toParse.lastIndexOf("}") + 1);
const parsedJson = JSON.parse(jsonOutput);
diff --git a/packages/it-tests/src/monorepo/python-package.test.ts b/packages/it-tests/src/monorepo/python-package.test.ts
index e35d8fabdf..ed878ae9a2 100644
--- a/packages/it-tests/src/monorepo/python-package.test.ts
+++ b/packages/it-tests/src/monorepo/python-package.test.ts
@@ -48,6 +48,39 @@ test("Python package should create the same renderMedia payload as normal Lambda
inputProps: {
hi: "there",
},
+ audioBitrate: null,
+ audioCodec: null,
+ chromiumOptions: {},
+ colorSpace: "default",
+ concurrencyPerLambda: 1,
+ crf: undefined,
+ deleteAfter: null,
+ downloadBehavior: { type: "play-in-browser" },
+ envVariables: {},
+ everyNthFrame: 1,
+ forceBucketName: null,
+ forceHeight: null,
+ forceWidth: null,
+ frameRange: null,
+ framesPerLambda: null,
+ imageFormat: "jpeg",
+ jpegQuality: 80,
+ logLevel: "info",
+ maxRetries: 1,
+ muted: false,
+ numberOfGifLoops: 0,
+ offthreadVideoCacheSizeInBytes: null,
+ outName: null,
+ overwrite: false,
+ pixelFormat: undefined,
+ privacy: "public",
+ proResProfile: undefined,
+ rendererFunctionName: null,
+ scale: 1,
+ timeoutInMilliseconds: 30000,
+ videoBitrate: null,
+ webhook: null,
+ x264Preset: null,
});
const jsonOutput = toParse.substring(0, toParse.lastIndexOf("}") + 1);
const parsedJson = JSON.parse(jsonOutput);
diff --git a/packages/lambda-go/internalops.go b/packages/lambda-go/internalops.go
index b113b6fe19..6dedcfc665 100644
--- a/packages/lambda-go/internalops.go
+++ b/packages/lambda-go/internalops.go
@@ -20,6 +20,11 @@ func constructRenderInternals(options *RemotionOptions) (*renderInternalOptions,
return nil, validationErrors
}
+ jpegQuality := 80
+ if options.JpegQuality != 0 {
+ jpegQuality = options.JpegQuality
+ }
+
internalParams := renderInternalOptions{
ServeUrl: options.ServeUrl,
InputProps: inputProps,
@@ -40,6 +45,7 @@ func constructRenderInternals(options *RemotionOptions) (*renderInternalOptions,
RendererFunctionName: &options.RendererFunctionName,
DeleteAfter: options.DeleteAfter,
Type: "start",
+ JpegQuality: jpegQuality,
}
internalParams.Muted = options.Muted
@@ -130,7 +136,11 @@ func constructRenderInternals(options *RemotionOptions) (*renderInternalOptions,
} else {
internalParams.ChromiumOptions = options.ChromiumOptions
}
- internalParams.EnvVariables = options.EnvVariables
+ if options.EnvVariables == nil {
+ internalParams.EnvVariables = map[string]interface{}{}
+ } else {
+ internalParams.EnvVariables = options.EnvVariables
+ }
return &internalParams, nil
}
diff --git a/packages/lambda-go/models.go b/packages/lambda-go/models.go
index 00397be6ec..f348a12f2d 100644
--- a/packages/lambda-go/models.go
+++ b/packages/lambda-go/models.go
@@ -11,7 +11,7 @@ type RemotionOptions struct {
ImageFormat string `json:"imageFormat"`
Crf int `json:"crf"`
EnvVariables interface{} `json:"envVariables"`
- Quality int `json:"quality"`
+ JpegQuality int `json:"jpegQuality"`
MaxRetries int `json:"maxRetries"`
Privacy string `json:"privacy"`
ColorSpace string `json:"colorSpace"`
@@ -52,7 +52,7 @@ type renderInternalOptions struct {
ImageFormat string `json:"imageFormat"`
Crf int `json:"crf,omitempty"`
EnvVariables interface{} `json:"envVariables,omitempty"`
- Quality int `json:"quality,omitempty"`
+ JpegQuality int `json:"jpegQuality"`
MaxRetries int `json:"maxRetries"`
Privacy string `json:"privacy"`
ColorSpace string `json:"colorSpace"`
diff --git a/packages/lambda-php/src/RenderParams.php b/packages/lambda-php/src/RenderParams.php
index ce618176ca..1a0318ebc4 100644
--- a/packages/lambda-php/src/RenderParams.php
+++ b/packages/lambda-php/src/RenderParams.php
@@ -45,8 +45,8 @@ class RenderParams
private $imageFormat = 'jpeg';
private $crf = null;
private $envVariables = [];
- private $quality = null;
private $maxRetries = 1;
+ private $jpegQuality = 80;
private $privacy = 'private';
private $colorSpace = 'default';
private $logLevel = 'info';
@@ -83,8 +83,8 @@ class RenderParams
string $imageFormat = 'jpeg',
?int $crf = null,
?array $envVariables = null,
- ?int $quality = null,
int $maxRetries = 1,
+ int $jpegQuality = 80,
string $privacy = 'public',
string $colorSpace = 'default',
string $logLevel = 'info',
@@ -121,8 +121,8 @@ class RenderParams
$this->imageFormat = $imageFormat;
$this->crf = $crf;
$this->envVariables = $envVariables;
- $this->quality = $quality;
$this->maxRetries = $maxRetries;
+ $this->jpegQuality = $jpegQuality;
$this->privacy = $privacy;
$this->colorSpace = $colorSpace;
$this->logLevel = $logLevel;
@@ -164,6 +164,7 @@ class RenderParams
'codec' => $this->getCodec(),
'imageFormat' => $this->getImageFormat(),
'maxRetries' => $this->getMaxRetries(),
+ 'jpegQuality' => $this->getJpegQuality(),
'privacy' => $this->getPrivacy(),
'colorSpace' => $this->getColorSpace(),
'logLevel' => $this->getLogLevel(),
@@ -198,6 +199,8 @@ class RenderParams
if ($this->getEnvVariables() !== null) {
$parameters['envVariables'] = $this->getEnvVariables();
+ } else {
+ $parameters['envVariables'] = new stdClass();
}
if ($this->getPixelFormat() !== null) {
@@ -212,10 +215,6 @@ class RenderParams
$parameters['proResProfile'] = $this->getProResProfile();
}
- if ($this->getQuality() !== null) {
- $parameters['quality'] = $this->getQuality();
- }
-
return $parameters;
}
@@ -431,42 +430,43 @@ class RenderParams
return $this;
}
+
/**
- * Get the value of quality
+ * Get the value of maxRetries
*/
- public function getQuality()
+ public function getMaxRetries()
{
- return $this->quality;
+ return $this->maxRetries;
}
/**
- * Set the value of quality
+ * Set the value of maxRetries
*
* @return self
*/
- public function setQuality($quality)
+ public function setMaxRetries($maxRetries)
{
- $this->quality = $quality;
+ $this->maxRetries = $maxRetries;
return $this;
}
- /**
- * Get the value of maxRetries
+ /**
+ * Get the value of jpegQuality
*/
- public function getMaxRetries()
+ public function getJpegQuality()
{
- return $this->maxRetries;
+ return $this->jpegQuality;
}
/**
- * Set the value of maxRetries
+ * Set the value of jpegQuality
*
* @return self
*/
- public function setMaxRetries($maxRetries)
+ public function setJpegQuality($jpegQuality)
{
- $this->maxRetries = $maxRetries;
+ $this->jpegQuality = $jpegQuality;
return $this;
}
diff --git a/packages/lambda-python/remotion_lambda/models.py b/packages/lambda-python/remotion_lambda/models.py
index 92ca807e5d..fe31e5559c 100644
--- a/packages/lambda-python/remotion_lambda/models.py
+++ b/packages/lambda-python/remotion_lambda/models.py
@@ -23,9 +23,9 @@ class RenderParams:
version: str = ""
image_format: str = 'jpeg'
crf: Optional[int] = None
- env_variables: Optional[List] = None
- quality: Optional[int] = None
+ env_variables: Optional[Dict] = None
max_retries: int = 1
+ jpeg_quality: int = 80
privacy: str = 'public'
color_space: str = 'default'
log_level: str = 'info'
@@ -66,6 +66,8 @@ class RenderParams:
'codec': self.codec,
'imageFormat': self.image_format,
'maxRetries': self.max_retries,
+ 'jpegQuality': self.jpeg_quality,
+ 'envVariables': self.env_variables,
'privacy': self.privacy,
'colorSpace': self.color_space,
'logLevel': self.log_level,
@@ -97,8 +99,8 @@ class RenderParams:
if self.crf is not None:
parameters['crf'] = self.crf
- if self.env_variables is not None:
- parameters['envVariables'] = self.env_variables
+ if self.env_variables is None:
+ parameters['envVariables'] = {}
if self.pixel_format is not None:
parameters['pixelFormat'] = self.pixel_format
@@ -109,9 +111,6 @@ class RenderParams:
if self.x264_preset is not None:
parameters['x264Preset'] = self.x264_preset
- if self.quality is not None:
- parameters['quality'] = self.quality
-
return parameters
diff --git a/packages/lambda/src/api/make-lambda-payload.ts b/packages/lambda/src/api/make-lambda-payload.ts
index 79ba48e1c8..6d42eb300c 100644
--- a/packages/lambda/src/api/make-lambda-payload.ts
+++ b/packages/lambda/src/api/make-lambda-payload.ts
@@ -1,18 +1,80 @@
+import type {
+ AudioCodec,
+ ChromiumOptions,
+ ColorSpace,
+ FrameRange,
+ LogLevel,
+ PixelFormat,
+ ProResProfile,
+ ToOptions,
+ VideoImageFormat,
+ X264Preset,
+} from '@remotion/renderer';
+import type {BrowserSafeApis} from '@remotion/renderer/client';
import {VERSION} from 'remotion/version';
-import type {LambdaStartPayload, LambdaStatusPayload} from '../defaults';
+import type {AwsRegion, DeleteAfter} from '../client';
+import type {
+ LambdaStartPayload,
+ LambdaStatusPayload,
+ OutNameInput,
+ Privacy,
+ WebhookOption,
+} from '../defaults';
import {LambdaRoutines} from '../defaults';
import {
compressInputProps,
getNeedsToUpload,
serializeOrThrow,
} from '../shared/compress-props';
+import type {DownloadBehavior} from '../shared/content-disposition-header';
import {validateDownloadBehavior} from '../shared/validate-download-behavior';
import {validateFramesPerLambda} from '../shared/validate-frames-per-lambda';
+import type {LambdaCodec} from '../shared/validate-lambda-codec';
import {validateLambdaCodec} from '../shared/validate-lambda-codec';
import {validateServeUrl} from '../shared/validate-serveurl';
import {validateWebhook} from '../shared/validate-webhook';
import type {GetRenderProgressInput} from './get-render-progress';
-import type {RenderMediaOnLambdaInput} from './render-media-on-lambda';
+
+export type InnerRenderMediaOnLambdaInput = {
+ region: AwsRegion;
+ functionName: string;
+ serveUrl: string;
+ composition: string;
+ inputProps: Record<string, unknown>;
+ codec: LambdaCodec;
+ imageFormat: VideoImageFormat;
+ crf: number | undefined;
+ envVariables: Record<string, string>;
+ pixelFormat: PixelFormat | undefined;
+ proResProfile: ProResProfile | undefined;
+ x264Preset: X264Preset | null;
+ privacy: Privacy;
+ jpegQuality: number;
+ maxRetries: number;
+ framesPerLambda: number | null;
+ logLevel: LogLevel;
+ frameRange: FrameRange | null;
+ outName: OutNameInput | null;
+ timeoutInMilliseconds: number;
+ chromiumOptions: ChromiumOptions;
+ scale: number;
+ everyNthFrame: number;
+ numberOfGifLoops: number | null;
+ concurrencyPerLambda: number;
+ downloadBehavior: DownloadBehavior;
+ muted: boolean;
+ overwrite: boolean;
+ audioBitrate: string | null;
+ videoBitrate: string | null;
+ webhook: WebhookOption | null;
+ forceWidth: number | null;
+ forceHeight: number | null;
+ rendererFunctionName: string | null;
+ forceBucketName: string | null;
+ audioCodec: AudioCodec | null;
+ colorSpace: ColorSpace;
+ deleteAfter: DeleteAfter | null;
+} & ToOptions<typeof BrowserSafeApis.optionsMap.renderMediaOnLambda>;
export const makeLambdaRenderMediaPayload = async ({
rendererFunctionName,
@@ -49,19 +111,11 @@ export const makeLambdaRenderMediaPayload = async ({
downloadBehavior,
muted,
overwrite,
- dumpBrowserLogs,
jpegQuality,
- quality,
offthreadVideoCacheSizeInBytes,
deleteAfter,
colorSpace,
-}: RenderMediaOnLambdaInput): Promise<LambdaStartPayload> => {
- if (quality) {
- throw new Error(
- 'quality has been renamed to jpegQuality. Please rename the option.',
- );
- }
-
+}: InnerRenderMediaOnLambdaInput): Promise<LambdaStartPayload> => {
const actualCodec = validateLambdaCodec(codec);
validateServeUrl(serveUrl);
validateFramesPerLambda({
@@ -86,31 +140,31 @@ export const makeLambdaRenderMediaPayload = async ({
propsType: 'input-props',
});
return {
- rendererFunctionName: rendererFunctionName ?? null,
- framesPerLambda: framesPerLambda ?? null,
+ rendererFunctionName,
+ framesPerLambda,
composition,
serveUrl,
inputProps: serialized,
codec: actualCodec,
- imageFormat: imageFormat ?? 'jpeg',
+ imageFormat,
crf,
envVariables,
pixelFormat,
proResProfile,
- x264Preset: x264Preset ?? null,
+ x264Preset,
jpegQuality,
- maxRetries: maxRetries ?? 1,
- privacy: privacy ?? 'public',
- logLevel: dumpBrowserLogs ? 'verbose' : logLevel ?? 'info',
- frameRange: frameRange ?? null,
- outName: outName ?? null,
- timeoutInMilliseconds: timeoutInMilliseconds ?? 30000,
- chromiumOptions: chromiumOptions ?? {},
- scale: scale ?? 1,
- everyNthFrame: everyNthFrame ?? 1,
- numberOfGifLoops: numberOfGifLoops ?? 0,
- concurrencyPerLambda: concurrencyPerLambda ?? 1,
- downloadBehavior: downloadBehavior ?? {type: 'play-in-browser'},
+ maxRetries,
+ privacy,
+ logLevel,
+ frameRange,
+ outName,
+ timeoutInMilliseconds,
+ chromiumOptions,
+ scale,
+ everyNthFrame,
+ numberOfGifLoops,
+ concurrencyPerLambda,
+ downloadBehavior,
muted: muted ?? false,
version: VERSION,
overwrite: overwrite ?? false,
diff --git a/packages/lambda/src/api/render-media-on-lambda.ts b/packages/lambda/src/api/render-media-on-lambda.ts
index 84520930f5..5a4893b279 100644
--- a/packages/lambda/src/api/render-media-on-lambda.ts
+++ b/packages/lambda/src/api/render-media-on-lambda.ts
@@ -20,6 +20,7 @@ import {LambdaRoutines} from '../shared/constants';
import type {DownloadBehavior} from '../shared/content-disposition-header';
import {getCloudwatchRendererUrl, getS3RenderUrl} from '../shared/get-aws-urls';
import type {LambdaCodec} from '../shared/validate-lambda-codec';
+import type {InnerRenderMediaOnLambdaInput} from './make-lambda-payload';
import {makeLambdaRenderMediaPayload} from './make-lambda-payload';
export type RenderMediaOnLambdaInput = {
@@ -79,7 +80,7 @@ export type RenderMediaOnLambdaOutput = {
};
const renderMediaOnLambdaRaw = async (
- input: RenderMediaOnLambdaInput,
+ input: InnerRenderMediaOnLambdaInput,
): Promise<RenderMediaOnLambdaOutput> => {
const {functionName, region, rendererFunctionName} = input;
@@ -140,9 +141,58 @@ const renderMediaOnLambdaRaw = async (
* @param params.webhook Configuration for webhook called upon completion or timeout of the render.
* @returns {Promise<RenderMediaOnLambdaOutput>} See documentation for detailed structure
*/
-export const renderMediaOnLambda = PureJSAPIs.wrapWithErrorHandling(
- renderMediaOnLambdaRaw,
-) as typeof renderMediaOnLambdaRaw;
+export const renderMediaOnLambda = (
+ options: RenderMediaOnLambdaInput,
+): Promise<RenderMediaOnLambdaOutput> => {
+ const wrapped = PureJSAPIs.wrapWithErrorHandling(renderMediaOnLambdaRaw);
+ if (options.quality) {
+ throw new Error(
+ 'quality has been renamed to jpegQuality. Please rename the option.',
+ );
+ }
+
+ return wrapped({
+ audioBitrate: options.audioBitrate ?? null,
+ audioCodec: options.audioCodec ?? null,
+ chromiumOptions: options.chromiumOptions ?? {},
+ codec: options.codec,
+ colorSpace: options.colorSpace ?? 'default',
+ composition: options.composition,
+ concurrencyPerLambda: options.concurrencyPerLambda ?? 1,
+ crf: options.crf,
+ downloadBehavior: options.downloadBehavior ?? {type: 'play-in-browser'},
+ envVariables: options.envVariables ?? {},
+ everyNthFrame: options.everyNthFrame ?? 1,
+ forceBucketName: options.forceBucketName ?? null,
+ forceHeight: options.forceHeight ?? null,
+ forceWidth: options.forceWidth ?? null,
+ frameRange: options.frameRange ?? null,
+ framesPerLambda: options.framesPerLambda ?? null,
+ functionName: options.functionName,
+ imageFormat: options.imageFormat ?? 'jpeg',
+ inputProps: options.inputProps ?? {},
+ jpegQuality: options.jpegQuality ?? 80,
+ logLevel: options.logLevel ?? 'info',
+ maxRetries: options.maxRetries ?? 1,
+ muted: options.muted ?? false,
+ numberOfGifLoops: options.numberOfGifLoops ?? 0,
+ offthreadVideoCacheSizeInBytes: options.offthreadVideoCacheSizeInBytes ?? 0,
+ outName: options.outName ?? null,
+ overwrite: options.overwrite ?? false,
+ pixelFormat: options.pixelFormat ?? undefined,
+ privacy: options.privacy ?? 'public',
+ proResProfile: options.proResProfile ?? undefined,
+ region: options.region,
+ rendererFunctionName: options.rendererFunctionName ?? null,
+ scale: options.scale ?? 1,
+ serveUrl: options.serveUrl,
+ timeoutInMilliseconds: options.timeoutInMilliseconds ?? 30000,
+ videoBitrate: options.videoBitrate ?? null,
+ webhook: options.webhook ?? null,
+ x264Preset: options.x264Preset ?? null,
+ deleteAfter: options.deleteAfter ?? null,
+ });
+};
/**
* @deprecated Renamed to renderMediaOnLambda()