Skip to content

🎥 Make videos programmatically with React

add to most important lambda functions

Jonny Burgerafd3ed811c34
diff --git a/packages/cloudrun/src/api/deploy-service.ts b/packages/cloudrun/src/api/deploy-service.ts
index 587ececf93..a5a58e831f 100644
--- a/packages/cloudrun/src/api/deploy-service.ts
+++ b/packages/cloudrun/src/api/deploy-service.ts
@@ -1,3 +1,4 @@
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {
DEFAULT_MAX_INSTANCES,
DEFAULT_MIN_INSTANCES,
@@ -29,18 +30,7 @@ export type DeployServiceOutput = {
alreadyExists: boolean;
};
-/**
- * @description Creates a Cloud Run service in your project that will be able to render a video in GCP.
- * @link https://remotion.dev/docs/cloudrun/deployservice
- * @param params.performImageVersionValidation Validate that an image exists in the public Artifact Registry that matches the Remotion Version. Default true
- * @param params.memoryLimit Memory limit of Cloud Run service to deploy.
- * @param params.cpuLimit CPU limit of Cloud Run service to deploy.
- * @param params.timeoutSeconds After how many seconds the Cloud Run service should be killed if it does not end itself.
- * @param params.projectID GCP Project ID to deploy the Cloud Run service to.
- * @param params.region GCP region to deploy the Cloud Run service to.
- * @returns {Promise<DeployServiceOutput>} See documentation for detailed structure
- */
-export const deployService = async ({
+const deployServiceRaw = async ({
performImageVersionValidation = true,
memoryLimit,
cpuLimit,
@@ -129,3 +119,17 @@ export const deployService = async ({
alreadyExists: false,
};
};
+
+/**
+ * @description Creates a Cloud Run service in your project that will be able to render a video in GCP.
+ * @link https://remotion.dev/docs/cloudrun/deployservice
+ * @param params.performImageVersionValidation Validate that an image exists in the public Artifact Registry that matches the Remotion Version. Default true
+ * @param params.memoryLimit Memory limit of Cloud Run service to deploy.
+ * @param params.cpuLimit CPU limit of Cloud Run service to deploy.
+ * @param params.timeoutSeconds After how many seconds the Cloud Run service should be killed if it does not end itself.
+ * @param params.projectID GCP Project ID to deploy the Cloud Run service to.
+ * @param params.region GCP region to deploy the Cloud Run service to.
+ * @returns {Promise<DeployServiceOutput>} See documentation for detailed structure
+ */
+export const deployService =
+ BrowserSafeApis.wrapWithErrorHandling(deployServiceRaw);
diff --git a/packages/cloudrun/src/api/deploy-site.ts b/packages/cloudrun/src/api/deploy-site.ts
index 44cfc7655a..335421b1cd 100644
--- a/packages/cloudrun/src/api/deploy-site.ts
+++ b/packages/cloudrun/src/api/deploy-site.ts
@@ -1,4 +1,5 @@
import type {WebpackOverrideFn} from '@remotion/bundler';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {cloudrunDeleteFile, cloudrunLs} from '../functions/helpers/io';
import {bundleSite} from '../shared/bundle-site';
import {getSitesKey} from '../shared/constants';
@@ -37,15 +38,7 @@ export type DeploySiteOutput = Promise<{
};
}>;
-/**
- * @description Deploys a Remotion project to a GCP storage bucket to prepare it for rendering on Cloud Run.
- * @link https://remotion.dev/docs/cloudrun/deploysite
- * @param {string} params.entryPoint An absolute path to the entry file of your Remotion project.
- * @param {string} params.bucketName The name of the bucket to deploy your project into.
- * @param {string} params.siteName The name of the folder in which the project gets deployed to.
- * @param {object} params.options Further options, see documentation page for this function.
- */
-export const deploySite = async ({
+const deploySiteRaw = async ({
entryPoint,
bucketName,
siteName,
@@ -101,7 +94,7 @@ export const deploySite = async ({
bucketName,
key: d.name as string,
});
- }),
+ })
),
]);
@@ -115,3 +108,13 @@ export const deploySite = async ({
},
};
};
+
+/**
+ * @description Deploys a Remotion project to a GCP storage bucket to prepare it for rendering on Cloud Run.
+ * @link https://remotion.dev/docs/cloudrun/deploysite
+ * @param {string} params.entryPoint An absolute path to the entry file of your Remotion project.
+ * @param {string} params.bucketName The name of the bucket to deploy your project into.
+ * @param {string} params.siteName The name of the folder in which the project gets deployed to.
+ * @param {object} params.options Further options, see documentation page for this function.
+ */
+export const deploySite = BrowserSafeApis.wrapWithErrorHandling(deploySiteRaw);
diff --git a/packages/cloudrun/src/api/render-media-on-cloudrun.ts b/packages/cloudrun/src/api/render-media-on-cloudrun.ts
index 7bfd44faf3..c5dddf4640 100644
--- a/packages/cloudrun/src/api/render-media-on-cloudrun.ts
+++ b/packages/cloudrun/src/api/render-media-on-cloudrun.ts
@@ -10,7 +10,7 @@ import type {
X264Preset,
} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
-import type {BrowserSafeApis} from '@remotion/renderer/client';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {Internals} from 'remotion';
import type {
CloudRunCrashResponse,
@@ -64,47 +64,7 @@ export type RenderMediaOnCloudrunInput = {
preferLossless?: boolean;
} & Partial<ToOptions<typeof BrowserSafeApis.optionsMap.renderMediaOnLambda>>;
-/**
- * @description Triggers a render on a GCP Cloud Run service given a composition and a Cloud Run URL.
- * @see [Documentation](https://remotion.dev/docs/cloudrun/renderMediaOnGcp)
- * @param params.cloudRunUrl The URL of the Cloud Run service that should be used. Use either this or serviceName.
- * @param params.serviceName The name of the Cloud Run service that should be used. Use either this or cloudRunUrl.
- * @param params.region The region that the Cloud Run service is deployed in.
- * @param params.serveUrl The URL of the deployed project
- * @param params.composition The ID of the composition which should be rendered.
- * @param params.inputProps The input props that should be passed to the composition.
- * @param params.codec The media codec which should be used for encoding.
- * @param params.forceBucketName The name of the bucket that the output file should be uploaded to.
- * @param params.privacy Whether the output file should be public or private.
- * @param params.outputFile The name of the output file.
- * @param params.updateRenderProgress A callback that is called with the progress of the render.
- * @param params.jpegQuality JPEG quality if JPEG was selected as the image format.
- * @param params.audioCodec The encoding of the audio of the output video.
- * @param params.audioBitrate The target bitrate for the audio of the generated video.
- * @param params.videoBitrate The target bitrate of the generated video.
- * @param params.proResProfile Sets a ProRes profile. Only applies to videos rendered with prores codec.
- * @param params.x264Preset Sets a Preset profile. Only applies to videos rendered with h.264 codec.
- * @param params.crf Constant Rate Factor, controlling the quality.
- * @param params.pixelFormat Custom pixel format to use. Usually used for special use cases like transparent videos.
- * @param params.imageFormat Which image format the frames should be rendered in.
- * @param params.scale Scales the output dimensions by a factor.
- * @param params.everyNthFrame Only used if rendering gigs - renders only every nth frame.
- * @param params.numberOfGifLoops Only used if rendering gigs - how many times the gif should loop. Null means infinite.
- * @param params.frameRange Specify a single frame (a number) or a range of frames (a tuple [number, number]) to be rendered.
- * @param params.envVariables Object containing environment variables to be injected in your project.
- * @param params.chromiumOptions Allows you to set certain Chromium / Google Chrome flags.
- * @param params.muted If set to true, no audio is rendered.
- * @param params.forceWidth Overrides default composition width.
- * @param params.forceHeight Overrides default composition height.
- * @param params.logLevel Level of logging that Cloud Run service should perform. Default "info".
- * @param params.delayRenderTimeoutInMilliseconds A number describing how long the render may take to resolve all delayRender() calls before it times out.
- * @param params.concurrency By default, each Cloud Run service renders with concurrency 100% (equal to number of available cores). You may use the option to customize this value.
- * @param params.enforceAudioTrack Render a silent audio track if there wouldn't be any otherwise.
- * @param params.preferLossless Uses a lossless audio codec, if one is available for the codec. If you set audioCodec, it takes priority over preferLossless.
- * @returns {Promise<RenderMediaOnCloudrunOutput>} See documentation for detailed structure
- */
-
-export const renderMediaOnCloudrun = async ({
+const renderMediaOnCloudrunRaw = async ({
cloudRunUrl,
serviceName,
region,
@@ -275,3 +235,47 @@ export const renderMediaOnCloudrun = async ({
return renderResponse;
};
+
+/**
+ * @description Triggers a render on a GCP Cloud Run service given a composition and a Cloud Run URL.
+ * @see [Documentation](https://remotion.dev/docs/cloudrun/renderMediaOnGcp)
+ * @param params.cloudRunUrl The URL of the Cloud Run service that should be used. Use either this or serviceName.
+ * @param params.serviceName The name of the Cloud Run service that should be used. Use either this or cloudRunUrl.
+ * @param params.region The region that the Cloud Run service is deployed in.
+ * @param params.serveUrl The URL of the deployed project
+ * @param params.composition The ID of the composition which should be rendered.
+ * @param params.inputProps The input props that should be passed to the composition.
+ * @param params.codec The media codec which should be used for encoding.
+ * @param params.forceBucketName The name of the bucket that the output file should be uploaded to.
+ * @param params.privacy Whether the output file should be public or private.
+ * @param params.outputFile The name of the output file.
+ * @param params.updateRenderProgress A callback that is called with the progress of the render.
+ * @param params.jpegQuality JPEG quality if JPEG was selected as the image format.
+ * @param params.audioCodec The encoding of the audio of the output video.
+ * @param params.audioBitrate The target bitrate for the audio of the generated video.
+ * @param params.videoBitrate The target bitrate of the generated video.
+ * @param params.proResProfile Sets a ProRes profile. Only applies to videos rendered with prores codec.
+ * @param params.x264Preset Sets a Preset profile. Only applies to videos rendered with h.264 codec.
+ * @param params.crf Constant Rate Factor, controlling the quality.
+ * @param params.pixelFormat Custom pixel format to use. Usually used for special use cases like transparent videos.
+ * @param params.imageFormat Which image format the frames should be rendered in.
+ * @param params.scale Scales the output dimensions by a factor.
+ * @param params.everyNthFrame Only used if rendering gigs - renders only every nth frame.
+ * @param params.numberOfGifLoops Only used if rendering gigs - how many times the gif should loop. Null means infinite.
+ * @param params.frameRange Specify a single frame (a number) or a range of frames (a tuple [number, number]) to be rendered.
+ * @param params.envVariables Object containing environment variables to be injected in your project.
+ * @param params.chromiumOptions Allows you to set certain Chromium / Google Chrome flags.
+ * @param params.muted If set to true, no audio is rendered.
+ * @param params.forceWidth Overrides default composition width.
+ * @param params.forceHeight Overrides default composition height.
+ * @param params.logLevel Level of logging that Cloud Run service should perform. Default "info".
+ * @param params.delayRenderTimeoutInMilliseconds A number describing how long the render may take to resolve all delayRender() calls before it times out.
+ * @param params.concurrency By default, each Cloud Run service renders with concurrency 100% (equal to number of available cores). You may use the option to customize this value.
+ * @param params.enforceAudioTrack Render a silent audio track if there wouldn't be any otherwise.
+ * @param params.preferLossless Uses a lossless audio codec, if one is available for the codec. If you set audioCodec, it takes priority over preferLossless.
+ * @returns {Promise<RenderMediaOnCloudrunOutput>} See documentation for detailed structure
+ */
+
+export const renderMediaOnCloudrun = BrowserSafeApis.wrapWithErrorHandling(
+ renderMediaOnCloudrunRaw
+) as typeof renderMediaOnCloudrunRaw;
diff --git a/packages/cloudrun/src/api/render-still-on-cloudrun.ts b/packages/cloudrun/src/api/render-still-on-cloudrun.ts
index 0cd7f323f5..73bd173cd6 100644
--- a/packages/cloudrun/src/api/render-still-on-cloudrun.ts
+++ b/packages/cloudrun/src/api/render-still-on-cloudrun.ts
@@ -5,7 +5,7 @@ import type {
ToOptions,
} from '@remotion/renderer';
import {RenderInternals} from '@remotion/renderer';
-import type {BrowserSafeApis} from '@remotion/renderer/client';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {Internals} from 'remotion';
import type {
CloudRunCrashResponse,
@@ -67,7 +67,7 @@ export type RenderStillOnCloudrunInput = {
* @returns {Promise<RenderStillOnCloudrunOutput>} See documentation for detailed structure
*/
-export const renderStillOnCloudrun = async ({
+const renderStillOnCloudrunRaw = async ({
cloudRunUrl,
serviceName,
region,
@@ -203,3 +203,7 @@ export const renderStillOnCloudrun = async ({
return renderResponse;
};
+
+export const renderStillOnCloudrun = BrowserSafeApis.wrapWithErrorHandling(
+ renderStillOnCloudrunRaw
+) as typeof renderStillOnCloudrunRaw;
diff --git a/packages/lambda/src/api/deploy-function.ts b/packages/lambda/src/api/deploy-function.ts
index 6ab66b4443..82439e77f2 100644
--- a/packages/lambda/src/api/deploy-function.ts
+++ b/packages/lambda/src/api/deploy-function.ts
@@ -1,3 +1,4 @@
+import {BrowserSafeApis} from '@remotion/renderer/client';
import {VERSION} from 'remotion/version';
import {getFunctions} from '../api/get-functions';
import type {AwsRegion} from '../pricing/aws-regions';
@@ -32,20 +33,8 @@ export type DeployFunctionOutput = {
alreadyExisted: boolean;
};
-/**
- * @description Creates an AWS Lambda function in your account that will be able to render a video in the cloud.
- * @see [Documentation](https://www.remotion.dev/docs/lambda/deployfunction)
- * @param params.createCloudWatchLogGroup Whether you'd like to create a CloudWatch Log Group to store the logs for this function.
- * @param params.cloudWatchLogRetentionPeriodInDays (optional) The number of days to retain the CloudWatch logs for this function. Default is 14 days.
- * @param params.region The region you want to deploy your function to.
- * @param params.timeoutInSeconds After how many seconds the lambda function should be killed if it does not end itself.
- * @param params.memorySizeInMb How much memory should be allocated to the Lambda function.
- * @param params.architecture The architecture Lambda should run on. One of x86_64 and x64
- * @param params.diskSizeInMb The amount of storage the function should be allocated. The higher, the longer videos you can render. Default 512.
- * @returns {Promise<DeployFunctionOutput>} An object that contains the `functionName` property
- */
-export const deployFunction = async (
- params: DeployFunctionInput,
+const deployFunctionRaw = async (
+ params: DeployFunctionInput
): Promise<DeployFunctionOutput> => {
const diskSizeInMb = params.diskSizeInMb ?? DEFAULT_EPHEMERAL_STORAGE_IN_MB;
@@ -74,7 +63,7 @@ export const deployFunction = async (
f.version === VERSION &&
f.memorySizeInMb === params.memorySizeInMb &&
f.timeoutInSeconds === params.timeoutInSeconds &&
- f.diskSizeInMb === diskSizeInMb,
+ f.diskSizeInMb === diskSizeInMb
);
const created = await createFunction({
@@ -102,3 +91,20 @@ export const deployFunction = async (
alreadyExisted: Boolean(alreadyDeployed),
};
};
+
+/**
+ * @description Creates an AWS Lambda function in your account that will be able to render a video in the cloud.
+ * @see [Documentation](https://www.remotion.dev/docs/lambda/deployfunction)
+ * @param params.createCloudWatchLogGroup Whether you'd like to create a CloudWatch Log Group to store the logs for this function.
+ * @param params.cloudWatchLogRetentionPeriodInDays (optional) The number of days to retain the CloudWatch logs for this function. Default is 14 days.
+ * @param params.region The region you want to deploy your function to.
+ * @param params.timeoutInSeconds After how many seconds the lambda function should be killed if it does not end itself.
+ * @param params.memorySizeInMb How much memory should be allocated to the Lambda function.
+ * @param params.architecture The architecture Lambda should run on. One of x86_64 and x64
+ * @param params.diskSizeInMb The amount of storage the function should be allocated. The higher, the longer videos you can render. Default 512.
+ * @returns {Promise<DeployFunctionOutput>} An object that contains the `functionName` property
+ */
+
+export const deployFunction = BrowserSafeApis.wrapWithErrorHandling(
+ deployFunctionRaw
+) as typeof deployFunctionRaw;
diff --git a/packages/lambda/src/api/deploy-site.ts b/packages/lambda/src/api/deploy-site.ts
index 45b85645ec..34b84284dd 100644
--- a/packages/lambda/src/api/deploy-site.ts
+++ b/packages/lambda/src/api/deploy-site.ts
@@ -1,4 +1,5 @@
import type {WebpackOverrideFn} from '@remotion/bundler';
+import {BrowserSafeApis} from '@remotion/renderer/client';
import fs from 'node:fs';
import {lambdaDeleteFile, lambdaLs} from '../functions/helpers/io';
import type {AwsRegion} from '../pricing/aws-regions';
@@ -44,16 +45,7 @@ export type DeploySiteOutput = Promise<{
};
}>;
-/**
- * @description Deploys a Remotion project to an S3 bucket to prepare it for rendering on AWS Lambda.
- * @see [Documentation](https://remotion.dev/docs/lambda/deploysite)
- * @param {AwsRegion} params.region The region in which the S3 bucket resides in.
- * @param {string} params.entryPoint An absolute path to the entry file of your Remotion project.
- * @param {string} params.bucketName The name of the bucket to deploy your project into.
- * @param {string} params.siteName The name of the folder in which the project gets deployed to.
- * @param {object} params.options Further options, see documentation page for this function.
- */
-export const deploySite = async ({
+const deploySiteRaw = async ({
bucketName,
entryPoint,
siteName,
@@ -128,7 +120,7 @@ export const deploySite = async ({
key: d.Key as string,
region,
});
- }),
+ })
),
]);
@@ -148,3 +140,16 @@ export const deploySite = async ({
},
};
};
+
+/**
+ * @description Deploys a Remotion project to an S3 bucket to prepare it for rendering on AWS Lambda.
+ * @see [Documentation](https://remotion.dev/docs/lambda/deploysite)
+ * @param {AwsRegion} params.region The region in which the S3 bucket resides in.
+ * @param {string} params.entryPoint An absolute path to the entry file of your Remotion project.
+ * @param {string} params.bucketName The name of the bucket to deploy your project into.
+ * @param {string} params.siteName The name of the folder in which the project gets deployed to.
+ * @param {object} params.options Further options, see documentation page for this function.
+ */
+export const deploySite = BrowserSafeApis.wrapWithErrorHandling(
+ deploySiteRaw
+) as typeof deploySiteRaw;
diff --git a/packages/renderer/src/print-useful-error-message.ts b/packages/renderer/src/print-useful-error-message.ts
index a27bd07b8d..14a7b502a7 100644
--- a/packages/renderer/src/print-useful-error-message.ts
+++ b/packages/renderer/src/print-useful-error-message.ts
@@ -2,7 +2,15 @@ import {chalk} from './chalk';
import {Log} from './logger';
import {truthy} from './truthy';
+const alreadyPrinted: Error[] = [];
+
export const printUsefulErrorMessage = (err: Error) => {
+ if (alreadyPrinted.includes(err)) {
+ return;
+ }
+
+ alreadyPrinted.push(err);
+
if (err.message.includes('Could not play video with')) {
Log.info();
Log.info(