Skip to content

🎥 Make videos programmatically with React

add tailwind template

Jonny Burger3bd06c2c6099
diff --git a/packages/create-video/src/templates.tsx b/packages/create-video/src/templates.tsx
index 9383576438..6620b28046 100644
--- a/packages/create-video/src/templates.tsx
+++ b/packages/create-video/src/templates.tsx
@@ -97,7 +97,7 @@ export const FEATURED_TEMPLATES: Template[] = [
defaultBranch: 'main',
featuredOnHomePage: 'Next.js',
previewURL: null,
- templateInMonorepo: null,
+ templateInMonorepo: 'template-next-app',
allowEnableTailwind: false,
},
{
diff --git a/packages/template-next-app/.env.example b/packages/template-next-app/.env.example
new file mode 100644
index 0000000000..23c2bac312
--- /dev/null
+++ b/packages/template-next-app/.env.example
@@ -0,0 +1,2 @@
+REMOTION_AWS_ACCESS_KEY_ID=""
+REMOTION_AWS_SECRET_ACCESS_KEY=""
diff --git a/packages/template-next-app/.eslintrc.json b/packages/template-next-app/.eslintrc.json
new file mode 100644
index 0000000000..cb442176e8
--- /dev/null
+++ b/packages/template-next-app/.eslintrc.json
@@ -0,0 +1,10 @@
+{
+ "extends": "next",
+ "plugins": ["@remotion"],
+ "overrides": [
+ {
+ "files": ["remotion/**/*.{ts,tsx}"],
+ "extends": ["plugin:@remotion/recommended"]
+ }
+ ]
+}
diff --git a/packages/template-next-app/.gitignore b/packages/template-next-app/.gitignore
new file mode 100644
index 0000000000..cc9b35922b
--- /dev/null
+++ b/packages/template-next-app/.gitignore
@@ -0,0 +1,38 @@
+# 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
\ No newline at end of file
diff --git a/packages/template-next-app/.npmrc b/packages/template-next-app/.npmrc
new file mode 100644
index 0000000000..3e775efb0f
--- /dev/null
+++ b/packages/template-next-app/.npmrc
@@ -0,0 +1 @@
+auto-install-peers=true
diff --git a/packages/template-next-app/.prettierrc b/packages/template-next-app/.prettierrc
new file mode 100644
index 0000000000..37d5071748
--- /dev/null
+++ b/packages/template-next-app/.prettierrc
@@ -0,0 +1,5 @@
+{
+ "useTabs": false,
+ "bracketSpacing": true,
+ "tabWidth": 2
+}
diff --git a/packages/template-next-app/README.md b/packages/template-next-app/README.md
new file mode 100644
index 0000000000..3de043b5b3
--- /dev/null
+++ b/packages/template-next-app/README.md
@@ -0,0 +1,76 @@
+<img src="https://github.com/remotion-dev/template-next/assets/1629785/9092db5f-7c0c-4d38-97c4-5f5a61f5cc098" />
+<br/>
+<br/>
+
+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. There is a [Tailwind CSS version](https://github.com/remotion-dev/template-next-app-dir-tailwind) and a [Pages directory version](https://github.com/remotion-dev/template-next-pages-dir) of this template available.
+
+<img src="https://github.com/remotion-dev/template-next/assets/1629785/c9c2e5ca-2637-4ec8-8e40-a8feb5740d88" />
+
+## Getting Started
+
+[Use this template](https://github.com/new?template_name=template-next-app-dir&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
+```
+
+## Commands
+
+Start the Next.js dev server:
+
+```
+npm run dev
+```
+
+Open the Remotion Studio:
+
+```
+npm run remotion
+```
+
+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-next-app/app/api/lambda/progress/route.ts b/packages/template-next-app/app/api/lambda/progress/route.ts
new file mode 100644
index 0000000000..5c52e0ca62
--- /dev/null
+++ b/packages/template-next-app/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 { executeApi } from "../../../../helpers/api-response";
+import { ProgressRequest, ProgressResponse } from "../../../../types/schema";
+
+export const POST = executeApi<ProgressResponse, typeof ProgressRequest>(
+ 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-next-app/app/api/lambda/render/route.ts b/packages/template-next-app/app/api/lambda/render/route.ts
new file mode 100644
index 0000000000..d6a07b31e1
--- /dev/null
+++ b/packages/template-next-app/app/api/lambda/render/route.ts
@@ -0,0 +1,50 @@
+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 { executeApi } from "../../../../helpers/api-response";
+import { RenderRequest } from "../../../../types/schema";
+
+export const POST = executeApi<RenderMediaOnLambdaOutput, typeof RenderRequest>(
+ 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-next-app/app/favicon.ico b/packages/template-next-app/app/favicon.ico
new file mode 100644
index 0000000000..718d6fea48
Binary files /dev/null and b/packages/template-next-app/app/favicon.ico differ
diff --git a/packages/template-next-app/app/layout.tsx b/packages/template-next-app/app/layout.tsx
new file mode 100644
index 0000000000..107b812cce
--- /dev/null
+++ b/packages/template-next-app/app/layout.tsx
@@ -0,0 +1,22 @@
+import "../styles/global.css";
+import { Metadata } from "next";
+
+export const metadata: Metadata = {
+ title: "Remotion and Next.js",
+ description: "Remotion and Next.js",
+ viewport: "width=device-width, initial-scale=1, maximum-scale=1",
+};
+
+export default function RootLayout({
+ // Layouts must accept a children prop.
+ // This will be populated with nested layouts or pages
+ children,
+}: {
+ children: React.ReactNode;
+}) {
+ return (
+ <html lang="en">
+ <body>{children}</body>
+ </html>
+ );
+}
diff --git a/packages/template-next-app/app/page.tsx b/packages/template-next-app/app/page.tsx
new file mode 100644
index 0000000000..3a3d62a27a
--- /dev/null
+++ b/packages/template-next-app/app/page.tsx
@@ -0,0 +1,79 @@
+"use client";
+
+import { Player } from "@remotion/player";
+import type { NextPage } from "next";
+import React, { useMemo, useState } from "react";
+import { Main } from "../remotion/MyComp/Main";
+import {
+ CompositionProps,
+ defaultMyCompProps,
+ DURATION_IN_FRAMES,
+ VIDEO_FPS,
+ VIDEO_HEIGHT,
+ VIDEO_WIDTH,
+} from "../types/constants";
+import { z } from "zod";
+import { RenderControls } from "../components/RenderControls";
+import { Tips } from "../components/Tips/Tips";
+import { Spacing } from "../components/Spacing";
+
+const container: React.CSSProperties = {
+ maxWidth: 768,
+ margin: "auto",
+ marginBottom: 20,
+};
+
+const outer: React.CSSProperties = {
+ borderRadius: "var(--geist-border-radius)",
+ overflow: "hidden",
+ boxShadow: "0 0 200px rgba(0, 0, 0, 0.15)",
+ marginBottom: 40,
+ marginTop: 60,
+};
+
+const player: React.CSSProperties = {
+ width: "100%",
+};
+
+const Home: NextPage = () => {
+ const [text, setText] = useState<string>(defaultMyCompProps.title);
+
+ const inputProps: z.infer<typeof CompositionProps> = useMemo(() => {
+ return {
+ title: text,
+ };
+ }, [text]);
+
+ return (
+ <div>
+ <div style={container}>
+ <div className="cinematics" style={outer}>
+ <Player
+ component={Main}
+ inputProps={inputProps}
+ durationInFrames={DURATION_IN_FRAMES}
+ fps={VIDEO_FPS}
+ compositionHeight={VIDEO_HEIGHT}
+ compositionWidth={VIDEO_WIDTH}
+ style={player}
+ controls
+ autoPlay
+ loop
+ />
+ </div>
+ <RenderControls
+ text={text}
+ setText={setText}
+ inputProps={inputProps}
+ ></RenderControls>
+ <Spacing></Spacing>
+ <Spacing></Spacing>
+ <Spacing></Spacing>
+ <Spacing></Spacing>
+ <Tips></Tips>
+ </div>
+ </div>
+ );
+};
+
+export default Home;
diff --git a/packages/template-next-app/components/AlignEnd.tsx b/packages/template-next-app/components/AlignEnd.tsx
new file mode 100644
index 0000000000..f08aa29ad5
--- /dev/null
+++ b/packages/template-next-app/components/AlignEnd.tsx
@@ -0,0 +1,11 @@
+import React from "react";
+
+const container: React.CSSProperties = {
+ alignSelf: "flex-end",
+};
+
+export const AlignEnd: React.FC<{
+ children: React.ReactNode;
+}> = ({ children }) => {
+ return <div style={container}>{children}</div>;
+};
diff --git a/packages/template-next-app/components/Button/Button.tsx b/packages/template-next-app/components/Button/Button.tsx
new file mode 100644
index 0000000000..b697c90314
--- /dev/null
+++ b/packages/template-next-app/components/Button/Button.tsx
@@ -0,0 +1,37 @@
+import React, { forwardRef } from "react";
+import { Spacing } from "../Spacing";
+import { Spinner } from "../Spinner/Spinner";
+import styles from "./styles.module.css";
+
+const ButtonForward: React.ForwardRefRenderFunction<
+ HTMLButtonElement,
+ {
+ onClick?: () => void;
+ disabled?: boolean;
+ children: React.ReactNode;
+ loading?: boolean;
+ secondary?: boolean;
+ }
+> = ({ onClick, disabled, children, loading, secondary }, ref) => {
+ return (
+ <button
+ ref={ref}
+ className={[
+ styles.button,
+ secondary ? styles.secondarybutton : undefined,
+ ].join(" ")}
+ onClick={onClick}
+ disabled={disabled}
+ >
+ {loading && (
+ <>
+ <Spinner size={20}></Spinner>
+ <Spacing></Spacing>
+ </>
+ )}
+ {children}
+ </button>
+ );
+};
+
+export const Button = forwardRef(ButtonForward);
diff --git a/packages/template-next-app/components/Button/styles.module.css b/packages/template-next-app/components/Button/styles.module.css
new file mode 100644
index 0000000000..143543e9e8
--- /dev/null
+++ b/packages/template-next-app/components/Button/styles.module.css
@@ -0,0 +1,37 @@
+.button {
+ border: 1px solid var(--foreground);
+ border-radius: var(--geist-border-radius);
+ background-color: var(--foreground);
+ color: var(--background);
+ padding-left: var(--geist-half-pad);
+ padding-right: var(--geist-half-pad);
+ height: 40px;
+ font-family: var(--geist-font);
+ font-weight: 500;
+ transition: all 0.15s ease;
+ display: inline-flex;
+ flex-direction: row;
+ align-items: center;
+ appearance: none;
+ font-size: 14px;
+}
+
+.secondarybutton {
+ background-color: var(--background);
+ color: var(--foreground);
+ border-color: var(--unfocused-border-color);
+}
+
+.button:hover {
+ background-color: var(--background);
+ cursor: pointer;
+ color: var(--foreground);
+ border-color: var(--focused-border-color);
+}
+
+.button:disabled {
+ background-color: var(--button-disabled-color);
+ color: var(--disabled-text-color);
+ border-color: var(--unfocused-border-color);
+ cursor: not-allowed;
+}
diff --git a/packages/template-next-app/components/Container.tsx b/packages/template-next-app/components/Container.tsx
new file mode 100644
index 0000000000..71fe2f9b7e
--- /dev/null
+++ b/packages/template-next-app/components/Container.tsx
@@ -0,0 +1,16 @@
+import React from "react";
+
+const inputContainer: React.CSSProperties = {
+ border: "1px solid var(--unfocused-border-color)",
+ padding: "var(--geist-pad)",
+ borderRadius: "var(--geist-border-radius)",
+ backgroundColor: "var(--background)",
+ display: "flex",
+ flexDirection: "column",
+};
+
+export const InputContainer: React.FC<{
+ children: React.ReactNode;
+}> = ({ children }) => {
+ return <div style={inputContainer}>{children}</div>;
+};
diff --git a/packages/template-next-app/components/DownloadButton.tsx b/packages/template-next-app/components/DownloadButton.tsx
new file mode 100644
index 0000000000..5e60c49486
--- /dev/null
+++ b/packages/template-next-app/components/DownloadButton.tsx
@@ -0,0 +1,69 @@
+import React from "react";
+import { State } from "../helpers/use-rendering";
+import { Button } from "./Button/Button";
+import { Spacing } from "./Spacing";
+
+const light: React.CSSProperties = {
+ opacity: 0.6,
+};
+
+const link: React.CSSProperties = {
+ textDecoration: "none",
+};
+
+const row: React.CSSProperties = {
+ display: "flex",
+ flexDirection: "row",
+};
+
+const Megabytes: React.FC<{
+ sizeInBytes: number;
+}> = ({ sizeInBytes }) => {
+ const megabytes = Intl.NumberFormat("en", {
+ notation: "compact",
+ style: "unit",
+ unit: "byte",
+ unitDisplay: "narrow",
+ }).format(sizeInBytes);
+ return <span style={light}>{megabytes}</span>;
+};
+
+export const DownloadButton: React.FC<{
+ state: State;
+ undo: () => void;
+}> = ({ state, undo }) => {
+ if (state.status === "rendering") {
+ return <Button disabled>Download video</Button>;
+ }
+
+ if (state.status !== "done") {
+ throw new Error("Download button should not be rendered when not done");
+ }
+
+ return (
+ <div style={row}>
+ <Button secondary onClick={undo}>
+ <UndoIcon></UndoIcon>
+ </Button>
+ <Spacing></Spacing>
+ <a style={link} href={state.url}>
+ <Button>
+ Download video
+ <Spacing></Spacing>
+ <Megabytes sizeInBytes={state.size}></Megabytes>
+ </Button>
+ </a>
+ </div>
+ );
+};
+
+const UndoIcon: React.FC = () => {
+ return (
+ <svg height="1em" viewBox="0 0 512 512">
+ <path
+ fill="var(--foreground)"
+ d="M48.5 224H40c-13.3 0-24-10.7-24-24V72c0-9.7 5.8-18.5 14.8-22.2s19.3-1.7 26.2 5.2L98.6 96.6c87.6-86.5 228.7-86.2 315.8 1c87.5 87.5 87.5 229.3 0 316.8s-229.3 87.5-316.8 0c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0c62.5 62.5 163.8 62.5 226.3 0s62.5-163.8 0-226.3c-62.2-62.2-162.7-62.5-225.3-1L185 183c6.9 6.9 8.9 17.2 5.2 26.2s-12.5 14.8-22.2 14.8H48.5z"
+ />
+ </svg>
+ );
+};
diff --git a/packages/template-next-app/components/Error.tsx b/packages/template-next-app/components/Error.tsx
new file mode 100644
index 0000000000..7fa5d80fb3
--- /dev/null
+++ b/packages/template-next-app/components/Error.tsx
@@ -0,0 +1,38 @@
+import React from "react";
+
+const container: React.CSSProperties = {
+ color: "var(--geist-error)",
+ fontFamily: "var(--geist-font)",
+ paddingTop: "var(--geist-half-pad)",
+ paddingBottom: "var(--geist-half-pad)",
+};
+
+const icon: React.CSSProperties = {
+ height: 20,
+ verticalAlign: "text-bottom",
+ marginRight: 6,
+};
+
+export const ErrorComp: React.FC<{
+ message: string;
+}> = ({ message }) => {
+ return (
+ <div style={container}>
+ <svg
+ fill="none"
+ shapeRendering="geometricPrecision"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="2"
+ viewBox="0 0 24 24"
+ style={icon}
+ >
+ <circle cx="12" cy="12" r="10" fill="var(--geist-fill)"></circle>
+ <path d="M12 8v4" stroke="currentColor"></path>
+ <path d="M12 16h.01" stroke="currentColor"></path>
+ </svg>
+ <strong>Error:</strong> {message}
+ </div>
+ );
+};
diff --git a/packages/template-next-app/components/Input.tsx b/packages/template-next-app/components/Input.tsx
new file mode 100644
index 0000000000..40b32dd470
--- /dev/null
+++ b/packages/template-next-app/components/Input.tsx
@@ -0,0 +1,36 @@
+import React, { useCallback } from "react";
+
+const textarea: React.CSSProperties = {
+ resize: "none",
+ lineHeight: 1.7,
+ display: "block",
+ width: "100%",
+ borderRadius: "var(--geist-border-radius)",
+ backgroundColor: "var(--background)",
+ padding: "var(--geist-half-pad)",
+ color: "var(--foreground)",
+ fontSize: 14,
+};
+
+export const Input: React.FC<{
+ text: string;
+ setText: React.Dispatch<React.SetStateAction<string>>;
+ disabled?: boolean;
+}> = ({ text, setText, disabled }) => {
+ const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
+ (e) => {
+ setText(e.currentTarget.value);
+ },
+ [setText],
+ );
+
+ return (
+ <input
+ disabled={disabled}
+ name="title"
+ style={textarea}
+ value={text}
+ onChange={onChange}
+ />
+ );
+};
diff --git a/packages/template-next-app/components/ProgressBar.tsx b/packages/template-next-app/components/ProgressBar.tsx
new file mode 100644
index 0000000000..f383f994cd
--- /dev/null
+++ b/packages/template-next-app/components/ProgressBar.tsx
@@ -0,0 +1,35 @@
+import React, { useMemo } from "react";
+
+export const ProgressBar: React.FC<{
+ progress: number;
+}> = ({ progress }) => {
+ const style: React.CSSProperties = useMemo(() => {
+ return {
+ width: "100%",
+ height: 10,
+ borderRadius: 5,
+ appearance: "none",
+ backgroundColor: "var(--unfocused-border-color)",
+ marginTop: 10,
+ marginBottom: 25,
+ };
+ }, []);
+
+ const fill: React.CSSProperties = useMemo(() => {
+ return {
+ backgroundColor: "var(--foreground)",
+ height: 10,
+ borderRadius: 5,
+ transition: "width 0.1s ease-in-out",
+ width: `${progress * 100}%`,
+ };
+ }, [progress]);
+
+ return (
+ <div>
+ <div style={style}>
+ <div style={fill}></div>
+ </div>
+ </div>
+ );
+};
diff --git a/packages/template-next-app/components/RenderControls.tsx b/packages/template-next-app/components/RenderControls.tsx
new file mode 100644
index 0000000000..9cb56cc148
--- /dev/null
+++ b/packages/template-next-app/components/RenderControls.tsx
@@ -0,0 +1,59 @@
+import { z } from "zod";
+import { useRendering } from "../helpers/use-rendering";
+import { CompositionProps, COMP_NAME } from "../types/constants";
+import { AlignEnd } from "./AlignEnd";
+import { Button } from "./Button/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";
+
+export const RenderControls: React.FC<{
+ text: string;
+ setText: React.Dispatch<React.SetStateAction<string>>;
+ inputProps: z.infer<typeof CompositionProps>;
+}> = ({ text, setText, inputProps }) => {
+ const { renderMedia, state, undo } = useRendering(COMP_NAME, inputProps);
+
+ return (
+ <InputContainer>
+ {state.status === "init" ||
+ state.status === "invoking" ||
+ state.status === "error" ? (
+ <>
+ <Input
+ disabled={state.status === "invoking"}
+ setText={setText}
+ text={text}
+ ></Input>
+ <Spacing></Spacing>
+ <AlignEnd>
+ <Button
+ disabled={state.status === "invoking"}
+ loading={state.status === "invoking"}
+ onClick={renderMedia}
+ >
+ Render video
+ </Button>
+ </AlignEnd>
+ {state.status === "error" ? (
+ <ErrorComp message={state.error.message}></ErrorComp>
+ ) : null}
+ </>
+ ) : null}
+ {state.status === "rendering" || state.status === "done" ? (
+ <>
+ <ProgressBar
+ progress={state.status === "rendering" ? state.progress : 1}
+ />
+ <Spacing></Spacing>
+ <AlignEnd>
+ <DownloadButton undo={undo} state={state}></DownloadButton>
+ </AlignEnd>
+ </>
+ ) : null}
+ </InputContainer>
+ );
+};
diff --git a/packages/template-next-app/components/Spacing.tsx b/packages/template-next-app/components/Spacing.tsx
new file mode 100644
index 0000000000..31965a480c
--- /dev/null
+++ b/packages/template-next-app/components/Spacing.tsx
@@ -0,0 +1,12 @@
+import React from "react";
+
+export const Spacing: React.FC = () => {
+ return (
+ <div
+ style={{
+ height: "var(--geist-quarter-pad)",
+ width: "var(--geist-quarter-pad)",
+ }}
+ />
+ );
+};
diff --git a/packages/template-next-app/components/Spinner/Spinner.tsx b/packages/template-next-app/components/Spinner/Spinner.tsx
new file mode 100644
index 0000000000..ee0ce8f05b
--- /dev/null
+++ b/packages/template-next-app/components/Spinner/Spinner.tsx
@@ -0,0 +1,47 @@
+import React, { useMemo } from "react";
+import { makeRect } from "@remotion/shapes";
+import { translatePath } from "@remotion/paths";
+import styles from "./styles.module.css";
+
+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 (
+ <svg style={style} viewBox={`0 0 ${viewBox} ${viewBox}`}>
+ {new Array(lines).fill(true).map((_, index) => {
+ return (
+ <path
+ className={styles.line}
+ style={{
+ rotate: `${(index * Math.PI * 2) / lines}rad`,
+ transformOrigin: "center center",
+ animationDelay: `${index * 0.1 - lines * 0.1}s`,
+ }}
+ key={index}
+ d={translated}
+ fill="var(--foreground)"
+ ></path>
+ );
+ })}
+ </svg>
+ );
+};
diff --git a/packages/template-next-app/components/Spinner/styles.module.css b/packages/template-next-app/components/Spinner/styles.module.css
new file mode 100644
index 0000000000..00419b05e1
--- /dev/null
+++ b/packages/template-next-app/components/Spinner/styles.module.css
@@ -0,0 +1,12 @@
+@keyframes spinner {
+ 0% {
+ opacity: 1;
+ }
+ 100% {
+ opacity: 0.15;
+ }
+}
+
+.line {
+ animation: spinner 1.2s linear infinite;
+}
diff --git a/packages/template-next-app/components/Tips/Tips.tsx b/packages/template-next-app/components/Tips/Tips.tsx
new file mode 100644
index 0000000000..a6cea969b3
--- /dev/null
+++ b/packages/template-next-app/components/Tips/Tips.tsx
@@ -0,0 +1,67 @@
+import React from "react";
+import styles from "./styles.module.css";
+
+const titlerow: React.CSSProperties = {
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "center",
+ justifyContent: "flex-start",
+};
+
+const titlestyle: React.CSSProperties = {
+ marginBottom: "0.75em",
+ marginTop: "0.75em",
+ color: "var(--foreground)",
+};
+
+const a: React.CSSProperties = {
+ textDecoration: "none",
+ color: "inherit",
+ flex: 1,
+};
+
+const Tip: React.FC<{
+ title: React.ReactNode;
+ description: React.ReactNode;
+ href: string;
+}> = ({ title, description, href }) => {
+ return (
+ <a href={href} target="_blank" rel="noreferrer" style={a}>
+ <div className={styles.item}>
+ <div style={titlerow}>
+ <h4 style={titlestyle}>{title}</h4>
+ <div className={styles.flex}></div>
+ <svg className={styles.icon} height="1em" viewBox="0 0 448 512">
+ <path
+ fill="var(--foreground)"
+ d="M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"
+ />
+ </svg>
+ </div>
+ <p className={styles.p}>{description}</p>
+ </div>
+ </a>
+ );
+};
+
+export const Tips: React.FC = () => {
+ return (
+ <div className={styles.row}>
+ <Tip
+ href="https://www.remotion.dev/docs/the-fundamentals"
+ title="Learn Remotion"
+ description="Learn how to customize this video written in React."
+ ></Tip>
+ <Tip
+ href="https://github.com/remotion-dev/template-next-app-dir"
+ title="See source"
+ description="Visit the GitHub repository for this app."
+ ></Tip>
+ <Tip
+ href="https://remotion.dev/discord"
+ title="Join the community"
+ description="Chat with others builders on Discord."
+ ></Tip>
+ </div>
+ );
+};
diff --git a/packages/template-next-app/components/Tips/styles.module.css b/packages/template-next-app/components/Tips/styles.module.css
new file mode 100644
index 0000000000..af17b0837e
--- /dev/null
+++ b/packages/template-next-app/components/Tips/styles.module.css
@@ -0,0 +1,40 @@
+.row {
+ display: flex;
+ flex-direction: row;
+ font-family: Inter;
+}
+
+.item {
+ cursor: pointer;
+ transition: transform 0.2s ease-in-out;
+ padding: 10px;
+}
+
+.icon {
+ opacity: 0;
+ transition: opacity 0.2s ease-in-out;
+}
+
+.item:hover {
+ transform: translateY(-2px);
+ .icon {
+ opacity: 1;
+ }
+}
+
+.p {
+ font-size: 14px;
+ margin-top: 0;
+ line-height: 1.5;
+ color: var(--subtitle);
+}
+
+.flex {
+ flex: 1;
+}
+
+@media (max-width: 768px) {
+ .row {
+ flex-direction: column;
+ }
+}
diff --git a/packages/template-next-app/config.mjs b/packages/template-next-app/config.mjs
new file mode 100644
index 0000000000..af7f057cf0
--- /dev/null
+++ b/packages/template-next-app/config.mjs
@@ -0,0 +1,12 @@
+import { VERSION } from "remotion/version";
+
+/**
+ * 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 = 2048;
+export const TIMEOUT = 240;
diff --git a/packages/template-next-app/deploy.mjs b/packages/template-next-app/deploy.mjs
new file mode 100644
index 0000000000..83bccc7de4
--- /dev/null
+++ b/packages/template-next-app/deploy.mjs
@@ -0,0 +1,76 @@
+import {
+ deployFunction,
+ deploySite,
+ getOrCreateBucket,
+} from "@remotion/lambda";
+import dotenv from "dotenv";
+import path from "path";
+import { RAM, REGION, SITE_NAME, TIMEOUT } from "./config.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,
+ });
+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(), "remotion", "index.ts"),
+ siteName: SITE_NAME,
+ region: REGION,
+});
+
+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-next-app/helpers/api-response.ts b/packages/template-next-app/helpers/api-response.ts
new file mode 100644
index 0000000000..d4da4ce786
--- /dev/null
+++ b/packages/template-next-app/helpers/api-response.ts
@@ -0,0 +1,36 @@
+import { NextResponse } from "next/server";
+import { z, ZodType } from "zod";
+
+export type ApiResponse<Res> =
+ | {
+ type: "error";
+ message: string;
+ }
+ | {
+ type: "success";
+ data: Res;
+ };
+
+export const executeApi =
+ <Res, Req extends ZodType>(
+ schema: Req,
+ handler: (req: Request, body: z.infer<Req>) => Promise<Res>,
+ ) =>
+ 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-next-app/helpers/use-rendering.ts b/packages/template-next-app/helpers/use-rendering.ts
new file mode 100644
index 0000000000..a7f549d24f
--- /dev/null
+++ b/packages/template-next-app/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<void>((resolve) => {
+ setTimeout(() => {
+ resolve();
+ }, milliSeconds);
+ });
+};
+
+export const useRendering = (
+ id: string,
+ inputProps: z.infer<typeof CompositionProps>,
+) => {
+ const [state, setState] = useState<State>({
+ 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-next-app/lambda/api.ts b/packages/template-next-app/lambda/api.ts
new file mode 100644
index 0000000000..a01d801ed5
--- /dev/null
+++ b/packages/template-next-app/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 <Res>(
+ endpoint: string,
+ body: unknown,
+): Promise<Res> => {
+ const result = await fetch(endpoint, {
+ method: "post",
+ body: JSON.stringify(body),
+ headers: {
+ "content-type": "application/json",
+ },
+ });
+ const json = (await result.json()) as ApiResponse<Res>;
+ if (json.type === "error") {
+ throw new Error(json.message);
+ }
+
+ return json.data;
+};
+
+export const renderVideo = async ({
+ id,
+ inputProps,
+}: {
+ id: string;
+ inputProps: z.infer<typeof CompositionProps>;
+}) => {
+ const body: z.infer<typeof RenderRequest> = {
+ id,
+ inputProps,
+ };
+
+ return makeRequest<RenderMediaOnLambdaOutput>("/api/lambda/render", body);
+};
+
+export const getProgress = async ({
+ id,
+ bucketName,
+}: {
+ id: string;
+ bucketName: string;
+}) => {
+ const body: z.infer<typeof ProgressRequest> = {
+ id,
+ bucketName,
+ };
+
+ return makeRequest<ProgressResponse>("/api/lambda/progress", body);
+};
diff --git a/packages/template-next-app/next.config.js b/packages/template-next-app/next.config.js
new file mode 100644
index 0000000000..cfdc89fd80
--- /dev/null
+++ b/packages/template-next-app/next.config.js
@@ -0,0 +1,8 @@
+/** @type {import('next').NextConfig} */
+const nextConfig = {
+ reactStrictMode: true,
+ swcMinify: true,
+
+};
+
+module.exports = nextConfig;
diff --git a/packages/template-next-app/package.json b/packages/template-next-app/package.json
new file mode 100644
index 0000000000..0aaa7b6a4d
--- /dev/null
+++ b/packages/template-next-app/package.json
@@ -0,0 +1,40 @@
+{
+ "name": "template-next-app",
+ "version": "0.1.0",
+ "private": true,
+ "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:*",
+ "next": "14.2.13",
+ "react": "18.3.1",
+ "react-dom": "18.3.1",
+ "remotion": "workspace:*",
+ "zod": "3.22.3"
+ },
+ "devDependencies": {
+ "@remotion/eslint-config": "workspace:*",
+ "@types/node": "20.14.11",
+ "@types/react": "18.3.1",
+ "@types/react-dom": "18.3.0",
+ "@types/web": "0.0.78",
+ "dotenv": "16.0.3",
+ "eslint": "8.56.0",
+ "eslint-config-next": "14.2.13",
+ "typescript": "5.3.3",
+ "prettier": "3.2.5"
+ }
+}
diff --git a/packages/template-next-app/remotion.config.ts b/packages/template-next-app/remotion.config.ts
new file mode 100644
index 0000000000..fa14ff0033
--- /dev/null
+++ b/packages/template-next-app/remotion.config.ts
@@ -0,0 +1,8 @@
+// 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";
+
+Config.setVideoImageFormat("jpeg");
diff --git a/packages/template-next-app/remotion/MyComp/Main.tsx b/packages/template-next-app/remotion/MyComp/Main.tsx
new file mode 100644
index 0000000000..14891a8dcf
--- /dev/null
+++ b/packages/template-next-app/remotion/MyComp/Main.tsx
@@ -0,0 +1,63 @@
+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 React, { useMemo } from "react";
+import { Rings } from "./Rings";
+import { TextFade } from "./TextFade";
+
+loadFont();
+
+const container: React.CSSProperties = {
+ backgroundColor: "white",
+};
+
+const logo: React.CSSProperties = {
+ justifyContent: "center",
+ alignItems: "center",
+};
+
+export const Main = ({ title }: z.infer<typeof CompositionProps>) => {
+ 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,
+ });
+
+ const titleStyle: React.CSSProperties = useMemo(() => {
+ return { fontFamily, fontSize: 70 };
+ }, []);
+
+ return (
+ <AbsoluteFill style={container}>
+ <Sequence durationInFrames={transitionStart + transitionDuration}>
+ <Rings outProgress={logoOut}></Rings>
+ <AbsoluteFill style={logo}>
+ <NextLogo outProgress={logoOut}></NextLogo>
+ </AbsoluteFill>
+ </Sequence>
+ <Sequence from={transitionStart + transitionDuration / 2}>
+ <TextFade>
+ <h1 style={titleStyle}>{title}</h1>
+ </TextFade>
+ </Sequence>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/template-next-app/remotion/MyComp/NextLogo.tsx b/packages/template-next-app/remotion/MyComp/NextLogo.tsx
new file mode 100644
index 0000000000..5d0f03ab6a
--- /dev/null
+++ b/packages/template-next-app/remotion/MyComp/NextLogo.tsx
@@ -0,0 +1,119 @@
+import { evolvePath } from "@remotion/paths";
+import React, { useMemo } from "react";
+import { interpolate, spring, useCurrentFrame, useVideoConfig } from "remotion";
+
+const mask: React.CSSProperties = {
+ maskType: "alpha",
+};
+
+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 (
+ <svg style={style} fill="none" viewBox="0 0 180 180">
+ <mask height="180" id="mask" style={mask} width="180" x="0" y="0">
+ <circle cx="90" cy="90" fill="black" r="90"></circle>
+ </mask>
+ <mask id="n-mask" style={mask}>
+ <path d={nStroke} fill="black"></path>
+ </mask>
+ <g mask="url(#mask)">
+ <circle cx="90" cy="90" fill="black" r="90"></circle>
+ <g stroke="url(#gradient0)" mask="url(#n-mask)">
+ <path
+ strokeWidth="12.1136"
+ d={firstPath}
+ strokeDasharray={evolution1.strokeDasharray}
+ strokeDashoffset={evolution1.strokeDashoffset}
+ ></path>
+ <path
+ strokeWidth={12.1136}
+ d={secondPath}
+ strokeDasharray={evolution2.strokeDasharray}
+ strokeDashoffset={evolution2.strokeDashoffset}
+ ></path>
+ </g>
+ <path
+ stroke="url(#gradient1)"
+ d={thirdPath}
+ strokeDasharray={evolution3.strokeDasharray}
+ strokeDashoffset={evolution3.strokeDashoffset}
+ strokeWidth="12"
+ ></path>
+ </g>
+ <defs>
+ <linearGradient
+ gradientUnits="userSpaceOnUse"
+ id="gradient0"
+ x1="109"
+ x2="144.5"
+ y1="116.5"
+ y2="160.5"
+ >
+ <stop stopColor="white"></stop>
+ <stop offset="1" stopColor="white" stopOpacity="0"></stop>
+ </linearGradient>
+ <linearGradient
+ gradientUnits="userSpaceOnUse"
+ id="gradient1"
+ x1="121"
+ x2="120.799"
+ y1="54"
+ y2="106.875"
+ >
+ <stop stopColor="white"></stop>
+ <stop offset="1" stopColor="white" stopOpacity="0"></stop>
+ </linearGradient>
+ </defs>
+ </svg>
+ );
+};
diff --git a/packages/template-next-app/remotion/MyComp/Rings.tsx b/packages/template-next-app/remotion/MyComp/Rings.tsx
new file mode 100644
index 0000000000..c886f4460f
--- /dev/null
+++ b/packages/template-next-app/remotion/MyComp/Rings.tsx
@@ -0,0 +1,58 @@
+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 (
+ <AbsoluteFill
+ style={{
+ justifyContent: "center",
+ alignItems: "center",
+ }}
+ >
+ <div
+ style={{
+ height,
+ width,
+ borderRadius: "50%",
+ backgroundColor: color,
+ position: "absolute",
+ boxShadow: "0 0 100px rgba(0, 0, 0, 0.05)",
+ }}
+ ></div>
+ </AbsoluteFill>
+ );
+};
+
+export const Rings: React.FC<{
+ outProgress: number;
+}> = ({ outProgress }) => {
+ const scale = 1 / (1 - outProgress);
+ const { height } = useVideoConfig();
+
+ return (
+ <AbsoluteFill
+ style={{
+ transform: `scale(${scale})`,
+ }}
+ >
+ {new Array(5)
+ .fill(true)
+ .map((_, i) => {
+ return (
+ <RadialGradient
+ key={i}
+ radius={height * 0.3 * i}
+ color={interpolateColors(i, [0, 4], ["#fff", "#fff"])}
+ />
+ );
+ })
+ .reverse()}
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/template-next-app/remotion/MyComp/TextFade.tsx b/packages/template-next-app/remotion/MyComp/TextFade.tsx
new file mode 100644
index 0000000000..a9a0891aaa
--- /dev/null
+++ b/packages/template-next-app/remotion/MyComp/TextFade.tsx
@@ -0,0 +1,54 @@
+import React, { useMemo } from "react";
+import {
+ AbsoluteFill,
+ interpolate,
+ spring,
+ useCurrentFrame,
+ useVideoConfig,
+} from "remotion";
+
+const outer: React.CSSProperties = {};
+
+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 container: React.CSSProperties = useMemo(() => {
+ return {
+ justifyContent: "center",
+ alignItems: "center",
+ };
+ }, []);
+
+ const content: React.CSSProperties = useMemo(() => {
+ return {
+ maskImage,
+ WebkitMaskImage: maskImage,
+ };
+ }, [maskImage]);
+
+ return (
+ <AbsoluteFill style={outer}>
+ <AbsoluteFill style={container}>
+ <div style={content}>{children}</div>
+ </AbsoluteFill>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/template-next-app/remotion/Root.tsx b/packages/template-next-app/remotion/Root.tsx
new file mode 100644
index 0000000000..92de0800a6
--- /dev/null
+++ b/packages/template-next-app/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 (
+ <>
+ <Composition
+ id={COMP_NAME}
+ component={Main}
+ durationInFrames={DURATION_IN_FRAMES}
+ fps={VIDEO_FPS}
+ width={VIDEO_WIDTH}
+ height={VIDEO_HEIGHT}
+ defaultProps={defaultMyCompProps}
+ />
+ <Composition
+ id="NextLogo"
+ component={NextLogo}
+ durationInFrames={300}
+ fps={30}
+ width={140}
+ height={140}
+ defaultProps={{
+ outProgress: 0,
+ }}
+ />
+ </>
+ );
+};
diff --git a/packages/template-next-app/remotion/index.ts b/packages/template-next-app/remotion/index.ts
new file mode 100644
index 0000000000..f31c790edb
--- /dev/null
+++ b/packages/template-next-app/remotion/index.ts
@@ -0,0 +1,4 @@
+import { registerRoot } from "remotion";
+import { RemotionRoot } from "./Root";
+
+registerRoot(RemotionRoot);
diff --git a/packages/template-next-app/styles/global.css b/packages/template-next-app/styles/global.css
new file mode 100644
index 0000000000..6aa2d70cb6
--- /dev/null
+++ b/packages/template-next-app/styles/global.css
@@ -0,0 +1,58 @@
+:root {
+ --background: #fff;
+ --foreground: #000;
+ --unfocused-border-color: #eaeaea;
+ --focused-border-color: #666;
+
+ --button-disabled-color: #fafafa;
+ --disabled-text-color: #999;
+
+ --geist-border-radius: 5px;
+ --geist-quarter-pad: 6px;
+ --geist-half-pad: 12px;
+ --geist-pad: 24px;
+ --geist-font: "Inter";
+
+ --geist-error: #e00;
+
+ --subtitle: #666;
+}
+
+* {
+ box-sizing: border-box;
+}
+
+.cinematics {
+ box-shadow: 0 0 200px rgba(0, 0, 0, 0.15);
+}
+
+@media (prefers-color-scheme: dark) {
+ :root {
+ --background: #000000;
+ --unfocused-border-color: #333;
+ --focused-border-color: #888;
+ --foreground: #fff;
+ --button-disabled-color: #111;
+ --geist-error: red;
+ --subtitle: #8D8D8D
+
+ }
+ .cinematics {
+ box-shadow: 0 0 200px rgba(255, 255, 255, 0.15);
+ }
+}
+
+body {
+ background-color: var(--background);
+}
+
+
+input {
+ border: 1px solid var(--unfocused-border-color);
+ transition: border-color 0.15s ease;
+ outline: none;
+}
+
+input:focus {
+ border-color: var(--focused-border-color);
+}
diff --git a/packages/template-next-app/tsconfig.json b/packages/template-next-app/tsconfig.json
new file mode 100644
index 0000000000..0266bde2fd
--- /dev/null
+++ b/packages/template-next-app/tsconfig.json
@@ -0,0 +1,37 @@
+{
+ "compilerOptions": {
+ "target": "es5",
+ "lib": [
+ "dom",
+ "dom.iterable",
+ "esnext"
+ ],
+ "allowJs": true,
+ "skipLibCheck": true,
+ "strict": true,
+ "forceConsistentCasingInFileNames": true,
+ "noEmit": true,
+ "esModuleInterop": true,
+ "module": "esnext",
+ "moduleResolution": "node",
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "jsx": "preserve",
+ "incremental": true,
+ "noUnusedLocals": true,
+ "plugins": [
+ {
+ "name": "next"
+ }
+ ]
+ },
+ "include": [
+ "next-env.d.ts",
+ "**/*.ts",
+ "**/*.tsx",
+ ".next/types/**/*.ts"
+ ],
+ "exclude": [
+ "node_modules"
+ ]
+}
diff --git a/packages/template-next-app/types/constants.ts b/packages/template-next-app/types/constants.ts
new file mode 100644
index 0000000000..4767c5e80f
--- /dev/null
+++ b/packages/template-next-app/types/constants.ts
@@ -0,0 +1,15 @@
+import { z } from "zod";
+export const COMP_NAME = "MyComp";
+
+export const CompositionProps = z.object({
+ title: z.string(),
+});
+
+export const defaultMyCompProps: z.infer<typeof CompositionProps> = {
+ title: "Next.js and Remotion",
+};
+
+export const DURATION_IN_FRAMES = 200;
+export const VIDEO_WIDTH = 1280;
+export const VIDEO_HEIGHT = 720;
+export const VIDEO_FPS = 30;
diff --git a/packages/template-next-app/types/schema.ts b/packages/template-next-app/types/schema.ts
new file mode 100644
index 0000000000..da1562f334
--- /dev/null
+++ b/packages/template-next-app/types/schema.ts
@@ -0,0 +1,27 @@
+import { z } from "zod";
+import { CompositionProps } from "./constants";
+
+export const RenderRequest = z.object({
+ id: z.string(),
+ inputProps: CompositionProps,
+});
+
+export const ProgressRequest = z.object({
+ bucketName: z.string(),
+ id: z.string(),
+});
+
+export type ProgressResponse =
+ | {
+ type: "error";
+ message: string;
+ }
+ | {
+ type: "progress";
+ progress: number;
+ }
+ | {
+ type: "done";
+ url: string;
+ size: number;
+ };
diff --git a/packages/template-next-app/vercel.json b/packages/template-next-app/vercel.json
new file mode 100644
index 0000000000..b2129dd8ec
--- /dev/null
+++ b/packages/template-next-app/vercel.json
@@ -0,0 +1,4 @@
+{
+ "buildCommand": "node deploy.mjs && next build"
+ }
+
\ No newline at end of file
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 120493437b..c28aa54ddc 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1681,6 +1681,76 @@ importers:
specifier: 5.3.3
version: 5.3.3
+ packages/template-next-app:
+ dependencies:
+ '@remotion/bundler':
+ specifier: workspace:*
+ version: link:../bundler
+ '@remotion/cli':
+ specifier: workspace:*
+ version: link:../cli
+ '@remotion/google-fonts':
+ specifier: workspace:*
+ version: link:../google-fonts
+ '@remotion/lambda':
+ specifier: workspace:*
+ version: link:../lambda
+ '@remotion/paths':
+ specifier: workspace:*
+ version: link:../paths
+ '@remotion/player':
+ specifier: workspace:*
+ version: link:../player
+ '@remotion/shapes':
+ specifier: workspace:*
+ version: link:../shapes
+ next:
+ specifier: 14.2.13
+ react:
+ specifier: 18.3.1
+ version: 18.3.1
+ react-dom:
+ specifier: 18.3.1
+ version: 18.3.1([email protected])
+ remotion:
+ specifier: workspace:*
+ version: link:../core
+ zod:
+ specifier: 3.22.3
+ version: 3.22.3
+ devDependencies:
+ '@remotion/eslint-config':
+ specifier: workspace:*
+ version: link:../eslint-config
+ '@types/node':
+ specifier: 20.14.11
+ version: 20.14.11
+ '@types/react':
+ specifier: 18.3.1
+ version: 18.3.1
+ '@types/react-dom':
+ specifier: 18.3.0
+ version: 18.3.0
+ '@types/web':
+ specifier: 0.0.78
+ version: 0.0.78
+ dotenv:
+ specifier: 16.0.3
+ version: 16.0.3
+ eslint:
+ specifier: 8.56.0
+ version: 8.56.0
+ eslint-config-next:
+ specifier: 14.2.13
+ prettier:
+ specifier: 3.2.5
+ version: 3.2.5
+ typescript:
+ specifier: 5.3.3
+ version: 5.3.3
+
packages/template-next-pages:
dependencies:
'@remotion/bundler':
diff --git a/tsconfig.json b/tsconfig.json
index 83932527f1..eb39a9c458 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -120,6 +120,9 @@
{
"path": "./packages/template-next-pages"
},
+ {
+ "path": "./packages/template-next-app"
+ },
{
"path": "./packages/template-helloworld"
},