diff --git a/.env.example b/.env.example
new file mode 100644
index 00000000..23c2bac3
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,2 @@
+REMOTION_AWS_ACCESS_KEY_ID=""
+REMOTION_AWS_SECRET_ACCESS_KEY=""
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 00000000..cb442176
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,10 @@
+{
+ "extends": "next",
+ "plugins": ["@remotion"],
+ "overrides": [
+ {
+ "files": ["remotion/**/*.{ts,tsx}"],
+ "extends": ["plugin:@remotion/recommended"]
+ }
+ ]
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..cc9b3592
--- /dev/null
+++ b/.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/README.md b/README.md
new file mode 100644
index 00000000..2b7c3427
--- /dev/null
+++ b/README.md
@@ -0,0 +1,76 @@
+
+
+
+
+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 [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&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/app/api/lambda/progress/route.ts b/app/api/lambda/progress/route.ts
new file mode 100644
index 00000000..e4f935ee
--- /dev/null
+++ b/app/api/lambda/progress/route.ts
@@ -0,0 +1,48 @@
+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(
+ ProgressRequest,
+ async (req, body) => {
+ if (req.method !== "POST") {
+ throw new Error("Only POST requests are allowed");
+ }
+
+ 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/app/api/lambda/render/route.ts b/app/api/lambda/render/route.ts
new file mode 100644
index 00000000..cd70912c
--- /dev/null
+++ b/app/api/lambda/render/route.ts
@@ -0,0 +1,54 @@
+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(
+ RenderRequest,
+ async (req, body) => {
+ if (req.method !== "POST") {
+ throw new Error("Only POST requests are allowed");
+ }
+
+ 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/app/favicon.ico b/app/favicon.ico
new file mode 100644
index 00000000..718d6fea
Binary files /dev/null and b/app/favicon.ico differ
diff --git a/app/layout.tsx b/app/layout.tsx
new file mode 100644
index 00000000..107b812c
--- /dev/null
+++ b/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 (
+
+ {children}
+
+ );
+}
diff --git a/app/page.tsx b/app/page.tsx
new file mode 100644
index 00000000..3a3d62a2
--- /dev/null
+++ b/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(defaultMyCompProps.title);
+
+ const inputProps: z.infer = useMemo(() => {
+ return {
+ title: text,
+ };
+ }, [text]);
+
+ return (
+
+ );
+};
+
+export default Home;
diff --git a/components/AlignEnd.tsx b/components/AlignEnd.tsx
new file mode 100644
index 00000000..f08aa29a
--- /dev/null
+++ b/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 {children}
;
+};
diff --git a/components/Button/Button.tsx b/components/Button/Button.tsx
new file mode 100644
index 00000000..b697c903
--- /dev/null
+++ b/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 (
+
+ );
+};
+
+export const Button = forwardRef(ButtonForward);
diff --git a/components/Button/styles.module.css b/components/Button/styles.module.css
new file mode 100644
index 00000000..35a907d8
--- /dev/null
+++ b/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/components/Container.tsx b/components/Container.tsx
new file mode 100644
index 00000000..71fe2f9b
--- /dev/null
+++ b/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 {children}
;
+};
diff --git a/components/DownloadButton.tsx b/components/DownloadButton.tsx
new file mode 100644
index 00000000..5e60c494
--- /dev/null
+++ b/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 {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/components/Error.tsx b/components/Error.tsx
new file mode 100644
index 00000000..7fa5d80f
--- /dev/null
+++ b/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 (
+
+
+
Error: {message}
+
+ );
+};
diff --git a/components/Input.tsx b/components/Input.tsx
new file mode 100644
index 00000000..974ced7b
--- /dev/null
+++ b/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>;
+ disabled?: boolean;
+}> = ({ text, setText, disabled }) => {
+ const onChange: React.ChangeEventHandler = useCallback(
+ (e) => {
+ setText(e.currentTarget.value);
+ },
+ [setText]
+ );
+
+ return (
+
+ );
+};
diff --git a/components/ProgressBar.tsx b/components/ProgressBar.tsx
new file mode 100644
index 00000000..f383f994
--- /dev/null
+++ b/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 (
+
+ );
+};
diff --git a/components/RenderControls.tsx b/components/RenderControls.tsx
new file mode 100644
index 00000000..9cb56cc1
--- /dev/null
+++ b/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>;
+ 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/components/Spacing.tsx b/components/Spacing.tsx
new file mode 100644
index 00000000..31965a48
--- /dev/null
+++ b/components/Spacing.tsx
@@ -0,0 +1,12 @@
+import React from "react";
+
+export const Spacing: React.FC = () => {
+ return (
+
+ );
+};
diff --git a/components/Spinner/Spinner.tsx b/components/Spinner/Spinner.tsx
new file mode 100644
index 00000000..ee0ce8f0
--- /dev/null
+++ b/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 (
+
+ );
+};
diff --git a/components/Spinner/styles.module.css b/components/Spinner/styles.module.css
new file mode 100644
index 00000000..7f0880c7
--- /dev/null
+++ b/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/components/Tips/Tips.tsx b/components/Tips/Tips.tsx
new file mode 100644
index 00000000..a6cea969
--- /dev/null
+++ b/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 (
+
+
+
+ );
+};
+
+export const Tips: React.FC = () => {
+ return (
+
+
+
+
+
+ );
+};
diff --git a/components/Tips/styles.module.css b/components/Tips/styles.module.css
new file mode 100644
index 00000000..279e4ef8
--- /dev/null
+++ b/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/config.mjs b/config.mjs
new file mode 100644
index 00000000..af7f057c
--- /dev/null
+++ b/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/deploy.mjs b/deploy.mjs
new file mode 100644
index 00000000..536c6ccd
--- /dev/null
+++ b/deploy.mjs
@@ -0,0 +1,77 @@
+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,
+ architecture: "arm64",
+ });
+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/helpers/api-response.ts b/helpers/api-response.ts
new file mode 100644
index 00000000..e5d39878
--- /dev/null
+++ b/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/helpers/use-rendering.ts b/helpers/use-rendering.ts
new file mode 100644
index 00000000..5aa55754
--- /dev/null
+++ b/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/lambda/api.ts b/lambda/api.ts
new file mode 100644
index 00000000..b26bdfba
--- /dev/null
+++ b/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/next.config.js b/next.config.js
new file mode 100644
index 00000000..41ef5ac6
--- /dev/null
+++ b/next.config.js
@@ -0,0 +1,21 @@
+/** @type {import('next').NextConfig} */
+const nextConfig = {
+ reactStrictMode: true,
+ swcMinify: true,
+ webpack: (config, { webpack, isServer, nextRuntime }) => {
+ // Workaround for the following issue:
+ // https://github.com/aws-amplify/amplify-js/issues/11030#issuecomment-1598207365
+
+ // Avoid AWS SDK Node.js require issue
+ if (isServer && nextRuntime === "nodejs")
+ config.plugins.push(
+ new webpack.IgnorePlugin({ resourceRegExp: /^aws-crt$/ }),
+ new webpack.IgnorePlugin({
+ resourceRegExp: /^@aws-sdk\/signature-v4-crt$/,
+ })
+ );
+ return config;
+ },
+};
+
+module.exports = nextConfig;
diff --git a/package.json b/package.json
new file mode 100644
index 00000000..080a7ece
--- /dev/null
+++ b/package.json
@@ -0,0 +1,40 @@
+{
+ "name": "remotion-next-example",
+ "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": "^4.0.19",
+ "@remotion/cli": "^4.0.19",
+ "@remotion/google-fonts": "^4.0.19",
+ "@remotion/lambda": "^4.0.19",
+ "@remotion/paths": "^4.0.19",
+ "@remotion/player": "^4.0.19",
+ "@remotion/shapes": "^4.0.19",
+ "next": "^13.4.13",
+ "react": "^18.2.0",
+ "react-dom": "^18.2.0",
+ "remotion": "^4.0.19",
+ "zod": "^3.21.4"
+ },
+ "devDependencies": {
+ "@remotion/eslint-config": "^4.0.19",
+ "@types/node": "18.7.23",
+ "@types/react": "18.0.26",
+ "@types/react-dom": "18.0.6",
+ "@types/web": "^0.0.61",
+ "dotenv": "^16.0.3",
+ "eslint": "^8.43.0",
+ "eslint-config-next": "^13.4.13",
+ "prettier": "^2.8.8",
+ "typescript": "4.8.3"
+ }
+}
diff --git a/remotion.config.ts b/remotion.config.ts
new file mode 100644
index 00000000..fa14ff00
--- /dev/null
+++ b/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/remotion/MyComp/Main.tsx b/remotion/MyComp/Main.tsx
new file mode 100644
index 00000000..14891a8d
--- /dev/null
+++ b/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) => {
+ 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 (
+
+
+
+
+
+
+
+
+
+ {title}
+
+
+
+ );
+};
diff --git a/remotion/MyComp/NextLogo.tsx b/remotion/MyComp/NextLogo.tsx
new file mode 100644
index 00000000..bc9e7745
--- /dev/null
+++ b/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 (
+
+ );
+};
diff --git a/remotion/MyComp/Rings.tsx b/remotion/MyComp/Rings.tsx
new file mode 100644
index 00000000..c886f446
--- /dev/null
+++ b/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 (
+
+
+
+ );
+};
+
+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/remotion/MyComp/TextFade.tsx b/remotion/MyComp/TextFade.tsx
new file mode 100644
index 00000000..a9a0891a
--- /dev/null
+++ b/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 (
+
+
+ {children}
+
+
+ );
+};
diff --git a/remotion/Root.tsx b/remotion/Root.tsx
new file mode 100644
index 00000000..92de0800
--- /dev/null
+++ b/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 (
+ <>
+
+
+ >
+ );
+};
diff --git a/remotion/index.ts b/remotion/index.ts
new file mode 100644
index 00000000..f31c790e
--- /dev/null
+++ b/remotion/index.ts
@@ -0,0 +1,4 @@
+import { registerRoot } from "remotion";
+import { RemotionRoot } from "./Root";
+
+registerRoot(RemotionRoot);
diff --git a/styles/global.css b/styles/global.css
new file mode 100644
index 00000000..6aa2d70c
--- /dev/null
+++ b/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/tsconfig.json b/tsconfig.json
new file mode 100644
index 00000000..0266bde2
--- /dev/null
+++ b/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/types/constants.ts b/types/constants.ts
new file mode 100644
index 00000000..4767c5e8
--- /dev/null
+++ b/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 = {
+ 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/types/schema.ts b/types/schema.ts
new file mode 100644
index 00000000..da1562f3
--- /dev/null
+++ b/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/vercel.json b/vercel.json
new file mode 100644
index 00000000..b2129dd8
--- /dev/null
+++ b/vercel.json
@@ -0,0 +1,4 @@
+{
+ "buildCommand": "node deploy.mjs && next build"
+ }
+
\ No newline at end of file