🎥 Make videos programmatically with React
make typesafe
Jonny Burger9cc6bd9959ac
diff --git a/bun.lock b/bun.lockindex be3e26d73e..7f2a63ecc2 100644--- a/bun.lock+++ b/bun.lock@@ -2146,6 +2146,7 @@"@eslint/js": "9.38.0","@next/eslint-plugin-next": "15.1.6","@remotion/eslint-plugin": "workspace:*",+ "@remotion/renderer": "workspace:*","@tailwindcss/postcss": "4.1.1","@types/node": "20.12.14","@types/react": "19.2.7",diff --git a/packages/template-vercel/next.config.js b/packages/template-vercel/next.config.jsindex 5ae92554dd..e46dc0c74f 100644--- a/packages/template-vercel/next.config.js+++ b/packages/template-vercel/next.config.js@@ -5,7 +5,7 @@ const nextConfig = {reactStrictMode: true,// Include the Remotion bundle in the API routeoutputFileTracingIncludes: {- "/api/render": ["./" + BUILD_DIR + "/**/*", "./render.mjs"],+ "/api/render": ["./" + BUILD_DIR + "/**/*", "./render.ts"],},};diff --git a/packages/template-vercel/package.json b/packages/template-vercel/package.jsonindex b106161990..6c878da285 100644--- a/packages/template-vercel/package.json+++ b/packages/template-vercel/package.json@@ -32,6 +32,7 @@"devDependencies": {"@tailwindcss/postcss": "4.1.1","@remotion/eslint-plugin": "workspace:*",+ "@remotion/renderer": "workspace:*","@eslint/eslintrc": "3.1.0","@eslint/js": "9.38.0","@types/node": "20.12.14",diff --git a/packages/template-vercel/render.mjs b/packages/template-vercel/render.mjsdeleted file mode 100644index c7947454c2..0000000000--- a/packages/template-vercel/render.mjs+++ /dev/null@@ -1,31 +0,0 @@-import { renderMedia, selectComposition } from "@remotion/renderer";--const config = JSON.parse(process.argv[2]);--async function main() {- try {- const composition = await selectComposition({- serveUrl: config.serveUrl,- id: config.compositionId,- inputProps: config.inputProps,- });-- await renderMedia({- composition,- serveUrl: config.serveUrl,- codec: "h264",- outputLocation: "/tmp/video.mp4",- inputProps: config.inputProps,- onProgress: ({ progress }) => {- console.log(JSON.stringify({ type: "progress", progress }));- },- });-- console.log(JSON.stringify({ type: "done" }));- } catch (err) {- console.error(JSON.stringify({ type: "error", message: err.message }));- process.exit(1);- }-}--main();diff --git a/packages/template-vercel/render.ts b/packages/template-vercel/render.tsnew file mode 100644index 0000000000..36a90ed454--- /dev/null+++ b/packages/template-vercel/render.ts@@ -0,0 +1,36 @@+// This file is copied into the Vercel sandbox and executed with `node --strip-types`+import { renderMedia, selectComposition } from "@remotion/renderer";++export type RenderConfig = {+ serveUrl: string;+ compositionId: string;+ inputProps: Record<string, unknown>;+};++const config: RenderConfig = JSON.parse(process.argv[2]);++try {+ const composition = await selectComposition({+ serveUrl: config.serveUrl,+ id: config.compositionId,+ inputProps: config.inputProps,+ });++ await renderMedia({+ composition,+ serveUrl: config.serveUrl,+ codec: "h264",+ outputLocation: "/tmp/video.mp4",+ inputProps: config.inputProps,+ onProgress: ({ progress }) => {+ console.log(JSON.stringify({ type: "progress", progress }));+ },+ });++ console.log(JSON.stringify({ type: "done" }));+} catch (err) {+ console.error(+ JSON.stringify({ type: "error", message: (err as Error).message }),+ );+ process.exit(1);+}diff --git a/packages/template-vercel/src/app/api/render/helpers.ts b/packages/template-vercel/src/app/api/render/helpers.tsindex ae816c9b45..ddca94258c 100644--- a/packages/template-vercel/src/app/api/render/helpers.ts+++ b/packages/template-vercel/src/app/api/render/helpers.ts@@ -63,6 +63,6 @@ export function formatSSE(message: SSEMessage): string {}export async function getRenderScript(): Promise<Buffer> {- const renderScriptPath = path.join(process.cwd(), "render.mjs");+ const renderScriptPath = path.join(process.cwd(), "render.ts");return readFile(renderScriptPath);}diff --git a/packages/template-vercel/src/app/api/render/route.ts b/packages/template-vercel/src/app/api/render/route.tsindex 284da73bbe..6554dee9b3 100644--- a/packages/template-vercel/src/app/api/render/route.ts+++ b/packages/template-vercel/src/app/api/render/route.ts@@ -13,6 +13,7 @@ import {SSEMessage,} from "./helpers";import { BUILD_DIR } from "../../../../build-dir.mjs";+import type { RenderConfig } from "../../../../render";export async function POST(req: Request) {const encoder = new TextEncoder();@@ -120,26 +121,26 @@ export async function POST(req: Request) {await send({ type: "phase", phase: "Rendering video..." });// Use the local bundle copied to the sandbox- const serveUrl = "/vercel/sandbox/" + BUILD_DIR + "/index.html";+ const serveUrl = `/vercel/sandbox/${BUILD_DIR}`;const renderScript = await getRenderScript();await sandbox.writeFiles([{- path: "render.mjs",+ path: "render.ts",content: renderScript,},]);- const renderConfig = JSON.stringify({+ const renderConfig: RenderConfig = {serveUrl,compositionId: COMP_NAME,inputProps: body.inputProps,- });+ };// Run the render scriptconst renderCmd = await sandbox.runCommand({cmd: "node",- args: ["render.mjs", renderConfig],+ args: ["--strip-types", "render.ts", JSON.stringify(renderConfig)],detached: true,});