Skip to content

πŸŽ₯ Make videos programmatically with React

cloud run CLI roughly working

Matt McGillivray4887d2e14e36
diff --git a/packages/example/package.json b/packages/example/package.json
index b8d42174c4..c76737cc26 100644
--- a/packages/example/package.json
+++ b/packages/example/package.json
@@ -42,6 +42,7 @@
"@remotion/shapes": "3.3.64",
"@remotion/skia": "3.3.64",
"@remotion/three": "3.3.64",
+ "@remotion/gcp": "0.0.1",
"@types/express": "^4.17.11",
"@types/node": "^16.7.5",
"@types/opentype.js": "^1.3.4",
diff --git a/packages/gcp/package.json b/packages/gcp/package.json
index c86f2a7bdc..e45016e0b3 100644
--- a/packages/gcp/package.json
+++ b/packages/gcp/package.json
@@ -20,7 +20,8 @@
"@remotion/bundler": "3.3.64",
"@remotion/cli": "3.3.64",
"@remotion/renderer": "3.3.64",
- "remotion": "3.3.64"
+ "remotion": "3.3.64",
+ "got": "11.8.2"
},
"devDependencies": {
"prettier-plugin-organize-imports": "^3.2.2",
diff --git a/packages/gcp/readme.md b/packages/gcp/readme.md
index 5dae5217bc..b44314a850 100644
--- a/packages/gcp/readme.md
+++ b/packages/gcp/readme.md
@@ -50,7 +50,7 @@ Navigate to the [Service Accounts](https://console.cloud.google.com/projectselec
### 3. Enable required APIs in the project
-- Enable the Cloud Run API. Navigate to the [Cloud Run API](https://console.cloud.google.com/apis/library/run.googleapis.com) screen in Google Cloud Console, and click ENABLE. Make sure the correct project is selected in the dropdown in the top left.
+- Enable the Cloud Run API. Navigate to the [Cloud Run API](https://console.cloud.google.com/apis/library/run.googleapis.com) screen in Google Cloud Console, and click ENABLE. Make sure the correct project is selected in the dropdown in the top left. This is required in order to use Cloud Run.
# Available commands from the CLI:
@@ -96,6 +96,8 @@ This command will bundle the site and upload it to a GCP bucket. To view storage
# Render media on GCP
+## Manually, making a post request
+
Within the Cloud Run service, you can see the URL of the service. Distributed rendering is not yet supported, but rendering a still or media in a single-threaded instance is available.
To render a still, send a POST request to the URL with the following body:
@@ -144,7 +146,18 @@ To render media, send a POST request to the URL with the following body:
}
```
-<br><br><br><br>
+## Using the CLI command, WIP
+
+`pnpm exec remotion gcp render https://storage.googleapis.com/remotioncloudrun-n8x4pc7dz3/sites/axp52acnh2/index.html expert`
+
+- βœ… above render command worked, with meaningful output in the CLI.
+ - 🟩 Cloud Run url is currently hardcoded, pass that in as a param
+- 🟩 Error when rendering color-interpolation composition, checking cloud run logs, it has run out of memory
+ - 🟩 Surface the cloud run logs back to CLI
+ - 🟩 Update Cloud Run Deploy command to accept memory + CPU parameters
+ - 🟩 Deploy new Cloud Run Service with larger limit, test it works
+- 🟩 Work out progress bar for CLI
+ <br><br><br><br>
# To Do
diff --git a/packages/gcp/src/api/render-media-on-gcp.ts b/packages/gcp/src/api/render-media-on-gcp.ts
index 7151cef7fd..226bfd5ec3 100644
--- a/packages/gcp/src/api/render-media-on-gcp.ts
+++ b/packages/gcp/src/api/render-media-on-gcp.ts
@@ -1,4 +1,4 @@
-import {Log} from '../cli/log';
+import got from 'got';
import type {GcpCodec} from '../shared/validate-gcp-codec';
import {validateGcpCodec} from '../shared/validate-gcp-codec';
import {validateServeUrl} from '../shared/validate-serveurl';
@@ -11,15 +11,15 @@ export type RenderMediaOnGcpInput = {
inputProps?: unknown;
codec: GcpCodec;
outputBucket: string;
- outputFolderPath: string;
- outName: string;
+ outputFile: string;
};
export type RenderMediaOnGcpOutput = {
- renderId: string;
+ publicUrl: string;
+ cloudStorageUri: string;
+ size: string;
bucketName: string;
- // cloudWatchLogs: string;
- folderInGcpConsole: string;
+ renderId: string;
};
/**
@@ -45,52 +45,26 @@ export const renderMediaOnGcp = async ({
inputProps,
codec,
outputBucket,
- outputFolderPath,
- outName,
+ outputFile,
}: RenderMediaOnGcpInput): Promise<RenderMediaOnGcpOutput> => {
const actualCodec = validateGcpCodec(codec);
validateServeUrl(serveUrl);
// todo: allow serviceName to be passed in, and fetch the cloud run URL based on the name
- try {
- const postData = JSON.stringify({
- type: 'media',
- composition,
- serveUrl,
- codec: actualCodec,
- inputProps,
- outputBucket,
- outputFile: `${outputFolderPath}${outName}`,
- });
- // Log.info(`Posting11: ${postData} to ${cloudRunUrl}`);
-
- const response = await fetch(cloudRunUrl, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(postData),
- });
+ const postData = {
+ type: 'media',
+ composition,
+ serveUrl,
+ codec: actualCodec,
+ inputProps,
+ outputBucket,
+ outputFile,
+ };
- Log.info('response from Cloud Run πŸ‘‡');
- Log.info(JSON.stringify(response.json()));
+ const response: RenderMediaOnGcpOutput = await got
+ .post(cloudRunUrl, {json: postData})
+ .json();
- return {
- renderId: 'res.renderId',
- bucketName: 'res.bucketName',
- // cloudWatchLogs: getCloudwatchStreamUrl({
- // functionName,
- // method: LambdaRoutines.renderer,
- // region,
- // renderId: res.renderId,
- // rendererFunctionName: rendererFunctionName ?? null,
- // }),
- folderInGcpConsole: 'folderInGcpConsole',
- };
- } catch (e: any) {
- // eslint-disable-next-line no-console
- console.error('Error rendering media on GCP');
- throw e;
- }
+ return response;
};
diff --git a/packages/gcp/src/cli/commands/render/render.ts b/packages/gcp/src/cli/commands/render/render.ts
index f3d42d0e08..06c0e1b626 100644
--- a/packages/gcp/src/cli/commands/render/render.ts
+++ b/packages/gcp/src/cli/commands/render/render.ts
@@ -13,6 +13,7 @@ import {validateServeUrl} from '../../../shared/validate-serveurl';
import {parsedGcpCli} from '../../args';
import {quit} from '../../helpers/quit';
import {Log} from '../../log';
+
// import {makeMultiProgressFromStatus, makeProgressString} from './progress';
export const RENDER_COMMAND = 'render';
@@ -60,20 +61,47 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
// const privacy = parsedLambdaCli.privacy ?? DEFAULT_OUTPUT_PRIVACY;
// validatePrivacy(privacy);
- const outputBucket = parsedGcpCli['output-bucket']; // Todo: I think this should be optional with a fallback
- const outputFolderPath = parsedGcpCli['output-folder-path']; // Todo: I think this should be optional with a fallback
+ const outputBucket =
+ parsedGcpCli['output-bucket'] || 'remotioncloudrun-n8x4pc7dz3'; // Todo: I think this should be optional with a fallback
+
+ // Todo: Check cloudRunUrl is valid, as the error message is obtuse
+ CliInternals.Log.info(
+ CliInternals.chalk.gray(
+ `
+Sending request to Cloud Run:
+ type = media
+ composition = ${composition}
+ codec = ${codec}
+ outputBucket = ${outputBucket}
+ outputFile = ${outName}
+ `.trim()
+ )
+ );
+ Log.info();
const res = await renderMediaOnGcp({
- cloudRunUrl: 'https://new-two-tv4h6muxbq-ts.a.run.app',
+ cloudRunUrl: 'https://cloud-run-render-2gu7pevugq-ue.a.run.app',
// serviceName,
serveUrl,
composition,
inputProps,
codec: codec as GcpCodec,
outputBucket,
- outputFolderPath,
- outName,
+ outputFile: outName,
});
+ Log.info(
+ CliInternals.chalk.blueBright(
+ `
+🀘 Rendered on Cloud Run! 🀘
+
+ Public URL = ${res.publicUrl}
+ Cloud Storage Uri = ${res.cloudStorageUri}
+ Size (KB) = ${Math.round(Number(res.size) / 1000)}
+ Bucket Name = ${res.bucketName}
+ Render ID = ${res.renderId}
+ `.trim()
+ )
+ );
// const totalSteps = downloadName ? 6 : 5;
@@ -81,23 +109,7 @@ export const renderCommand = async (args: string[], remotionRoot: string) => {
// CliInternals.quietFlagProvided()
// );
- Log.info(
- CliInternals.chalk.gray(
- `bucket = ${res.bucketName}, serveUrl = ${serveUrl}` // ToDo: use serviceName if available
- )
- );
- Log.info(
- CliInternals.chalk.gray(
- `renderId = ${res.renderId}, codec = ${codec} (${reason})`
- )
- );
- // const verbose = RenderInternals.isEqualOrBelowLogLevel(
- // ConfigInternals.Logging.getLogLevel(),
- // 'verbose'
- // );
-
// Log.verbose(`CloudWatch logs (if enabled): ${res.cloudWatchLogs}`);
- Log.verbose(`Render folder: ${res.folderInGcpConsole}`);
// const status = await getRenderProgress({
// functionName,
// bucketName: res.bucketName,
diff --git a/packages/gcp/src/functions/render-media-single-thread.ts b/packages/gcp/src/functions/render-media-single-thread.ts
index fb72903fd2..4bdcdb8254 100644
--- a/packages/gcp/src/functions/render-media-single-thread.ts
+++ b/packages/gcp/src/functions/render-media-single-thread.ts
@@ -1,6 +1,7 @@
import type * as ff from '@google-cloud/functions-framework';
import {Storage} from '@google-cloud/storage';
import {renderMedia} from '@remotion/renderer';
+import {randomHash} from '../shared/random-hash';
import {getCompositionFromBody} from './helpers/get-composition-from-body';
/*
@@ -13,7 +14,7 @@ import {getCompositionFromBody} from './helpers/get-composition-from-body';
"titleColor": "black"
},
"outputBucket": "remotionlambda-test",
- "outputFile": "outFolder/mediaOutput.mp4"
+ "outputFile": "mediaOutput.mp4"
}
*/
@@ -27,6 +28,7 @@ export const renderMediaSingleThread = async (
);
const tempFilePath = '/tmp/output.mp4';
+ const renderId = randomHash({randomInTests: true});
await renderMedia({
composition,
@@ -38,10 +40,25 @@ export const renderMediaSingleThread = async (
const storage = new Storage();
- await storage
+ const uploadedResponse = await storage
.bucket(req.body.outputBucket)
- .upload(tempFilePath, {destination: req.body.outputFile});
+ .upload(tempFilePath, {
+ destination: `renders/${renderId}/${req.body.outputFile}`,
+ });
- console.log('output uploaded to ', req.body.outputBucket);
- res.send('OK');
+ const uploadedFile = uploadedResponse[0];
+ const renderMetadata = await uploadedFile.getMetadata();
+ const responseData = {
+ publicUrl: uploadedFile.publicUrl(),
+ cloudStorageUri: uploadedFile.cloudStorageURI.href,
+ size: renderMetadata[0].size,
+ bucketName: req.body.outputBucket,
+ renderId,
+ };
+
+ console.log('Render Completed:', responseData);
+
+ const jsonContent = JSON.stringify(responseData);
+
+ res.end(jsonContent);
};
diff --git a/packages/gcp/src/functions/render-still-single-thread.ts b/packages/gcp/src/functions/render-still-single-thread.ts
index f3a46df8a0..57550dfbef 100644
--- a/packages/gcp/src/functions/render-still-single-thread.ts
+++ b/packages/gcp/src/functions/render-still-single-thread.ts
@@ -1,6 +1,7 @@
import type * as ff from '@google-cloud/functions-framework';
import {Storage} from '@google-cloud/storage';
import {renderStill} from '@remotion/renderer';
+import {randomHash} from '../shared/random-hash';
import {getCompositionFromBody} from './helpers/get-composition-from-body';
/*
@@ -11,7 +12,7 @@ import {getCompositionFromBody} from './helpers/get-composition-from-body';
"text": "Created on Cloud Runℒ️"
},
"outputBucket": "remotionlambda-test",
- "outputFile": "outFolder/stillOutput.png"
+ "outputFile": "stillOutput.png"
}
*/
@@ -25,6 +26,7 @@ export const renderStillSingleThread = async (
);
const tempFilePath = '/tmp/still.png';
+ const renderId = randomHash({randomInTests: true});
await renderStill({
composition,
@@ -35,11 +37,25 @@ export const renderStillSingleThread = async (
const storage = new Storage();
- await storage
+ const uploadedResponse = await storage
.bucket(req.body.outputBucket)
- .upload(tempFilePath, {destination: req.body.outputFile});
+ .upload(tempFilePath, {
+ destination: `renders/${renderId}/${req.body.outputFile}`,
+ });
- console.log('output uploaded to ', req.body.outputBucket);
+ const uploadedFile = uploadedResponse[0];
+ const renderMetadata = await uploadedFile.getMetadata();
+ const responseData = {
+ publicUrl: uploadedFile.publicUrl(),
+ cloudStorageUri: uploadedFile.cloudStorageURI.href,
+ size: renderMetadata[0].size,
+ bucketName: req.body.outputBucket,
+ renderId,
+ };
- res.send('OK');
+ console.log('Render Completed:', responseData);
+
+ const jsonContent = JSON.stringify(responseData);
+
+ res.end(jsonContent);
};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b73521f2c7..94bda9f51f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -485,6 +485,7 @@ importers:
'@remotion/cli': 3.3.64
'@remotion/eslint-config': 3.3.64
'@remotion/eslint-plugin': 3.3.64
+ '@remotion/gcp': 0.0.1
'@remotion/gif': 3.3.64
'@remotion/google-fonts': 3.3.64
'@remotion/lambda': 3.3.64
@@ -534,6 +535,7 @@ importers:
'@remotion/cli': link:../cli
'@remotion/eslint-config': link:../eslint-config
'@remotion/eslint-plugin': link:../eslint-plugin
+ '@remotion/gcp': link:../gcp
'@remotion/gif': link:../gif
'@remotion/google-fonts': link:../google-fonts
'@remotion/lambda': link:../lambda
@@ -586,6 +588,7 @@ importers:
'@remotion/renderer': 3.3.64
'@types/minimist': 1.2.2
eslint: 8.25.0
+ got: 11.8.2
prettier: ^2.7.1
prettier-plugin-organize-imports: ^3.2.2
remotion: 3.3.64
@@ -598,6 +601,7 @@ importers:
'@remotion/bundler': link:../bundler
'@remotion/cli': link:../cli
'@remotion/renderer': link:../renderer
+ got: 11.8.2
remotion: link:../core
devDependencies:
'@jonny/eslint-config': 3.0.266_t54va6jeo5lf3vtqih5uiyrm5e
@@ -13182,8 +13186,8 @@ packages:
dependencies:
clone-response: 1.0.2
get-stream: 5.2.0
- http-cache-semantics: 4.1.0
- keyv: 4.5.0
+ http-cache-semantics: 4.1.1
+ keyv: 4.5.2
lowercase-keys: 2.0.0
normalize-url: 6.1.0
responselike: 2.0.1
@@ -16917,6 +16921,23 @@ packages:
dependencies:
get-intrinsic: 1.2.0
+ /got/11.8.2:
+ resolution: {integrity: sha512-D0QywKgIe30ODs+fm8wMZiAcZjypcCodPNuMz5H9Mny7RJ+IjJ10BdmGW7OM7fHXP+O7r6ZwapQ/YQmMSvB0UQ==}
+ engines: {node: '>=10.19.0'}
+ dependencies:
+ '@sindresorhus/is': 4.6.0
+ '@szmarczak/http-timer': 4.0.6
+ '@types/cacheable-request': 6.0.2
+ '@types/responselike': 1.0.0
+ cacheable-lookup: 5.0.4
+ cacheable-request: 7.0.2
+ decompress-response: 6.0.0
+ http2-wrapper: 1.0.3
+ lowercase-keys: 2.0.0
+ p-cancelable: 2.1.1
+ responselike: 2.0.1
+ dev: false
+
/got/11.8.5:
resolution: {integrity: sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ==}
engines: {node: '>=10.19.0'}
@@ -17406,6 +17427,10 @@ packages:
/http-cache-semantics/4.1.0:
resolution: {integrity: sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==}
+ dev: false
+
+ /http-cache-semantics/4.1.1:
+ resolution: {integrity: sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==}
/http-deceiver/1.2.7:
resolution: {integrity: sha1-+nFolEq5pRnTN8sL7HKE3D5yPYc=}
@@ -18640,8 +18665,8 @@ packages:
json-buffer: 3.0.0
dev: false
- /keyv/4.5.0:
- resolution: {integrity: sha512-2YvuMsA+jnFGtBareKqgANOEKe1mk3HKiXu2fRmAfyxG0MJAywNhi5ttWA3PMjl4NmpyjZNbFifR2vNjW1znfA==}
+ /keyv/4.5.2:
+ resolution: {integrity: sha512-5MHbFaKn8cNSmVW7BYnijeAVlE4cYA/SVkifVgrh7yotnfhKmjuXpDKjrABLnT0SfHWV21P8ow07OGfRrNDg8g==}
dependencies:
json-buffer: 3.0.1