Skip to content

πŸŽ₯ Make videos programmatically with React

RenderMediaOnCloudrunOutput only used for success. In still; outputBucket changed to forceBucketName

Matt McGillivray6e0122dbd266
diff --git a/packages/cloudrun/src/api/render-media-on-cloudrun.ts b/packages/cloudrun/src/api/render-media-on-cloudrun.ts
index 2db106fb9e..6b12dd914c 100644
--- a/packages/cloudrun/src/api/render-media-on-cloudrun.ts
+++ b/packages/cloudrun/src/api/render-media-on-cloudrun.ts
@@ -1,6 +1,7 @@
import type {ChromiumOptions, FrameRange, LogLevel} from '@remotion/renderer';
import type {
CloudRunPayloadType,
+ ErrorResponsePayload,
RenderMediaOnCloudrunOutput,
} from '../functions/helpers/payloads';
import type {GcpRegion} from '../pricing/gcp-regions';
@@ -179,7 +180,7 @@ export const renderMediaOnCloudrun = async ({
const authenticatedDataPromise =
await new Promise<RenderMediaOnCloudrunOutput>((resolve, reject) => {
// TODO: Add any sort of type safety
- let response: any;
+ let response: RenderMediaOnCloudrunOutput | ErrorResponsePayload;
const stream: any = postResponse.data;
@@ -193,9 +194,8 @@ export const renderMediaOnCloudrun = async ({
});
stream.on('end', () => {
- if (!response) {
- reject(new Error('no response received'));
- return;
+ if (response.status !== 'success') {
+ throw new Error(response.stack);
}
resolve(response);
diff --git a/packages/cloudrun/src/api/render-still-on-cloudrun.ts b/packages/cloudrun/src/api/render-still-on-cloudrun.ts
index 483d65d719..c237b6e01e 100644
--- a/packages/cloudrun/src/api/render-still-on-cloudrun.ts
+++ b/packages/cloudrun/src/api/render-still-on-cloudrun.ts
@@ -7,19 +7,21 @@ import type {
CloudRunPayloadType,
RenderStillOnCloudrunOutput,
} from '../functions/helpers/payloads';
+import type {GcpRegion} from '../pricing/gcp-regions';
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 RenderStillOnCloudrunInput = {
cloudRunUrl?: string;
serviceName?: string;
- region?: string;
+ region: GcpRegion;
serveUrl: string;
composition: string;
inputProps?: unknown;
- outputBucket: string;
+ forceBucketName: string;
privacy?: 'public' | 'private';
outputFile?: string;
imageFormat: StillImageFormat;
@@ -42,7 +44,7 @@ export type RenderStillOnCloudrunInput = {
* @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.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.imageFormat Which image format the frame should be rendered in.
@@ -64,7 +66,7 @@ export const renderStillOnCloudrun = async ({
serveUrl,
composition,
inputProps,
- outputBucket,
+ forceBucketName,
privacy,
outputFile,
imageFormat,
@@ -80,6 +82,9 @@ export const renderStillOnCloudrun = async ({
validateServeUrl(serveUrl);
if (privacy) validatePrivacy(privacy);
+ const outputBucket =
+ forceBucketName ?? (await getOrCreateBucket({region})).bucketName;
+
const cloudRunEndpoint = await getCloudrunEndpoint({
cloudRunUrl,
serviceName,
diff --git a/packages/cloudrun/src/cli/commands/render/renderMedia.ts b/packages/cloudrun/src/cli/commands/render/renderMedia.ts
index 3a25caf1f5..3e11d3027a 100644
--- a/packages/cloudrun/src/cli/commands/render/renderMedia.ts
+++ b/packages/cloudrun/src/cli/commands/render/renderMedia.ts
@@ -5,7 +5,6 @@ import type {CloudrunCodec} from '../../../shared/validate-gcp-codec';
import {ConfigInternals} from '@remotion/cli/config';
import {downloadFile} from '../../../api/download-file';
import {parsedCloudrunCli} from '../../args';
-import {quit} from '../../helpers/quit';
import {Log} from '../../log';
import {renderArgsCheck} from './helpers/renderArgsCheck';
@@ -146,13 +145,12 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
renderProgress.doneIn = Date.now() - renderStart;
updateProgress();
- if (res.status === 'success') {
- Log.info(`
+ Log.info(`
`);
- Log.info(
- CliInternals.chalk.blueBright(
- `
+ Log.info(
+ CliInternals.chalk.blueBright(
+ `
${res.publicUrl ? `Public URL = ${decodeURIComponent(res.publicUrl)}` : ``}
Cloud Storage Uri = ${res.cloudStorageUri}
Size (KB) = ${Math.round(Number(res.size) / 1000)}
@@ -161,26 +159,21 @@ Privacy = ${res.privacy}
Render ID = ${res.renderId}
Codec = ${codec} (${codecReason})
`.trim()
- )
- );
+ )
+ );
- if (downloadName) {
- Log.info('');
- Log.info('downloading file...');
+ if (downloadName) {
+ Log.info('');
+ Log.info('downloading file...');
- const destination = await downloadFile({
- bucketName: res.bucketName,
- gsutilURI: res.cloudStorageUri,
- downloadName,
- });
+ const destination = await downloadFile({
+ bucketName: res.bucketName,
+ gsutilURI: res.cloudStorageUri,
+ downloadName,
+ });
- Log.info(
- CliInternals.chalk.blueBright(`Downloaded file to ${destination}!`)
- );
- }
- } else {
- Log.error('Render failed with the following error: ');
- Log.error(res.stack);
- quit(1);
+ Log.info(
+ CliInternals.chalk.blueBright(`Downloaded file to ${destination}!`)
+ );
}
};
diff --git a/packages/cloudrun/src/cli/commands/render/renderStill.ts b/packages/cloudrun/src/cli/commands/render/renderStill.ts
index e853967003..8bf671adcd 100644
--- a/packages/cloudrun/src/cli/commands/render/renderStill.ts
+++ b/packages/cloudrun/src/cli/commands/render/renderStill.ts
@@ -2,7 +2,6 @@ import {CliInternals} from '@remotion/cli';
import {ConfigInternals} from '@remotion/cli/config';
import {downloadFile} from '../../../api/download-file';
import {renderStillOnCloudrun} from '../../../api/render-still-on-cloudrun';
-import {quit} from '../../helpers/quit';
import {Log} from '../../log';
import {renderArgsCheck} from './helpers/renderArgsCheck';
@@ -17,9 +16,10 @@ export const renderStillSubcommand = async (
cloudRunUrl,
composition,
outName,
- outputBucket,
+ forceBucketName,
privacy,
downloadName,
+ region,
} = await renderArgsCheck(RENDER_STILL_SUBCOMMAND, args);
const {
@@ -53,9 +53,10 @@ export const renderStillSubcommand = async (
CliInternals.chalk.gray(
`
Cloud Run Service URL = ${cloudRunUrl}
+Region = ${region}
Type = still
Composition = ${composition}
-Output Bucket = ${outputBucket}
+Output Bucket = ${forceBucketName}
Output File = ${outName ?? 'out.png'}
Output File Privacy = ${privacy}
${downloadName ? ` Downloaded File = ${downloadName}` : ''}
@@ -89,6 +90,7 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
const res = await renderStillOnCloudrun({
cloudRunUrl,
serveUrl,
+ region,
inputProps,
imageFormat,
composition,
@@ -100,44 +102,38 @@ ${downloadName ? ` Downloaded File = ${downloadName}` : ''}
scale,
forceHeight: height,
forceWidth: width,
- outputBucket,
+ forceBucketName,
outputFile: outName,
logLevel: ConfigInternals.Logging.getLogLevel(),
});
doneIn = Date.now() - renderStart;
updateProgress(true);
- if (res.status === 'success') {
- Log.info(
- CliInternals.chalk.gray(`Cloud Storage Uri = ${res.cloudStorageUri}`)
- );
- Log.info(CliInternals.chalk.gray(`Render ID = ${res.renderId}`));
- Log.info(
- CliInternals.chalk.gray(
- `${Math.round(Number(res.size) / 1000)} KB, Privacy: ${
- res.privacy
- }, Bucket: ${res.bucketName}`
- )
- );
- Log.info(CliInternals.chalk.blue(`β—‹ ${res.publicUrl}`));
+ Log.info(
+ CliInternals.chalk.gray(`Cloud Storage Uri = ${res.cloudStorageUri}`)
+ );
+ Log.info(CliInternals.chalk.gray(`Render ID = ${res.renderId}`));
+ Log.info(
+ CliInternals.chalk.gray(
+ `${Math.round(Number(res.size) / 1000)} KB, Privacy: ${
+ res.privacy
+ }, Bucket: ${res.bucketName}`
+ )
+ );
+ Log.info(CliInternals.chalk.blue(`β—‹ ${res.publicUrl}`));
- if (downloadName) {
- Log.info('');
- Log.info('downloading file...');
+ if (downloadName) {
+ Log.info('');
+ Log.info('downloading file...');
- const destination = await downloadFile({
- bucketName: res.bucketName,
- gsutilURI: res.cloudStorageUri,
- downloadName,
- });
+ const destination = await downloadFile({
+ bucketName: res.bucketName,
+ gsutilURI: res.cloudStorageUri,
+ downloadName,
+ });
- Log.info(
- CliInternals.chalk.blueBright(`Downloaded file to ${destination}!`)
- );
- }
- } else {
- Log.error('Render failed with the following reason:');
- Log.error(res.stack);
- quit(1);
+ Log.info(
+ CliInternals.chalk.blueBright(`Downloaded file to ${destination}!`)
+ );
}
};
diff --git a/packages/cloudrun/src/functions/helpers/payloads.ts b/packages/cloudrun/src/functions/helpers/payloads.ts
index 410c9fe11c..6de7c9e794 100644
--- a/packages/cloudrun/src/functions/helpers/payloads.ts
+++ b/packages/cloudrun/src/functions/helpers/payloads.ts
@@ -71,39 +71,33 @@ const renderFailResponsePayload = z.object({
stack: z.string(),
});
-const renderStillOnLambdaResponsePayload = z.discriminatedUnion('status', [
- z.object({
- publicUrl: z.string().optional().nullable(),
- cloudStorageUri: z.string(),
- size: z.number(),
- bucketName: z.string(),
- renderId: z.string(),
- status: z.literal('success'),
- privacy: z.enum(['public-read', 'project-private']),
- }),
- renderFailResponsePayload,
-]);
+const renderStillOnCloudrunResponsePayload = z.object({
+ publicUrl: z.string().optional().nullable(),
+ cloudStorageUri: z.string(),
+ size: z.number(),
+ bucketName: z.string(),
+ renderId: z.string(),
+ status: z.literal('success'),
+ privacy: z.enum(['public-read', 'project-private']),
+});
-const renderMediaOnLambdaResponsePayload = z.discriminatedUnion('status', [
- z.object({
- publicUrl: z.string().optional().nullable(),
- cloudStorageUri: z.string(),
- size: z.number(),
- bucketName: z.string(),
- renderId: z.string(),
- status: z.literal('success'),
- privacy: z.enum(['public-read', 'project-private']),
- }),
- renderFailResponsePayload,
-]);
+const renderMediaOnCloudrunResponsePayload = z.object({
+ publicUrl: z.string().optional().nullable(),
+ cloudStorageUri: z.string(),
+ size: z.number(),
+ bucketName: z.string(),
+ renderId: z.string(),
+ status: z.literal('success'),
+ privacy: z.enum(['public-read', 'project-private']),
+});
export type CloudRunPayloadType = z.infer<typeof CloudRunPayload>;
export type RenderStillOnCloudrunOutput = z.infer<
- typeof renderStillOnLambdaResponsePayload
+ typeof renderStillOnCloudrunResponsePayload
>;
export type RenderMediaOnCloudrunOutput = z.infer<
- typeof renderMediaOnLambdaResponsePayload
+ typeof renderMediaOnCloudrunResponsePayload
>;
export type ErrorResponsePayload = z.infer<typeof renderFailResponsePayload>;
diff --git a/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar b/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar
index d02a8da5da..dbcf885dd8 100644
Binary files a/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar and b/packages/cloudrun/src/gcpInstaller/gcpInstaller.tar differ
diff --git a/packages/docs/docs/cloudrun/rendermediaoncloudrun.md b/packages/docs/docs/cloudrun/rendermediaoncloudrun.md
index b1cd7cf4da..f8e88e21d4 100644
--- a/packages/docs/docs/cloudrun/rendermediaoncloudrun.md
+++ b/packages/docs/docs/cloudrun/rendermediaoncloudrun.md
@@ -30,6 +30,7 @@ const result = await renderMediaOnCloudrun({
});
console.log(result.bucketName);
+console.log(result.renderId);
```
## Arguments