Skip to content

🎥 Make videos programmatically with React

Bundle `remotion` imports into sandbox scripts, add missing `chromeMode` to render configs, clean up template scripts

Jonny Burger95d7142b2901
diff --git a/packages/docs/docs/vercel-sandbox.mdx b/packages/docs/docs/vercel-sandbox.mdx
index 4882292294..bdaf7136bc 100644
--- a/packages/docs/docs/vercel-sandbox.mdx
+++ b/packages/docs/docs/vercel-sandbox.mdx
@@ -10,13 +10,14 @@ Each render spawns an ephemeral Linux VM with full access to the Remotion render
As a reference implementation, we have created a template: [Next.js Sandbox Template](https://remotion.dev/templates/vercel).
-## Getting Started
+## Starter Template
+Use our [Next.js template](/templates/vercel) to get started quickly.
You can deploy with one-click using the button below:
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?demo-description=Render%20your%20Remotion%20videos%20on%20Vercel.&demo-image=%2F%2Fimages.ctfassets.net%2Fe5382hct74si%2F4pq2kfE4t05fMkDCKGsfqz%2F1444f1b559d50391052fdf5102502ac9%2FFlagsmith_Dark.png&demo-title=Remotion%20on%20Vercel&demo-url=https%3A%2F%2Ftemplate-vercel.remotion.dev%2F&from=templates&products=%255B%257B%2522type%2522%253A%2522blob%2522%257D%255D&project-name=Remotion%20on%20Vercel&project-names=Comma%20separated%20list%20of%20project%20names%2Cto%20match%20the%20root-directories&repository-name=remotion-on-vercel&repository-url=https%3A%2F%2Fgithub.com%2Fremotion-dev%2Ftemplate-vercel&root-directories=List%20of%20directory%20paths%20for%20the%20directories%20to%20clone%20into%20projects)
-Or, [visit the Remotion on Vercel template ](https://vercel.com/templates/template/remotion-on-vercel) on Vercel's template marketplace.
+Or, [visit the Remotion on Vercel template](https://vercel.com/templates/template/remotion-on-vercel) on Vercel's template marketplace.
### Manual
@@ -31,6 +32,14 @@ Push it to Vercel.
Then, in your Vercel dashboard, under "Storage", create a new Blob store and connect it to the project.
Redeploy for the changes to take effect.
+## `@remotion/vercel` package
+
+import {TableOfContents} from './vercel/table-of-contents';
+
+The [`@remotion/vercel`](/docs/vercel/api) package provides a programmatic API for rendering Remotion videos on Vercel Sandbox. The template uses this package under the hood.
+
+<TableOfContents />
+
## Advantages
This is the easiest way to setup Remotion server-side rendering. You only need one Vercel account and connect a blob storage - then you just push to deploy.
@@ -52,10 +61,6 @@ For concurrency, the limit is 10 simultaneous renders on Hobby, and 2000 on Pro
For more details, see: [Vercel Sandbox pricing](https://vercel.com/docs/vercel-sandbox/pricing)
-## `@remotion/vercel` package
-
-The [`@remotion/vercel`](/docs/vercel/api) package provides a programmatic API for rendering Remotion videos on Vercel Sandbox. The template uses this package under the hood.
-
## Source Code
See the [template source code](https://github.com/remotion-dev/remotion/tree/main/packages/template-vercel) for implementation details.
diff --git a/packages/template-vercel/build.ts b/packages/template-vercel/build.ts
deleted file mode 100644
index 5f63982d0a..0000000000
--- a/packages/template-vercel/build.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import { $ } from "bun";
-
-await $`bunx next build`;
diff --git a/packages/template-vercel/bundle.ts b/packages/template-vercel/bundle.ts
deleted file mode 100644
index 292779efbb..0000000000
--- a/packages/template-vercel/bundle.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import { $ } from "bun";
-import { BUILD_DIR } from "./build-dir.mjs";
-
-await $`bunx remotion bundle --out-dir ./${BUILD_DIR}`;
diff --git a/packages/template-vercel/package.json b/packages/template-vercel/package.json
index e07a1904a4..a1a438fa74 100644
--- a/packages/template-vercel/package.json
+++ b/packages/template-vercel/package.json
@@ -4,11 +4,10 @@
"private": true,
"scripts": {
"dev": "next dev",
- "build": "bun build.ts",
+ "build": "next build",
"start": "next start",
"lint": "eslint .",
"remotion": "remotion studio",
- "bundle": "bun bundle.ts",
"create-snapshot": "bun create-snapshot.ts",
"render": "remotion render"
},
diff --git a/packages/vercel/bundle.ts b/packages/vercel/bundle.ts
index 3734d2b8e7..aeb98c4a1e 100644
--- a/packages/vercel/bundle.ts
+++ b/packages/vercel/bundle.ts
@@ -15,15 +15,30 @@ const scriptMap: Record<string, string> = {
'upload-blob-script': 'src/scripts/upload-blob.ts',
};
-const transpiler = new Bun.Transpiler({loader: 'ts'});
-
const generatedDir = path.join('src', 'generated');
mkdirSync(generatedDir, {recursive: true});
-for (const name of Object.keys(scriptMap)) {
+
+// Bundle each script separately so that `remotion` imports are inlined,
+// while `@remotion/renderer`, `@vercel/blob`, `fs`, etc. stay external.
+const scriptBundles: Record<string, string> = {};
+for (const [name, entrypoint] of Object.entries(scriptMap)) {
writeFileSync(
path.join(generatedDir, `${name}.d.ts`),
'export declare const script: string;\n',
);
+
+ const scriptOutput = await build({
+ entrypoints: [entrypoint],
+ target: 'node',
+ external: ['@remotion/renderer', '@vercel/blob', 'fs'],
+ });
+
+ if (!scriptOutput.success) {
+ console.log(scriptOutput.logs.join('\n'));
+ process.exit(1);
+ }
+
+ scriptBundles[name] = await scriptOutput.outputs[0].text();
}
const output = await build({
@@ -60,9 +75,7 @@ const output = await build({
build.onLoad(
{namespace: 'script-embed', filter: /.*/},
async (args) => {
- const file = scriptMap[args.path];
- const tsContent = await Bun.file(file).text();
- const jsContent = transpiler.transformSync(tsContent);
+ const jsContent = scriptBundles[args.path];
return {
contents: `export const script = ${JSON.stringify(jsContent)};`,
loader: 'ts',
diff --git a/packages/vercel/src/render-media-on-vercel.ts b/packages/vercel/src/render-media-on-vercel.ts
index 707bbeb5df..efebf3bf2b 100644
--- a/packages/vercel/src/render-media-on-vercel.ts
+++ b/packages/vercel/src/render-media-on-vercel.ts
@@ -141,6 +141,10 @@ export async function renderMediaOnVercel({
offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytes ?? null,
mediaCacheSizeInBytes: mediaCacheSizeInBytes ?? null,
offthreadVideoThreads: offthreadVideoThreads ?? null,
+ chromeMode: 'headless-shell',
+ browserExecutable: null,
+ binariesDirectory: null,
+ repro: false,
};
const renderCmd = await sandbox.runCommand({
diff --git a/packages/vercel/src/render-still-on-vercel.ts b/packages/vercel/src/render-still-on-vercel.ts
index 4a2ebacdc0..448a15cd31 100644
--- a/packages/vercel/src/render-still-on-vercel.ts
+++ b/packages/vercel/src/render-still-on-vercel.ts
@@ -66,6 +66,9 @@ export async function renderStillOnVercel({
mediaCacheSizeInBytes: mediaCacheSizeInBytes ?? null,
offthreadVideoThreads: offthreadVideoThreads ?? null,
licenseKey: licenseKey ?? null,
+ chromeMode: 'headless-shell',
+ browserExecutable: null,
+ binariesDirectory: null,
};
const renderCmd = await sandbox.runCommand({