From 5f76b4bdee5e7859cd4a3ca8b63edb4f8182eb09 Mon Sep 17 00:00:00 2001 From: ASchwad Date: Sat, 29 Nov 2025 10:45:02 +0100 Subject: [PATCH 01/27] Copy nextjs-tailwind template --- bun.lock | 17 ++- .../template-code-generation/.env.example | 4 + packages/template-code-generation/.gitignore | 39 ++++++ packages/template-code-generation/.npmrc | 1 + packages/template-code-generation/.prettierrc | 5 + packages/template-code-generation/README.md | 88 +++++++++++++ packages/template-code-generation/config.mjs | 10 ++ packages/template-code-generation/deploy.mjs | 79 ++++++++++++ .../eslint.config.mjs | 53 ++++++++ .../template-code-generation/next.config.js | 6 + .../template-code-generation/package.json | 52 ++++++++ .../postcss.config.mjs | 6 + .../remotion.config.ts | 11 ++ .../src/app/api/lambda/progress/route.ts | 44 +++++++ .../src/app/api/lambda/render/route.ts | 56 ++++++++ .../src/app/favicon.ico | Bin 0 -> 25931 bytes .../src/app/layout.tsx | 25 ++++ .../template-code-generation/src/app/page.tsx | 65 ++++++++++ .../src/components/AlignEnd.tsx | 7 + .../src/components/Button.tsx | 39 ++++++ .../src/components/Container.tsx | 11 ++ .../src/components/DownloadButton.tsx | 56 ++++++++ .../src/components/Error.tsx | 25 ++++ .../src/components/Input.tsx | 24 ++++ .../src/components/ProgressBar.tsx | 22 ++++ .../src/components/RenderControls.tsx | 59 +++++++++ .../src/components/Spacing.tsx | 5 + .../src/components/Spinner.tsx | 46 +++++++ .../src/components/Tips.tsx | 53 ++++++++ .../src/helpers/api-response.ts | 36 ++++++ .../src/helpers/use-rendering.ts | 116 +++++++++++++++++ .../src/lambda/api.ts | 58 +++++++++ .../template-code-generation/src/lib/utils.ts | 6 + .../src/remotion/MyComp/Main.tsx | 58 +++++++++ .../src/remotion/MyComp/NextLogo.tsx | 122 ++++++++++++++++++ .../src/remotion/MyComp/Rings.tsx | 56 ++++++++ .../src/remotion/MyComp/TextFade.tsx | 45 +++++++ .../src/remotion/Root.tsx | 38 ++++++ .../src/remotion/index.ts | 5 + .../src/remotion/webpack-override.mjs | 8 ++ .../styles/global.css | 62 +++++++++ .../template-code-generation/tsconfig.json | 40 ++++++ .../types/constants.ts | 15 +++ .../template-code-generation/types/schema.ts | 27 ++++ packages/template-code-generation/vercel.json | 4 + 45 files changed, 1603 insertions(+), 1 deletion(-) create mode 100644 packages/template-code-generation/.env.example create mode 100644 packages/template-code-generation/.gitignore create mode 100644 packages/template-code-generation/.npmrc create mode 100644 packages/template-code-generation/.prettierrc create mode 100644 packages/template-code-generation/README.md create mode 100644 packages/template-code-generation/config.mjs create mode 100644 packages/template-code-generation/deploy.mjs create mode 100644 packages/template-code-generation/eslint.config.mjs create mode 100644 packages/template-code-generation/next.config.js create mode 100644 packages/template-code-generation/package.json create mode 100644 packages/template-code-generation/postcss.config.mjs create mode 100644 packages/template-code-generation/remotion.config.ts create mode 100644 packages/template-code-generation/src/app/api/lambda/progress/route.ts create mode 100644 packages/template-code-generation/src/app/api/lambda/render/route.ts create mode 100644 packages/template-code-generation/src/app/favicon.ico create mode 100644 packages/template-code-generation/src/app/layout.tsx create mode 100644 packages/template-code-generation/src/app/page.tsx create mode 100644 packages/template-code-generation/src/components/AlignEnd.tsx create mode 100644 packages/template-code-generation/src/components/Button.tsx create mode 100644 packages/template-code-generation/src/components/Container.tsx create mode 100644 packages/template-code-generation/src/components/DownloadButton.tsx create mode 100644 packages/template-code-generation/src/components/Error.tsx create mode 100644 packages/template-code-generation/src/components/Input.tsx create mode 100644 packages/template-code-generation/src/components/ProgressBar.tsx create mode 100644 packages/template-code-generation/src/components/RenderControls.tsx create mode 100644 packages/template-code-generation/src/components/Spacing.tsx create mode 100644 packages/template-code-generation/src/components/Spinner.tsx create mode 100644 packages/template-code-generation/src/components/Tips.tsx create mode 100644 packages/template-code-generation/src/helpers/api-response.ts create mode 100644 packages/template-code-generation/src/helpers/use-rendering.ts create mode 100644 packages/template-code-generation/src/lambda/api.ts create mode 100644 packages/template-code-generation/src/lib/utils.ts create mode 100644 packages/template-code-generation/src/remotion/MyComp/Main.tsx create mode 100644 packages/template-code-generation/src/remotion/MyComp/NextLogo.tsx create mode 100644 packages/template-code-generation/src/remotion/MyComp/Rings.tsx create mode 100644 packages/template-code-generation/src/remotion/MyComp/TextFade.tsx create mode 100644 packages/template-code-generation/src/remotion/Root.tsx create mode 100644 packages/template-code-generation/src/remotion/index.ts create mode 100644 packages/template-code-generation/src/remotion/webpack-override.mjs create mode 100644 packages/template-code-generation/styles/global.css create mode 100644 packages/template-code-generation/tsconfig.json create mode 100644 packages/template-code-generation/types/constants.ts create mode 100644 packages/template-code-generation/types/schema.ts create mode 100644 packages/template-code-generation/vercel.json diff --git a/bun.lock b/bun.lock index ddc3dc495f2..d22f86da5ac 100644 --- a/bun.lock +++ b/bun.lock @@ -1,6 +1,5 @@ { "lockfileVersion": 1, - "configVersion": 0, "workspaces": { "": { "name": "remotion-monorepo", @@ -95,6 +94,10 @@ "@remotion/bundler": "workspace:*", }, }, + "packages/bugs": { + "name": "bugs", + "version": "4.0.379", + }, "packages/bundler": { "name": "@remotion/bundler", "version": "4.0.379", @@ -195,6 +198,14 @@ "eslint": "catalog:", }, }, + "packages/cloudrun/container": { + "name": "cloud-run-render", + "version": "4.0.379", + "dependencies": { + "@google-cloud/functions-framework": "^3.1.3", + "@puppeteer/browsers": "^2.3.0", + }, + }, "packages/compositor": { "name": "@remotion/compositor", "version": "4.0.379", @@ -4293,6 +4304,8 @@ "buffer-from": ["buffer-from@1.1.2", "", {}, "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="], + "bugs": ["bugs@workspace:packages/bugs"], + "bun": ["bun@1.3.3", "", { "optionalDependencies": { "@oven/bun-darwin-aarch64": "1.3.3", "@oven/bun-darwin-x64": "1.3.3", "@oven/bun-darwin-x64-baseline": "1.3.3", "@oven/bun-linux-aarch64": "1.3.3", "@oven/bun-linux-aarch64-musl": "1.3.3", "@oven/bun-linux-x64": "1.3.3", "@oven/bun-linux-x64-baseline": "1.3.3", "@oven/bun-linux-x64-musl": "1.3.3", "@oven/bun-linux-x64-musl-baseline": "1.3.3", "@oven/bun-windows-x64": "1.3.3", "@oven/bun-windows-x64-baseline": "1.3.3" }, "os": [ "linux", "win32", "darwin", ], "cpu": [ "x64", "arm64", ], "bin": { "bun": "bin/bun.exe", "bunx": "bin/bunx.exe" } }, "sha512-2hJ4ocTZ634/Ptph4lysvO+LbbRZq8fzRvMwX0/CqaLBxrF2UB5D1LdMB8qGcdtCer4/VR9Bx5ORub0yn+yzmw=="], "bun-plugin-tailwind": ["bun-plugin-tailwind@0.1.2", "", { "peerDependencies": { "bun": ">=1.0.0" } }, "sha512-41jNC1tZRSK3s1o7pTNrLuQG8kL/0vR/JgiTmZAJ1eHwe0w5j6HFPKeqEk0WAD13jfrUC7+ULuewFBBCoADPpg=="], @@ -4393,6 +4406,8 @@ "clone-deep": ["clone-deep@4.0.1", "", { "dependencies": { "is-plain-object": "2.0.4", "kind-of": "6.0.3", "shallow-clone": "3.0.1" } }, "sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ=="], + "cloud-run-render": ["cloud-run-render@workspace:packages/cloudrun/container"], + "cloudevents": ["cloudevents@8.0.2", "", { "dependencies": { "ajv": "8.11.0", "ajv-formats": "2.1.1", "json-bigint": "1.0.0", "process": "0.11.10", "util": "0.12.5", "uuid": "8.3.2" } }, "sha512-93KKRR61D2NNE+2lg2HmLbl17beVTKpf1UYd/8BcXpuiDxbU2fb8gAfriSmVGmj1xX/Oh2t5Fh/xGOWFdu6F4A=="], "clsx": ["clsx@2.1.1", "", {}, "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA=="], diff --git a/packages/template-code-generation/.env.example b/packages/template-code-generation/.env.example new file mode 100644 index 00000000000..51ee435c392 --- /dev/null +++ b/packages/template-code-generation/.env.example @@ -0,0 +1,4 @@ +REMOTION_AWS_ACCESS_KEY_ID="" +REMOTION_AWS_SECRET_ACCESS_KEY="" + +OPENAI_API_KEY="" \ No newline at end of file diff --git a/packages/template-code-generation/.gitignore b/packages/template-code-generation/.gitignore new file mode 100644 index 00000000000..1efb618ffad --- /dev/null +++ b/packages/template-code-generation/.gitignore @@ -0,0 +1,39 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts +out/ +.env +build \ No newline at end of file diff --git a/packages/template-code-generation/.npmrc b/packages/template-code-generation/.npmrc new file mode 100644 index 00000000000..3e775efb0f4 --- /dev/null +++ b/packages/template-code-generation/.npmrc @@ -0,0 +1 @@ +auto-install-peers=true diff --git a/packages/template-code-generation/.prettierrc b/packages/template-code-generation/.prettierrc new file mode 100644 index 00000000000..37d50717489 --- /dev/null +++ b/packages/template-code-generation/.prettierrc @@ -0,0 +1,5 @@ +{ + "useTabs": false, + "bracketSpacing": true, + "tabWidth": 2 +} diff --git a/packages/template-code-generation/README.md b/packages/template-code-generation/README.md new file mode 100644 index 00000000000..f3ce3caad14 --- /dev/null +++ b/packages/template-code-generation/README.md @@ -0,0 +1,88 @@ + +
+
+ +This is a Next.js template for building programmatic video apps, with [`@remotion/player`](https://remotion.dev/player) and [`@remotion/lambda`](https://remotion.dev/lambda) built in. + +This template uses the Next.js App directory, with TailwindCSS. There is a [Non-TailwindCSS version](https://github.com/remotion-dev/template-next-app-dir), and a [Pages directory version](https://github.com/remotion-dev/template-next-pages-dir) of this template available. + + + +## Getting Started + +[Use this template](https://github.com/new?template_name=template-next-app-dir-tailwind&template_owner=remotion-dev) to clone it into your GitHub account. Run + +``` +npm i +``` + +afterwards. Alternatively, use this command to scaffold a project: + +``` +npx create-video@latest --next-tailwind +``` + +## Commands + +Start the Next.js dev server: + +``` +npm run dev +``` + +Open the Remotion Studio: + +``` +npx remotion studio +``` + +Render a video locally: + +``` +npx remotion render +``` + +Upgrade Remotion: + +``` +npx remotion upgrade +``` + +The following script will set up your Remotion Bundle and Lambda function on AWS: + +``` +node deploy.mjs +``` + +You should run this script after: + +- changing the video template +- changing `config.mjs` +- upgrading Remotion to a newer version + +## Set up rendering on AWS Lambda + +This template supports rendering the videos via [Remotion Lambda](https://remotion.dev/lambda). + +1. Copy the `.env.example` file to `.env` and fill in the values. + Complete the [Lambda setup guide](https://www.remotion.dev/docs/lambda/setup) to get your AWS credentials. + +1. Edit the `config.mjs` file to your desired Lambda settings. + +1. Run `node deploy.mjs` to deploy your Lambda function and Remotion Bundle. + +## Docs + +Get started with Remotion by reading the [fundamentals page](https://www.remotion.dev/docs/the-fundamentals). + +## Help + +We provide help on our [Discord server](https://remotion.dev/discord). + +## Issues + +Found an issue with Remotion? [File an issue here](https://remotion.dev/issue). + +## License + +Note that for some entities a company license is needed. [Read the terms here](https://github.com/remotion-dev/remotion/blob/main/LICENSE.md). diff --git a/packages/template-code-generation/config.mjs b/packages/template-code-generation/config.mjs new file mode 100644 index 00000000000..b18ed95152c --- /dev/null +++ b/packages/template-code-generation/config.mjs @@ -0,0 +1,10 @@ +/** + * Use autocomplete to get a list of available regions. + * @type {import('@remotion/lambda').AwsRegion} + */ +export const REGION = "us-east-1"; + +export const SITE_NAME = "my-next-app"; +export const RAM = 3009; +export const DISK = 10240; +export const TIMEOUT = 240; diff --git a/packages/template-code-generation/deploy.mjs b/packages/template-code-generation/deploy.mjs new file mode 100644 index 00000000000..2dcc0bd8fe9 --- /dev/null +++ b/packages/template-code-generation/deploy.mjs @@ -0,0 +1,79 @@ +import { + deployFunction, + deploySite, + getOrCreateBucket, +} from "@remotion/lambda"; +import dotenv from "dotenv"; +import path from "path"; +import { DISK, RAM, REGION, SITE_NAME, TIMEOUT } from "./config.mjs"; +import { webpackOverride } from "./src/remotion/webpack-override.mjs"; + +console.log("Selected region:", REGION); +dotenv.config(); + +if (!process.env.AWS_ACCESS_KEY_ID && !process.env.REMOTION_AWS_ACCESS_KEY_ID) { + console.log( + 'The environment variable "REMOTION_AWS_ACCESS_KEY_ID" is not set.', + ); + console.log("Lambda renders were not set up."); + console.log( + "Complete the Lambda setup: at https://www.remotion.dev/docs/lambda/setup", + ); + process.exit(0); +} +if ( + !process.env.AWS_SECRET_ACCESS_KEY && + !process.env.REMOTION_AWS_SECRET_ACCESS_KEY +) { + console.log( + 'The environment variable "REMOTION_REMOTION_AWS_SECRET_ACCESS_KEY" is not set.', + ); + console.log("Lambda renders were not set up."); + console.log( + "Complete the Lambda setup: at https://www.remotion.dev/docs/lambda/setup", + ); + process.exit(0); +} + +process.stdout.write("Deploying Lambda function... "); + +const { functionName, alreadyExisted: functionAlreadyExisted } = + await deployFunction({ + createCloudWatchLogGroup: true, + memorySizeInMb: RAM, + region: REGION, + timeoutInSeconds: TIMEOUT, + diskSizeInMb: DISK, + }); +console.log( + functionName, + functionAlreadyExisted ? "(already existed)" : "(created)", +); + +process.stdout.write("Ensuring bucket... "); +const { bucketName, alreadyExisted: bucketAlreadyExisted } = + await getOrCreateBucket({ + region: REGION, + }); +console.log( + bucketName, + bucketAlreadyExisted ? "(already existed)" : "(created)", +); + +process.stdout.write("Deploying site... "); +const { siteName } = await deploySite({ + bucketName, + entryPoint: path.join(process.cwd(), "src", "remotion", "index.ts"), + siteName: SITE_NAME, + region: REGION, + options: { webpackOverride }, +}); + +console.log(siteName); + +console.log(); +console.log("You now have everything you need to render videos!"); +console.log("Re-run this command when:"); +console.log(" 1) you changed the video template"); +console.log(" 2) you changed config.mjs"); +console.log(" 3) you upgraded Remotion to a newer version"); diff --git a/packages/template-code-generation/eslint.config.mjs b/packages/template-code-generation/eslint.config.mjs new file mode 100644 index 00000000000..b37f42b2024 --- /dev/null +++ b/packages/template-code-generation/eslint.config.mjs @@ -0,0 +1,53 @@ +import js from "@eslint/js"; +import nextPlugin from "@next/eslint-plugin-next"; +import remotion from "@remotion/eslint-plugin"; +import tseslint from "typescript-eslint"; + +// Build Next.js recommended rules and an "off" map for overrides +const nextRecommended = nextPlugin.configs.recommended ?? { rules: {} }; +const nextRecommendedRules = nextRecommended.rules ?? {}; +const offNextRules = Object.fromEntries( + Object.keys(nextRecommendedRules).map((k) => [k, "off"]), +); + +export default [ + // Global ignores + { + ignores: [ + "node_modules/**", + ".next/**", + "out/**", + "build/**", + "next-env.d.ts", + "next.config.js", + "deploy.mjs", + ], + }, + // Base JS recommended + js.configs.recommended, + // TypeScript recommended (non type-checked for speed/simplicity) + ...tseslint.configs.recommended, + // Next.js recommended rules applied to app code + { + files: ["**/*.{js,jsx,ts,tsx}"], + plugins: { "@next/next": nextPlugin }, + rules: { + ...nextRecommendedRules, + }, + }, + // Remotion rules applied only to remotion files + { + files: ["src/remotion/**"], + ...remotion.flatPlugin, + rules: { + ...remotion.flatPlugin.rules, + }, + }, + // Disable all Next.js rules within remotion files + { + files: ["src/remotion/**"], + rules: { + ...offNextRules, + }, + }, +]; diff --git a/packages/template-code-generation/next.config.js b/packages/template-code-generation/next.config.js new file mode 100644 index 00000000000..91ef62f0db5 --- /dev/null +++ b/packages/template-code-generation/next.config.js @@ -0,0 +1,6 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + reactStrictMode: true, +}; + +module.exports = nextConfig; diff --git a/packages/template-code-generation/package.json b/packages/template-code-generation/package.json new file mode 100644 index 00000000000..624663185b3 --- /dev/null +++ b/packages/template-code-generation/package.json @@ -0,0 +1,52 @@ +{ + "name": "template-code-generation", + "version": "0.1.0", + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start", + "lint": "eslint .", + "remotion": "remotion studio", + "render": "remotion render", + "deploy": "node deploy.mjs" + }, + "dependencies": { + "@remotion/bundler": "workspace:*", + "@remotion/cli": "workspace:*", + "@remotion/google-fonts": "workspace:*", + "@remotion/lambda": "workspace:*", + "@remotion/paths": "workspace:*", + "@remotion/player": "workspace:*", + "@remotion/shapes": "workspace:*", + "@remotion/tailwind-v4": "workspace:*", + "clsx": "2.1.1", + "next": "16.0.0", + "react": "19.0.0", + "react-dom": "19.0.0", + "remotion": "workspace:*", + "tailwind-merge": "3.0.1", + "zod": "3.22.3" + }, + "devDependencies": { + "@tailwindcss/postcss": "4.1.1", + "@remotion/eslint-plugin": "workspace:*", + "@eslint/eslintrc": "3.1.0", + "@eslint/js": "9.38.0", + "@types/node": "20.12.14", + "@types/react": "19.0.0", + "@types/react-dom": "19.0.0", + "@types/web": "0.0.166", + "autoprefixer": "10.4.20", + "dotenv": "16.0.3", + "eslint": "9.19.0", + "@next/eslint-plugin-next": "15.1.6", + "eslint-config-next": "15.1.6", + "@typescript-eslint/eslint-plugin": "8.46.0", + "@typescript-eslint/parser": "8.46.0", + "postcss": "8.4.47", + "prettier": "3.6.0", + "tailwindcss": "4.0.3", + "typescript": "5.8.2", + "typescript-eslint": "8.46.0" + } +} diff --git a/packages/template-code-generation/postcss.config.mjs b/packages/template-code-generation/postcss.config.mjs new file mode 100644 index 00000000000..7059fe95adc --- /dev/null +++ b/packages/template-code-generation/postcss.config.mjs @@ -0,0 +1,6 @@ +const config = { + plugins: { + "@tailwindcss/postcss": {}, + }, +}; +export default config; diff --git a/packages/template-code-generation/remotion.config.ts b/packages/template-code-generation/remotion.config.ts new file mode 100644 index 00000000000..cbf7520d9b4 --- /dev/null +++ b/packages/template-code-generation/remotion.config.ts @@ -0,0 +1,11 @@ +// See all configuration options: https://remotion.dev/docs/config +// Each option also is available as a CLI flag: https://remotion.dev/docs/cli + +// Note: When using the Node.JS APIs, the config file doesn't apply. Instead, pass options directly to the APIs + +import { Config } from "@remotion/cli/config"; +import { webpackOverride } from "./src/remotion/webpack-override.mjs"; + +Config.setVideoImageFormat("jpeg"); + +Config.overrideWebpackConfig(webpackOverride); diff --git a/packages/template-code-generation/src/app/api/lambda/progress/route.ts b/packages/template-code-generation/src/app/api/lambda/progress/route.ts new file mode 100644 index 00000000000..7f6fbcfcba4 --- /dev/null +++ b/packages/template-code-generation/src/app/api/lambda/progress/route.ts @@ -0,0 +1,44 @@ +import { + speculateFunctionName, + AwsRegion, + getRenderProgress, +} from "@remotion/lambda/client"; +import { DISK, RAM, REGION, TIMEOUT } from "../../../../../config.mjs"; +import { ProgressResponse, ProgressRequest } from "../../../../../types/schema"; +import { executeApi } from "../../../../helpers/api-response"; + +export const POST = executeApi( + ProgressRequest, + async (req, body) => { + const renderProgress = await getRenderProgress({ + bucketName: body.bucketName, + functionName: speculateFunctionName({ + diskSizeInMb: DISK, + memorySizeInMb: RAM, + timeoutInSeconds: TIMEOUT, + }), + region: REGION as AwsRegion, + renderId: body.id, + }); + + if (renderProgress.fatalErrorEncountered) { + return { + type: "error", + message: renderProgress.errors[0].message, + }; + } + + if (renderProgress.done) { + return { + type: "done", + url: renderProgress.outputFile as string, + size: renderProgress.outputSizeInBytes as number, + }; + } + + return { + type: "progress", + progress: Math.max(0.03, renderProgress.overallProgress), + }; + }, +); diff --git a/packages/template-code-generation/src/app/api/lambda/render/route.ts b/packages/template-code-generation/src/app/api/lambda/render/route.ts new file mode 100644 index 00000000000..822349c0b4e --- /dev/null +++ b/packages/template-code-generation/src/app/api/lambda/render/route.ts @@ -0,0 +1,56 @@ +import { AwsRegion, RenderMediaOnLambdaOutput } from "@remotion/lambda/client"; +import { + renderMediaOnLambda, + speculateFunctionName, +} from "@remotion/lambda/client"; +import { + DISK, + RAM, + REGION, + SITE_NAME, + TIMEOUT, +} from "../../../../../config.mjs"; +import { RenderRequest } from "../../../../../types/schema"; +import { executeApi } from "../../../../helpers/api-response"; + +export const POST = executeApi( + RenderRequest, + async (req, body) => { + if ( + !process.env.AWS_ACCESS_KEY_ID && + !process.env.REMOTION_AWS_ACCESS_KEY_ID + ) { + throw new TypeError( + "Set up Remotion Lambda to render videos. See the README.md for how to do so.", + ); + } + if ( + !process.env.AWS_SECRET_ACCESS_KEY && + !process.env.REMOTION_AWS_SECRET_ACCESS_KEY + ) { + throw new TypeError( + "The environment variable REMOTION_AWS_SECRET_ACCESS_KEY is missing. Add it to your .env file.", + ); + } + + const result = await renderMediaOnLambda({ + codec: "h264", + functionName: speculateFunctionName({ + diskSizeInMb: DISK, + memorySizeInMb: RAM, + timeoutInSeconds: TIMEOUT, + }), + region: REGION as AwsRegion, + serveUrl: SITE_NAME, + composition: body.id, + inputProps: body.inputProps, + framesPerLambda: 10, + downloadBehavior: { + type: "download", + fileName: "video.mp4", + }, + }); + + return result; + }, +); diff --git a/packages/template-code-generation/src/app/favicon.ico b/packages/template-code-generation/src/app/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..718d6fea4835ec2d246af9800eddb7ffb276240c GIT binary patch literal 25931 zcmeHv30#a{`}aL_*G&7qml|y<+KVaDM2m#dVr!KsA!#An?kSQM(q<_dDNCpjEux83 zLb9Z^XxbDl(w>%i@8hT6>)&Gu{h#Oeyszu?xtw#Zb1mO{pgX9699l+Qppw7jXaYf~-84xW z)w4x8?=youko|}Vr~(D$UXIbiXABHh`p1?nn8Po~fxRJv}|0e(BPs|G`(TT%kKVJAdg5*Z|x0leQq0 zkdUBvb#>9F()jo|T~kx@OM8$9wzs~t2l;K=woNssA3l6|sx2r3+kdfVW@e^8e*E}v zA1y5{bRi+3Z`uD3{F7LgFJDdvm;nJilkzDku>BwXH(8ItVCXk*-lSJnR?-2UN%hJ){&rlvg`CDTj z)Bzo!3v7Ou#83zEDEFcKt(f1E0~=rqeEbTnMvWR#{+9pg%7G8y>u1OVRUSoox-ovF z2Ydma(;=YuBY(eI|04{hXzZD6_f(v~H;C~y5=DhAC{MMS>2fm~1H_t2$56pc$NH8( z5bH|<)71dV-_oCHIrzrT`2s-5w_+2CM0$95I6X8p^r!gHp+j_gd;9O<1~CEQQGS8) zS9Qh3#p&J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9{fMPWo%4wYDG~BZ18BD+}h|GQKc-g^{++3MY>}W_uq7jGHx{mwE9fZiPCoxN$+7 zrODGGJrOkcPQUB(FD5aoS4g~7#6NR^ma7-!>mHuJfY5kTe6PpNNKC9GGRiu^L31uG z$7v`*JknQHsYB!Tm_W{a32TM099djW%5e+j0Ve_ct}IM>XLF1Ap+YvcrLV=|CKo6S zb+9Nl3_YdKP6%Cxy@6TxZ>;4&nTneadr z_ES90ydCev)LV!dN=#(*f}|ZORFdvkYBni^aLbUk>BajeWIOcmHP#8S)*2U~QKI%S zyrLmtPqb&TphJ;>yAxri#;{uyk`JJqODDw%(Z=2`1uc}br^V%>j!gS)D*q*f_-qf8&D;W1dJgQMlaH5er zN2U<%Smb7==vE}dDI8K7cKz!vs^73o9f>2sgiTzWcwY|BMYHH5%Vn7#kiw&eItCqa zIkR2~Q}>X=Ar8W|^Ms41Fm8o6IB2_j60eOeBB1Br!boW7JnoeX6Gs)?7rW0^5psc- zjS16yb>dFn>KPOF;imD}e!enuIniFzv}n$m2#gCCv4jM#ArwlzZ$7@9&XkFxZ4n!V zj3dyiwW4Ki2QG{@i>yuZXQizw_OkZI^-3otXC{!(lUpJF33gI60ak;Uqitp74|B6I zgg{b=Iz}WkhCGj1M=hu4#Aw173YxIVbISaoc z-nLZC*6Tgivd5V`K%GxhBsp@SUU60-rfc$=wb>zdJzXS&-5(NRRodFk;Kxk!S(O(a0e7oY=E( zAyS;Ow?6Q&XA+cnkCb{28_1N8H#?J!*$MmIwLq^*T_9-z^&UE@A(z9oGYtFy6EZef LrJugUA?W`A8`#=m literal 0 HcmV?d00001 diff --git a/packages/template-code-generation/src/app/layout.tsx b/packages/template-code-generation/src/app/layout.tsx new file mode 100644 index 00000000000..e19d2dc5cb2 --- /dev/null +++ b/packages/template-code-generation/src/app/layout.tsx @@ -0,0 +1,25 @@ +import "../../styles/global.css"; +import { Metadata, Viewport } from "next"; + +export const metadata: Metadata = { + title: "Remotion and Next.js", + description: "Remotion and Next.js", +}; + +export const viewport: Viewport = { + width: "device-width", + initialScale: 1, + maximumScale: 1, +}; + +export default function RootLayout({ + children, +}: { + children: React.ReactNode; +}) { + return ( + + {children} + + ); +} diff --git a/packages/template-code-generation/src/app/page.tsx b/packages/template-code-generation/src/app/page.tsx new file mode 100644 index 00000000000..1f92cb246af --- /dev/null +++ b/packages/template-code-generation/src/app/page.tsx @@ -0,0 +1,65 @@ +"use client"; + +import { Player } from "@remotion/player"; +import type { NextPage } from "next"; +import { useMemo, useState } from "react"; +import { z } from "zod"; +import { + defaultMyCompProps, + CompositionProps, + DURATION_IN_FRAMES, + VIDEO_FPS, + VIDEO_HEIGHT, + VIDEO_WIDTH, +} from "../../types/constants"; +import { RenderControls } from "../components/RenderControls"; +import { Spacing } from "../components/Spacing"; +import { Tips } from "../components/Tips"; +import { Main } from "../remotion/MyComp/Main"; + +const Home: NextPage = () => { + const [text, setText] = useState(defaultMyCompProps.title); + + const inputProps: z.infer = useMemo(() => { + return { + title: text, + }; + }, [text]); + + return ( +
+
+
+ +
+ + + + + + +
+
+ ); +}; + +export default Home; diff --git a/packages/template-code-generation/src/components/AlignEnd.tsx b/packages/template-code-generation/src/components/AlignEnd.tsx new file mode 100644 index 00000000000..7ff7ad53bfa --- /dev/null +++ b/packages/template-code-generation/src/components/AlignEnd.tsx @@ -0,0 +1,7 @@ +import React from "react"; + +export const AlignEnd: React.FC<{ + children: React.ReactNode; +}> = ({ children }) => { + return
{children}
; +}; diff --git a/packages/template-code-generation/src/components/Button.tsx b/packages/template-code-generation/src/components/Button.tsx new file mode 100644 index 00000000000..4f924f335df --- /dev/null +++ b/packages/template-code-generation/src/components/Button.tsx @@ -0,0 +1,39 @@ +import React, { forwardRef } from "react"; +import { Spacing } from "./Spacing"; +import { Spinner } from "./Spinner"; +import { cn } from "../lib/utils"; + +const ButtonForward: React.ForwardRefRenderFunction< + HTMLButtonElement, + { + onClick?: () => void; + disabled?: boolean; + children: React.ReactNode; + loading?: boolean; + secondary?: boolean; + } +> = ({ onClick, disabled, children, loading, secondary }, ref) => { + return ( + + ); +}; + +export const Button = forwardRef(ButtonForward); diff --git a/packages/template-code-generation/src/components/Container.tsx b/packages/template-code-generation/src/components/Container.tsx new file mode 100644 index 00000000000..19cbcb59e53 --- /dev/null +++ b/packages/template-code-generation/src/components/Container.tsx @@ -0,0 +1,11 @@ +import React from "react"; + +export const InputContainer: React.FC<{ + children: React.ReactNode; +}> = ({ children }) => { + return ( +
+ {children} +
+ ); +}; diff --git a/packages/template-code-generation/src/components/DownloadButton.tsx b/packages/template-code-generation/src/components/DownloadButton.tsx new file mode 100644 index 00000000000..9ccff26b803 --- /dev/null +++ b/packages/template-code-generation/src/components/DownloadButton.tsx @@ -0,0 +1,56 @@ +import React from "react"; +import { State } from "../helpers/use-rendering"; +import { Button } from "./Button"; +import { Spacing } from "./Spacing"; + +const Megabytes: React.FC<{ + sizeInBytes: number; +}> = ({ sizeInBytes }) => { + const megabytes = Intl.NumberFormat("en", { + notation: "compact", + style: "unit", + unit: "byte", + unitDisplay: "narrow", + }).format(sizeInBytes); + return {megabytes}; +}; + +export const DownloadButton: React.FC<{ + state: State; + undo: () => void; +}> = ({ state, undo }) => { + if (state.status === "rendering") { + return ; + } + + if (state.status !== "done") { + throw new Error("Download button should not be rendered when not done"); + } + + return ( + + ); +}; + +const UndoIcon: React.FC = () => { + return ( + + + + ); +}; diff --git a/packages/template-code-generation/src/components/Error.tsx b/packages/template-code-generation/src/components/Error.tsx new file mode 100644 index 00000000000..28020e53c2a --- /dev/null +++ b/packages/template-code-generation/src/components/Error.tsx @@ -0,0 +1,25 @@ +import React from "react"; + +export const ErrorComp: React.FC<{ + message: string; +}> = ({ message }) => { + return ( +
+ + + + + + Error: {message} +
+ ); +}; diff --git a/packages/template-code-generation/src/components/Input.tsx b/packages/template-code-generation/src/components/Input.tsx new file mode 100644 index 00000000000..d6dcc0434d6 --- /dev/null +++ b/packages/template-code-generation/src/components/Input.tsx @@ -0,0 +1,24 @@ +import React, { useCallback } from "react"; + +export const Input: React.FC<{ + text: string; + setText: React.Dispatch>; + disabled?: boolean; +}> = ({ text, setText, disabled }) => { + const onChange: React.ChangeEventHandler = useCallback( + (e) => { + setText(e.currentTarget.value); + }, + [setText], + ); + + return ( + + ); +}; diff --git a/packages/template-code-generation/src/components/ProgressBar.tsx b/packages/template-code-generation/src/components/ProgressBar.tsx new file mode 100644 index 00000000000..a4c5886df74 --- /dev/null +++ b/packages/template-code-generation/src/components/ProgressBar.tsx @@ -0,0 +1,22 @@ +import React, { useMemo } from "react"; + +export const ProgressBar: React.FC<{ + progress: number; +}> = ({ progress }) => { + const fill: React.CSSProperties = useMemo(() => { + return { + width: `${progress * 100}%`, + }; + }, [progress]); + + return ( +
+
+
+
+
+ ); +}; diff --git a/packages/template-code-generation/src/components/RenderControls.tsx b/packages/template-code-generation/src/components/RenderControls.tsx new file mode 100644 index 00000000000..37113100954 --- /dev/null +++ b/packages/template-code-generation/src/components/RenderControls.tsx @@ -0,0 +1,59 @@ +import { z } from "zod"; +import { AlignEnd } from "./AlignEnd"; +import { Button } from "./Button"; +import { InputContainer } from "./Container"; +import { DownloadButton } from "./DownloadButton"; +import { ErrorComp } from "./Error"; +import { Input } from "./Input"; +import { ProgressBar } from "./ProgressBar"; +import { Spacing } from "./Spacing"; +import { COMP_NAME, CompositionProps } from "../../types/constants"; +import { useRendering } from "../helpers/use-rendering"; + +export const RenderControls: React.FC<{ + text: string; + setText: React.Dispatch>; + inputProps: z.infer; +}> = ({ text, setText, inputProps }) => { + const { renderMedia, state, undo } = useRendering(COMP_NAME, inputProps); + + return ( + + {state.status === "init" || + state.status === "invoking" || + state.status === "error" ? ( + <> + + + + + + {state.status === "error" ? ( + + ) : null} + + ) : null} + {state.status === "rendering" || state.status === "done" ? ( + <> + + + + + + + ) : null} + + ); +}; diff --git a/packages/template-code-generation/src/components/Spacing.tsx b/packages/template-code-generation/src/components/Spacing.tsx new file mode 100644 index 00000000000..c901cfdadb6 --- /dev/null +++ b/packages/template-code-generation/src/components/Spacing.tsx @@ -0,0 +1,5 @@ +import React from "react"; + +export const Spacing: React.FC = () => { + return
; +}; diff --git a/packages/template-code-generation/src/components/Spinner.tsx b/packages/template-code-generation/src/components/Spinner.tsx new file mode 100644 index 00000000000..405f2260c1a --- /dev/null +++ b/packages/template-code-generation/src/components/Spinner.tsx @@ -0,0 +1,46 @@ +import React, { useMemo } from "react"; +import { makeRect } from "@remotion/shapes"; +import { translatePath } from "@remotion/paths"; + +const viewBox = 100; +const lines = 12; +const width = viewBox * 0.08; + +const { path } = makeRect({ + height: viewBox * 0.24, + width, + cornerRadius: width / 2, +}); + +const translated = translatePath(path, viewBox / 2 - width / 2, viewBox * 0.03); + +export const Spinner: React.FC<{ + size: number; +}> = ({ size }) => { + const style = useMemo(() => { + return { + width: size, + height: size, + }; + }, [size]); + + return ( + + {new Array(lines).fill(true).map((_, index) => { + return ( + + ); + })} + + ); +}; diff --git a/packages/template-code-generation/src/components/Tips.tsx b/packages/template-code-generation/src/components/Tips.tsx new file mode 100644 index 00000000000..4e0d16cf4eb --- /dev/null +++ b/packages/template-code-generation/src/components/Tips.tsx @@ -0,0 +1,53 @@ +import React from "react"; + +const Tip: React.FC<{ + title: React.ReactNode; + description: React.ReactNode; + href: string; +}> = ({ title, description, href }) => { + return ( + +
+
+

{title}

+
+ + + +
+

+ {description} +

+
+
+ ); +}; + +export const Tips: React.FC = () => { + return ( +
+ + + +
+ ); +}; diff --git a/packages/template-code-generation/src/helpers/api-response.ts b/packages/template-code-generation/src/helpers/api-response.ts new file mode 100644 index 00000000000..d4da4ce7862 --- /dev/null +++ b/packages/template-code-generation/src/helpers/api-response.ts @@ -0,0 +1,36 @@ +import { NextResponse } from "next/server"; +import { z, ZodType } from "zod"; + +export type ApiResponse = + | { + type: "error"; + message: string; + } + | { + type: "success"; + data: Res; + }; + +export const executeApi = + ( + schema: Req, + handler: (req: Request, body: z.infer) => Promise, + ) => + async (req: Request) => { + try { + const payload = await req.json(); + const parsed = schema.parse(payload); + const data = await handler(req, parsed); + return NextResponse.json({ + type: "success", + data: data, + }); + } catch (err) { + return NextResponse.json( + { type: "error", message: (err as Error).message }, + { + status: 500, + }, + ); + } + }; diff --git a/packages/template-code-generation/src/helpers/use-rendering.ts b/packages/template-code-generation/src/helpers/use-rendering.ts new file mode 100644 index 00000000000..ff7c29efdb0 --- /dev/null +++ b/packages/template-code-generation/src/helpers/use-rendering.ts @@ -0,0 +1,116 @@ +import { z } from "zod"; +import { useCallback, useMemo, useState } from "react"; +import { getProgress, renderVideo } from "../lambda/api"; +import { CompositionProps } from "../../types/constants"; + +export type State = + | { + status: "init"; + } + | { + status: "invoking"; + } + | { + renderId: string; + bucketName: string; + progress: number; + status: "rendering"; + } + | { + renderId: string | null; + status: "error"; + error: Error; + } + | { + url: string; + size: number; + status: "done"; + }; + +const wait = async (milliSeconds: number) => { + await new Promise((resolve) => { + setTimeout(() => { + resolve(); + }, milliSeconds); + }); +}; + +export const useRendering = ( + id: string, + inputProps: z.infer, +) => { + const [state, setState] = useState({ + status: "init", + }); + + const renderMedia = useCallback(async () => { + setState({ + status: "invoking", + }); + try { + const { renderId, bucketName } = await renderVideo({ id, inputProps }); + setState({ + status: "rendering", + progress: 0, + renderId: renderId, + bucketName: bucketName, + }); + + let pending = true; + + while (pending) { + const result = await getProgress({ + id: renderId, + bucketName: bucketName, + }); + switch (result.type) { + case "error": { + setState({ + status: "error", + renderId: renderId, + error: new Error(result.message), + }); + pending = false; + break; + } + case "done": { + setState({ + size: result.size, + url: result.url, + status: "done", + }); + pending = false; + break; + } + case "progress": { + setState({ + status: "rendering", + bucketName: bucketName, + progress: result.progress, + renderId: renderId, + }); + await wait(1000); + } + } + } + } catch (err) { + setState({ + status: "error", + error: err as Error, + renderId: null, + }); + } + }, [id, inputProps]); + + const undo = useCallback(() => { + setState({ status: "init" }); + }, []); + + return useMemo(() => { + return { + renderMedia, + state, + undo, + }; + }, [renderMedia, state, undo]); +}; diff --git a/packages/template-code-generation/src/lambda/api.ts b/packages/template-code-generation/src/lambda/api.ts new file mode 100644 index 00000000000..f1182d95777 --- /dev/null +++ b/packages/template-code-generation/src/lambda/api.ts @@ -0,0 +1,58 @@ +import { z } from "zod"; +import type { RenderMediaOnLambdaOutput } from "@remotion/lambda/client"; +import { + ProgressRequest, + ProgressResponse, + RenderRequest, +} from "../../types/schema"; +import { CompositionProps } from "../../types/constants"; +import { ApiResponse } from "../helpers/api-response"; + +const makeRequest = async ( + endpoint: string, + body: unknown, +): Promise => { + const result = await fetch(endpoint, { + method: "post", + body: JSON.stringify(body), + headers: { + "content-type": "application/json", + }, + }); + const json = (await result.json()) as ApiResponse; + if (json.type === "error") { + throw new Error(json.message); + } + + return json.data; +}; + +export const renderVideo = async ({ + id, + inputProps, +}: { + id: string; + inputProps: z.infer; +}) => { + const body: z.infer = { + id, + inputProps, + }; + + return makeRequest("/api/lambda/render", body); +}; + +export const getProgress = async ({ + id, + bucketName, +}: { + id: string; + bucketName: string; +}) => { + const body: z.infer = { + id, + bucketName, + }; + + return makeRequest("/api/lambda/progress", body); +}; diff --git a/packages/template-code-generation/src/lib/utils.ts b/packages/template-code-generation/src/lib/utils.ts new file mode 100644 index 00000000000..a5ef193506d --- /dev/null +++ b/packages/template-code-generation/src/lib/utils.ts @@ -0,0 +1,6 @@ +import { clsx, type ClassValue } from "clsx"; +import { twMerge } from "tailwind-merge"; + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)); +} diff --git a/packages/template-code-generation/src/remotion/MyComp/Main.tsx b/packages/template-code-generation/src/remotion/MyComp/Main.tsx new file mode 100644 index 00000000000..cf23037a594 --- /dev/null +++ b/packages/template-code-generation/src/remotion/MyComp/Main.tsx @@ -0,0 +1,58 @@ +import { z } from "zod"; +import { + AbsoluteFill, + Sequence, + spring, + useCurrentFrame, + useVideoConfig, +} from "remotion"; +import { CompositionProps } from "../../../types/constants"; +import { NextLogo } from "./NextLogo"; +import { loadFont, fontFamily } from "@remotion/google-fonts/Inter"; +import { Rings } from "./Rings"; +import { TextFade } from "./TextFade"; + +loadFont("normal", { + subsets: ["latin"], + weights: ["400", "700"], +}); +export const Main = ({ title }: z.infer) => { + const frame = useCurrentFrame(); + const { fps } = useVideoConfig(); + + const transitionStart = 2 * fps; + const transitionDuration = 1 * fps; + + const logoOut = spring({ + fps, + frame, + config: { + damping: 200, + }, + durationInFrames: transitionDuration, + delay: transitionStart, + }); + + return ( + + + + + + + + + +

+ {title} +

+
+
+
+ ); +}; diff --git a/packages/template-code-generation/src/remotion/MyComp/NextLogo.tsx b/packages/template-code-generation/src/remotion/MyComp/NextLogo.tsx new file mode 100644 index 00000000000..b7f87f6bf29 --- /dev/null +++ b/packages/template-code-generation/src/remotion/MyComp/NextLogo.tsx @@ -0,0 +1,122 @@ +import { evolvePath } from "@remotion/paths"; +import React, { useMemo } from "react"; +import { interpolate, spring, useCurrentFrame, useVideoConfig } from "remotion"; + +const nStroke = + "M149.508 157.52L69.142 54H54V125.97H66.1136V69.3836L139.999 164.845C143.333 162.614 146.509 160.165 149.508 157.52Z"; + +export const NextLogo: React.FC<{ + outProgress: number; +}> = ({ outProgress }) => { + const { fps } = useVideoConfig(); + const frame = useCurrentFrame(); + + const evolve1 = spring({ + fps, + frame, + config: { + damping: 200, + }, + }); + const evolve2 = spring({ + fps, + frame: frame - 15, + config: { + damping: 200, + }, + }); + const evolve3 = spring({ + fps, + frame: frame - 30, + config: { + damping: 200, + mass: 3, + }, + durationInFrames: 30, + }); + + const style: React.CSSProperties = useMemo(() => { + return { + height: 140, + borderRadius: 70, + scale: String(1 - outProgress), + }; + }, [outProgress]); + + const firstPath = `M 60.0568 54 v 71.97`; + const secondPath = `M 63.47956 56.17496 L 144.7535 161.1825`; + const thirdPath = `M 121 54 L 121 126`; + + const evolution1 = evolvePath(evolve1, firstPath); + const evolution2 = evolvePath(evolve2, secondPath); + const evolution3 = evolvePath( + interpolate(evolve3, [0, 1], [0, 0.7]), + thirdPath, + ); + + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; diff --git a/packages/template-code-generation/src/remotion/MyComp/Rings.tsx b/packages/template-code-generation/src/remotion/MyComp/Rings.tsx new file mode 100644 index 00000000000..8e27bae8569 --- /dev/null +++ b/packages/template-code-generation/src/remotion/MyComp/Rings.tsx @@ -0,0 +1,56 @@ +import React from "react"; +import { AbsoluteFill, interpolateColors, useVideoConfig } from "remotion"; + +const RadialGradient: React.FC<{ + radius: number; + color: string; +}> = ({ radius, color }) => { + const height = radius * 2; + const width = radius * 2; + + return ( + +
+
+ ); +}; + +export const Rings: React.FC<{ + outProgress: number; +}> = ({ outProgress }) => { + const scale = 1 / (1 - outProgress); + const { height } = useVideoConfig(); + + return ( + + {new Array(5) + .fill(true) + .map((_, i) => { + return ( + + ); + }) + .reverse()} + + ); +}; diff --git a/packages/template-code-generation/src/remotion/MyComp/TextFade.tsx b/packages/template-code-generation/src/remotion/MyComp/TextFade.tsx new file mode 100644 index 00000000000..1b71930a0b9 --- /dev/null +++ b/packages/template-code-generation/src/remotion/MyComp/TextFade.tsx @@ -0,0 +1,45 @@ +import React, { useMemo } from "react"; +import { + AbsoluteFill, + interpolate, + spring, + useCurrentFrame, + useVideoConfig, +} from "remotion"; + +export const TextFade: React.FC<{ + children: React.ReactNode; +}> = ({ children }) => { + const { fps } = useVideoConfig(); + const frame = useCurrentFrame(); + + const progress = spring({ + fps, + frame, + config: { + damping: 200, + }, + durationInFrames: 80, + }); + + const rightStop = interpolate(progress, [0, 1], [200, 0]); + + const leftStop = Math.max(0, rightStop - 60); + + const maskImage = `linear-gradient(-45deg, transparent ${leftStop}%, black ${rightStop}%)`; + + const content: React.CSSProperties = useMemo(() => { + return { + maskImage, + WebkitMaskImage: maskImage, + }; + }, [maskImage]); + + return ( + + +
{children}
+
+
+ ); +}; diff --git a/packages/template-code-generation/src/remotion/Root.tsx b/packages/template-code-generation/src/remotion/Root.tsx new file mode 100644 index 00000000000..83276274db8 --- /dev/null +++ b/packages/template-code-generation/src/remotion/Root.tsx @@ -0,0 +1,38 @@ +import { Composition } from "remotion"; +import { Main } from "./MyComp/Main"; +import { + COMP_NAME, + defaultMyCompProps, + DURATION_IN_FRAMES, + VIDEO_FPS, + VIDEO_HEIGHT, + VIDEO_WIDTH, +} from "../../types/constants"; +import { NextLogo } from "./MyComp/NextLogo"; + +export const RemotionRoot: React.FC = () => { + return ( + <> + +