🎥 Make videos programmatically with React
render docs + aligning inputs with lambda
Matt McGillivray22b793acd666
diff --git a/packages/cloudrun/package.json b/packages/cloudrun/package.jsonindex 818c63b109..914fb2f8ea 100644--- a/packages/cloudrun/package.json+++ b/packages/cloudrun/package.json@@ -43,9 +43,6 @@},"typesVersions": {">=1.0": {- "defaults": [- "dist/defaults.d.ts"- ],"regions": ["dist/regions.d.ts"]diff --git a/packages/cloudrun/src/api/render-media-on-cloudrun.ts b/packages/cloudrun/src/api/render-media-on-cloudrun.tsindex 3cd75fa779..2db106fb9e 100644--- a/packages/cloudrun/src/api/render-media-on-cloudrun.ts+++ b/packages/cloudrun/src/api/render-media-on-cloudrun.ts@@ -3,27 +3,29 @@ import type {CloudRunPayloadType,RenderMediaOnCloudrunOutput,} from '../functions/helpers/payloads';+import type {GcpRegion} from '../pricing/gcp-regions';import type {CloudrunCodec} from '../shared/validate-gcp-codec';import {validateCloudrunCodec} from '../shared/validate-gcp-codec';import {validatePrivacy} from '../shared/validate-privacy';import {validateServeUrl} from '../shared/validate-serveurl';+import {getOrCreateBucket} from './get-or-create-bucket';import {getAuthClientForUrl} from './helpers/get-auth-client-for-url';import {getCloudrunEndpoint} from './helpers/get-cloudrun-endpoint';export type RenderMediaOnCloudrunInput = {cloudRunUrl?: string;serviceName?: string;- region?: string;+ region: GcpRegion;serveUrl: string;composition: string;inputProps?: unknown;- codec: CloudrunCodec;privacy?: 'public' | 'private';- outputBucket: string;- outputFile?: string;+ forceBucketName?: string;+ outName?: string;updateRenderProgress?: (progress: number) => void;- jpegQuality?: number;+ codec: CloudrunCodec;audioCodec?: 'mp3' | 'aac' | 'pcm-16' | 'opus';+ jpegQuality?: number;audioBitrate?: string | null;videoBitrate?: string | null;proResProfile?:@@ -67,7 +69,7 @@ export type RenderMediaOnCloudrunInput = {* @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.outputBucket The name of the bucket that the output file should be uploaded to.+ * @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.@@ -100,9 +102,9 @@ export const renderMediaOnCloudrun = async ({composition,inputProps,codec,- outputBucket,+ forceBucketName,privacy,- outputFile,+ outName,updateRenderProgress,jpegQuality,audioCodec,@@ -127,6 +129,9 @@ export const renderMediaOnCloudrun = async ({validateServeUrl(serveUrl);if (privacy) validatePrivacy(privacy);+ const outputBucket =+ forceBucketName ?? (await getOrCreateBucket({region})).bucketName;+const cloudRunEndpoint = await getCloudrunEndpoint({cloudRunUrl,serviceName,@@ -155,7 +160,7 @@ export const renderMediaOnCloudrun = async ({muted,outputBucket,privacy,- outputFile,+ outName,forceWidth,forceHeight,type: 'media',diff --git a/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts b/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.tsindex 0b76782cec..b76212402b 100644--- a/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts+++ b/packages/cloudrun/src/cli/commands/render/helpers/renderArgsCheck.ts@@ -64,14 +64,10 @@ export const renderArgsCheck = async (subcommand: string, args: string[]) => {const privacy = parsedCloudrunCli.privacy ?? DEFAULT_OUTPUT_PRIVACY;validatePrivacy(privacy);- let outputBucket = parsedCloudrunCli['output-bucket'];- if (!outputBucket) {- if (!remotionBucket) {- remotionBucket = (await getOrCreateBucket({region})).bucketName;- }-- outputBucket = remotionBucket;- }+ const forceBucketName =+ parsedCloudrunCli['force-bucket-name'] ??+ remotionBucket ??+ (await getOrCreateBucket({region})).bucketName;let cloudRunUrl = parsedCloudrunCli['cloud-run-url'];let serviceName = parsedCloudrunCli['service-name'];@@ -108,8 +104,9 @@ export const renderArgsCheck = async (subcommand: string, args: string[]) => {cloudRunUrl,composition,outName,- outputBucket,+ forceBucketName,privacy,downloadName,+ region,};};diff --git a/packages/cloudrun/src/cli/commands/render/renderMedia.ts b/packages/cloudrun/src/cli/commands/render/renderMedia.tsindex 584b0092aa..3a25caf1f5 100644--- a/packages/cloudrun/src/cli/commands/render/renderMedia.ts+++ b/packages/cloudrun/src/cli/commands/render/renderMedia.ts@@ -20,9 +20,10 @@ export const renderMediaSubcommand = async (cloudRunUrl,composition,outName,- outputBucket,+ forceBucketName,downloadName,privacy,+ region,} = await renderArgsCheck(RENDER_MEDIA_SUBCOMMAND, args);const {codec, reason: codecReason} = CliInternals.getFinalOutputCodec({@@ -65,10 +66,11 @@ export const renderMediaSubcommand = async (CliInternals.chalk.gray(`Cloud Run Service URL = ${cloudRunUrl}+Region = ${region}Type = mediaComposition = ${composition}Codec = ${codec}-Output Bucket = ${outputBucket}+Output Bucket = ${forceBucketName}Output File = ${outName ?? 'out.mp4'}Output File Privacy = ${privacy}${downloadName ? ` Downloaded File = ${downloadName}` : ''}@@ -114,6 +116,7 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}const res = await renderMediaOnCloudrun({cloudRunUrl,serveUrl,+ region,inputProps,codec: codec as CloudrunCodec,imageFormat,@@ -125,7 +128,7 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}composition,privacy,frameRange: frameRange ?? undefined,- outputFile: outName,+ outName,chromiumOptions,scale,numberOfGifLoops,@@ -136,7 +139,7 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}forceHeight: height,forceWidth: width,audioCodec,- outputBucket,+ forceBucketName,updateRenderProgress,logLevel: ConfigInternals.Logging.getLogLevel(),});@@ -150,7 +153,7 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}Log.info(CliInternals.chalk.blueBright(`-Public URL = ${decodeURIComponent(res.publicUrl)}+${res.publicUrl ? `Public URL = ${decodeURIComponent(res.publicUrl)}` : ``}Cloud Storage Uri = ${res.cloudStorageUri}Size (KB) = ${Math.round(Number(res.size) / 1000)}Bucket Name = ${res.bucketName}diff --git a/packages/cloudrun/src/client.ts b/packages/cloudrun/src/client.tsdeleted file mode 100644index 08ebc0edb2..0000000000--- a/packages/cloudrun/src/client.ts+++ /dev/null@@ -1,6 +0,0 @@-import {renderMediaOnCloudrun} from './api/render-media-on-cloudrun';-import {renderStillOnCloudrun} from './api/render-still-on-cloudrun';-import type {GcpRegion} from './pricing/gcp-regions';--export {renderMediaOnCloudrun, renderStillOnCloudrun};-export type {GcpRegion};diff --git a/packages/cloudrun/src/functions/helpers/payloads.ts b/packages/cloudrun/src/functions/helpers/payloads.tsindex 0243818abd..410c9fe11c 100644--- a/packages/cloudrun/src/functions/helpers/payloads.ts+++ b/packages/cloudrun/src/functions/helpers/payloads.ts@@ -41,7 +41,7 @@ export const CloudRunPayload = z.discriminatedUnion('type', [chromiumOptions: chromiumOptions.optional(),muted: z.boolean().optional(),outputBucket: z.string(),- outputFile: z.string().optional(),+ outName: z.string().optional(),privacy: z.enum(['public', 'private']).optional(),logLevel,}),@@ -73,7 +73,7 @@ const renderFailResponsePayload = z.object({const renderStillOnLambdaResponsePayload = z.discriminatedUnion('status', [z.object({- publicUrl: z.string(),+ publicUrl: z.string().optional().nullable(),cloudStorageUri: z.string(),size: z.number(),bucketName: z.string(),@@ -86,7 +86,7 @@ const renderStillOnLambdaResponsePayload = z.discriminatedUnion('status', [const renderMediaOnLambdaResponsePayload = z.discriminatedUnion('status', [z.object({- publicUrl: z.string(),+ publicUrl: z.string().optional().nullable(),cloudStorageUri: z.string(),size: z.number(),bucketName: z.string(),diff --git a/packages/cloudrun/src/functions/render-media-single-thread.ts b/packages/cloudrun/src/functions/render-media-single-thread.tsindex c1c8993ad3..76796d2283 100644--- a/packages/cloudrun/src/functions/render-media-single-thread.ts+++ b/packages/cloudrun/src/functions/render-media-single-thread.ts@@ -70,7 +70,7 @@ export const renderMediaSingleThread = async (const uploadedResponse = await storage.bucket(body.outputBucket).upload(tempFilePath, {- destination: `renders/${renderId}/${body.outputFile ?? 'out.mp4'}`,+ destination: `renders/${renderId}/${body.outName ?? 'out.mp4'}`,predefinedAcl: publicUpload ? 'publicRead' : 'projectPrivate',});@@ -78,7 +78,7 @@ export const renderMediaSingleThread = async (const renderMetadata = await uploadedFile.getMetadata();const responseData: RenderMediaOnCloudrunOutput = {status: 'success',- publicUrl: uploadedFile.publicUrl(),+ publicUrl: publicUpload ? uploadedFile.publicUrl() : null,cloudStorageUri: uploadedFile.cloudStorageURI.href,size: renderMetadata[0].size,bucketName: body.outputBucket,diff --git a/packages/cloudrun/src/index.ts b/packages/cloudrun/src/index.tsindex 64640f330d..4fb06186e4 100644--- a/packages/cloudrun/src/index.ts+++ b/packages/cloudrun/src/index.ts@@ -9,8 +9,10 @@ import {getRegions} from './api/get-regions';import {getServiceInfo} from './api/get-service-info';import {getServices} from './api/get-services';import {getSites} from './api/get-sites';+import type {RenderMediaOnCloudrunInput} from './api/render-media-on-cloudrun';import {renderMediaOnCloudrun} from './api/render-media-on-cloudrun';import {renderStillOnCloudrun} from './api/render-still-on-cloudrun';+import type {RenderMediaOnCloudrunOutput} from './functions/helpers/payloads';import {CloudrunInternals} from './internals';export {@@ -25,4 +27,9 @@ export {getRegions,getSites,};-export type {DeployServiceInput, DeployServiceOutput};+export type {+ DeployServiceInput,+ DeployServiceOutput,+ RenderMediaOnCloudrunOutput,+ RenderMediaOnCloudrunInput,+};diff --git a/packages/docs/docs/cloudrun/cli/render.md b/packages/docs/docs/cloudrun/cli/render.mdindex e04f8cfc25..cce7dd6a6c 100644--- a/packages/docs/docs/cloudrun/cli/render.md+++ b/packages/docs/docs/cloudrun/cli/render.md@@ -62,9 +62,9 @@ One of:- `"public"` (_default_): The rendered media is publicly accessible under the Cloud Storage URL.- `"private"`: The rendered media is not publicly available, but is available within the GCP project to those with the correct permissions.-### `output-bucket`+### `--force-bucket-name`-The bucket to place the rendered media/still in. The resulting Google Cloud Storage URL will be in the format `gs://{bucket-name}/renders/{render-id}/{file-name}`. If this is not passed, the bucket that matches the region will be used.+Specify a specific bucket name to be used for the output. The resulting Google Cloud Storage URL will be in the format `gs://{bucket-name}/renders/{render-id}/{file-name}`. If not set, Remotion will choose the right bucket to use based on the region.### `--jpeg-quality`diff --git a/packages/docs/docs/cloudrun/rendermediaoncloudrun.md b/packages/docs/docs/cloudrun/rendermediaoncloudrun.mdindex 1333ed77b7..b1cd7cf4da 100644--- a/packages/docs/docs/cloudrun/rendermediaoncloudrun.md+++ b/packages/docs/docs/cloudrun/rendermediaoncloudrun.md@@ -1 +1,283 @@-TODO+---+image: /generated/articles-docs-cloudrun-rendermediaoncloudrun.png+id: rendermediaoncloudrun+title: renderMediaOnCloudrun()+crumb: "Cloud Run API"+---++import { MinimumFramesPerLambda } from "../../components/lambda/default-frames-per-lambda";++Kicks off a media rendering process on Remotion Cloud Run.++Requires a [service](/docs/cloudrun/deployservice) to already be deployed to execute the render.+A [site](/docs/cloudrun/deploysite) or a [Serve URL](/docs/terminology#serve-url) needs to be specified to determine what will be rendered.++## Example++```tsx twoslash+// @module: esnext+// @target: es2017+// ---cut---+import { renderMediaOnCloudrun } from "@remotion/cloudrun";++const result = await renderMediaOnCloudrun({+ region: "us-east1",+ serviceName: "remotion-render-bds9aab",+ composition: "MyVideo",+ serveUrl:+ "https://storage.googleapis.com/remotioncloudrun-123asd321/sites/abcdefgh",+ codec: "h264",+});++console.log(result.bucketName);+```++## Arguments++An object with the following properties:++### `cloudRunUrl?`++_optional. Required if serviceName not supplied_++The url of the Cloud Run service which should be used to perform the render. You must set either cloudRunUrl or serviceName, but not both++### `serviceName?`++_optional. Required if cloudRunUrl not supplied_++The name of the Cloud Run service which should be used to perform the render. This is used in conjunction with the region to determine the service endpoint, as the same service name can exist across multiple regions.++### `region`++In which region your Cloud Run service is deployed. It's highly recommended that your Remotion site is also in the same region.++### `serveUrl`++A URL pointing to a Remotion project. Use [`deploySite()`](/docs/cloudrun/deploysite) to deploy a Remotion project.++### `composition`++The `id` of the [composition](/docs/composition) you want to render.++### `codec`++Which codec should be used to encode the video.++Video codecs `h264`, `vp8` and `prores` are supported.++Audio codecs `mp3`, `aac` and `wav` are also supported.++See also [`renderMedia() -> codec`](/docs/renderer/render-media#codec).++### `inputProps?`++_optional_++React props that are passed to your composition. You define the shape of the props that the component accepts.++### `privacy?`++_optional_++One of:++- `"public"` (_default_): The rendered media is publicly accessible under the Cloud Storage URL.+- `"private"`: The rendered media is not publicly available, but is available within the GCP project to those with the correct permissions.++### `forceBucketName?`++_optional_++Specify a specific bucket name to be used for the output. The resulting Google Cloud Storage URL will be in the format `gs://{bucket-name}/renders/{render-id}/{file-name}`. If not set, Remotion will choose the right bucket to use based on the region.++### `updateRenderProgress?`++_optional_++A callback that is called with the progress of the render.++### `audioCodec?`++_optional_++Choose the encoding of your audio.++- Choose `pcm-16` if you need uncompressed audio.+- Not all video containers support all audio codecs.+- This option takes precedence if the `codec` option also specifies an audio codec.++Refer to the [Encoding guide](/docs/encoding/#audio-codec) to see defaults and supported combinations.++### `jpegQuality?`++_optional_++See [`renderMedia() -> jpegQuality`](/docs/renderer/render-media#jpegquality).++### `audioBitrate?`++_optional_++See [`renderMedia() -> audioBitrate`](/docs/renderer/render-media#audiobitrate).++### `videoBitrate?`++_optional_++See [`renderMedia() -> videoBitrate`](/docs/renderer/render-media#videobitrate).++### `proResProfile?`++_optional_++See [`renderMedia() -> proResProfile`](/docs/renderer/render-media#proresprofile).++### `crf?`++_optional_++See [`renderMedia() -> crf`](/docs/renderer/render-media#crf).++### `pixelFormat?`++_optional_++See [`renderMedia() -> pixelFormat`](/docs/renderer/render-media#pixelformat).++### `imageFormat?`++_optional_++See [`renderMedia() -> imageFormat`](/docs/renderer/render-media#imageformat).++### `scale?`++_optional_++Scales the output dimensions by a factor. See [Scaling](/docs/scaling) to learn more about this feature.++### `everyNthFrame?`++_optional_++Renders only every nth frame. For example only every second frame, every third frame and so on. Only works for rendering GIFs. [See here for more details.](/docs/render-as-gif)++### `numberOfGifLoops?`++_optional_++[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)++### `frameRange?`++_optional_++Specify a single frame (a number) or a range of frames (a tuple [number, number]) to be rendered.++### `envVariables?`++_optional_++See [`renderMedia() -> envVariables`](/docs/renderer/render-media#envvariables).++### `chromiumOptions?`++_optional_++Allows you to set certain Chromium / Google Chrome flags. See: [Chromium flags](/docs/chromium-flags).++#### `disableWebSecurity`++_boolean - default `false`_++This will most notably disable CORS among other security features.++#### `ignoreCertificateErrors`++_boolean - default `false`_++Results in invalid SSL certificates, such as self-signed ones, being ignored.++#### `gl`++_string_++Select the OpenGL renderer backend for Chromium.+Accepted values:++- `"angle"`,+- `"egl"`,+- `"swiftshader"`+- `"swangle"`+- `null` - Chromiums default++### `muted?`++_optional_++Disables audio output. See also [`renderMedia() -> muted`](/docs/renderer/render-media#muted).++### `forceWidth?`++_available_++Overrides default composition width.++### `forceHeight?`++_available_++Overrides default composition height.++### `logLevel?`++_available_++One of `verbose`, `info`, `warn`, `error`. Determines how much is being logged inside the Lambda function. Defaults to `info`.++### `outName?`++_optional_++The file name of the media output.++It can either be:++- `undefined` - it will default to `out` plus the appropriate file extension, for example: `renders/${renderId}/out.mp4`.+- A `string` - it will get saved to the same Cloud Storage bucket as your site under the key `renders/{renderId}/{outName}`.++## Return value++Returns a promise resolving to an object containing the following:++### `renderId`++A unique alphanumeric identifier for this render. Useful for obtaining status and finding the relevant files in the Cloud Storage bucket.++### `bucketName`++The Cloud Storage bucket name in which all files are being saved.++### `privacy`++Privacy of the output file, either:++- "public-read" - Publicly accessible under the Cloud Storage URL.+- "project-private" - Not publicly available, but is available within the GCP project to those with the correct permissions.++### `publicUrl`++If the privacy is set to public, this will be the publicly accessible URL of the rendered file. If the privacy is not public, this will be null.++### `cloudStorageUri`++Google Storage path, beginning with `gs://{bucket-name}`. Can be used with the [gsutil](https://cloud.google.com/storage/docs/gsutil) CLI tool.++### `size`++Size of the rendered media in KB.++## See also++- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/cloudrun/src/api/render-media-on-cloudrun.ts)