🎥 Make videos programmatically with React
hello world template
Jonny Burger53a82c47ef23
diff --git a/packages/create-video/src/templates.tsx b/packages/create-video/src/templates.tsxindex b090fbdaea..824369e800 100644--- a/packages/create-video/src/templates.tsx+++ b/packages/create-video/src/templates.tsx@@ -76,7 +76,7 @@ export const FEATURED_TEMPLATES: Template[] = [defaultBranch: 'main',featuredOnHomePage: 'Hello World',previewURL: 'https://remotion-helloworld.vercel.app/?/HelloWorld',- templateInMonorepo: null,+ templateInMonorepo: 'template-helloworld',allowEnableTailwind: false,},{diff --git a/packages/it-tests/src/templates/publish.ts b/packages/it-tests/src/templates/publish.tsindex 384cfae12d..7749ee3dad 100644--- a/packages/it-tests/src/templates/publish.ts+++ b/packages/it-tests/src/templates/publish.ts@@ -1,21 +1,42 @@import {$} from 'bun';+import {CreateVideoInternals, Template} from 'create-video';import {cpSync} from 'node:fs';import {tmpdir} from 'node:os';import path from 'path';-const publish = async () => {- const folder = path.join(process.cwd(), '..', 'template-blank');+const folders = CreateVideoInternals.FEATURED_TEMPLATES.filter(+ (t) => t.templateInMonorepo !== null,+);++const publish = async (template: Template) => {+ const folder = path.join(+ process.cwd(),+ '..',+ template.templateInMonorepo as string,+ );const tmpDir = tmpdir();const workingDir = path.join(tmpDir, `template-${Math.random()}`);+ await $`git add .`.cwd(folder);const files = await $`git ls-files`.cwd(folder).quiet();- const filesInTemplate = files.stdout.toString('utf-8').trim().split('\n');+ const filesInTemplate = files.stdout+ .toString('utf-8')+ .trim()+ .split('\n')+ .filter(Boolean);const branchName = `${Math.random().toString().replace('0.', '')}`;- await $`git clone [email protected]:remotion-dev/template-empty.git ${workingDir}`;+ await $`git clone [email protected]:remotion-dev/${template.repoName}.git ${workingDir}`;await $`git checkout -b ${branchName}`.cwd(workingDir);+ const existingFilesInRepo = await $`git ls-files`.cwd(workingDir).quiet();+ for (const file of existingFilesInRepo.stdout+ .toString('utf-8')+ .trim()+ .split('\n')) {+ await $`rm ${file}`.cwd(workingDir).quiet();+ }for (const file of filesInTemplate) {const src = path.join(folder, file);@@ -32,7 +53,7 @@ const publish = async () => {await $`git add .`.cwd(workingDir).nothrow();const hasChanges = await $`git status --porcelain`.cwd(workingDir).text();if (!hasChanges) {- console.log('No changes');+ console.log(`No changes in ${template.shortName}`);return;}@@ -41,4 +62,6 @@ const publish = async () => {await $`git push origin ${branchName}`.cwd(workingDir);};-await publish();+for (const template of folders) {+ await publish(template);+}diff --git a/packages/template-helloworld/.eslintrc b/packages/template-helloworld/.eslintrcnew file mode 100644index 0000000000..3ad72802a8--- /dev/null+++ b/packages/template-helloworld/.eslintrc@@ -0,0 +1,3 @@+{+ "extends": "@remotion"+}diff --git a/packages/template-helloworld/.gitignore b/packages/template-helloworld/.gitignorenew file mode 100644index 0000000000..b62197ba2f--- /dev/null+++ b/packages/template-helloworld/.gitignore@@ -0,0 +1,7 @@+node_modules+dist+.DS_Store+.env++# Ignore the output video from Git but not videos you import into src/.+outdiff --git a/packages/template-helloworld/.prettierrc b/packages/template-helloworld/.prettierrcnew file mode 100644index 0000000000..37d5071748--- /dev/null+++ b/packages/template-helloworld/.prettierrc@@ -0,0 +1,5 @@+{+ "useTabs": false,+ "bracketSpacing": true,+ "tabWidth": 2+}diff --git a/packages/template-helloworld/README.md b/packages/template-helloworld/README.mdnew file mode 100644index 0000000000..38c22c2df3--- /dev/null+++ b/packages/template-helloworld/README.md@@ -0,0 +1,54 @@+# Remotion video++<p align="center">+ <a href="https://github.com/remotion-dev/logo">+ <picture>+ <source media="(prefers-color-scheme: dark)" srcset="https://github.com/remotion-dev/logo/raw/main/animated-logo-banner-dark.gif">+ <img alt="Animated Remotion Logo" src="https://github.com/remotion-dev/logo/raw/main/animated-logo-banner-light.gif">+ </picture>+ </a>+</p>++Welcome to your Remotion project!++## Commands++**Install Dependencies**++```console+npm install+```++**Start Preview**++```console+npm start+```++**Render video**++```console+npm run build+```++**Upgrade Remotion**++```console+npm run upgrade+```++## 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://discord.gg/6VzzNDwUwV).++## Issues++Found an issue with Remotion? [File an issue here](https://github.com/remotion-dev/remotion/issues/new).++## 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-helloworld/package.json b/packages/template-helloworld/package.jsonnew file mode 100644index 0000000000..a25fb863e3--- /dev/null+++ b/packages/template-helloworld/package.json@@ -0,0 +1,31 @@+{+ "name": "template-helloworld",+ "version": "1.0.0",+ "description": "My Remotion video",+ "scripts": {+ "start": "remotion studio",+ "build": "remotion render HelloWorld out/video.mp4",+ "upgrade": "remotion upgrade",+ "test": "eslint src --ext ts,tsx,js,jsx && tsc"+ },+ "repository": {},+ "license": "UNLICENSED",+ "dependencies": {+ "@remotion/cli": "workspace:*",+ "@remotion/lambda": "workspace:*",+ "@remotion/zod-types": "workspace:*",+ "react": "18.3.1",+ "react-dom": "18.3.1",+ "remotion": "workspace:*",+ "zod": "3.22.3"+ },+ "devDependencies": {+ "@remotion/eslint-config": "workspace:*",+ "@types/react": "18.3.1",+ "@types/web": "0.0.78",+ "eslint": "8.56.0",+ "prettier": "3.2.5",+ "typescript": "5.3.3"+ },+ "private": true+}diff --git a/packages/template-helloworld/remotion.config.ts b/packages/template-helloworld/remotion.config.tsnew file mode 100644index 0000000000..2fb58bae46--- /dev/null+++ b/packages/template-helloworld/remotion.config.ts@@ -0,0 +1,9 @@+// 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");+Config.setOverwriteOutput(true);diff --git a/packages/template-helloworld/src/HelloWorld.tsx b/packages/template-helloworld/src/HelloWorld.tsxnew file mode 100644index 0000000000..eb108db85d--- /dev/null+++ b/packages/template-helloworld/src/HelloWorld.tsx@@ -0,0 +1,76 @@+import { spring } from "remotion";+import {+ AbsoluteFill,+ interpolate,+ Sequence,+ useCurrentFrame,+ useVideoConfig,+} from "remotion";+import { Logo } from "./HelloWorld/Logo";+import { Subtitle } from "./HelloWorld/Subtitle";+import { Title } from "./HelloWorld/Title";+import { z } from "zod";+import { zColor } from "@remotion/zod-types";++export const myCompSchema = z.object({+ titleText: z.string(),+ titleColor: zColor(),+ logoColor1: zColor(),+ logoColor2: zColor(),+});++export const HelloWorld: React.FC<z.infer<typeof myCompSchema>> = ({+ titleText: propOne,+ titleColor: propTwo,+ logoColor1,+ logoColor2,+}) => {+ const frame = useCurrentFrame();+ const { durationInFrames, fps } = useVideoConfig();++ // Animate from 0 to 1 after 25 frames+ const logoTranslationProgress = spring({+ frame: frame - 25,+ fps,+ config: {+ damping: 100,+ },+ });++ // Move the logo up by 150 pixels once the transition starts+ const logoTranslation = interpolate(+ logoTranslationProgress,+ [0, 1],+ [0, -150],+ );++ // Fade out the animation at the end+ const opacity = interpolate(+ frame,+ [durationInFrames - 25, durationInFrames - 15],+ [1, 0],+ {+ extrapolateLeft: "clamp",+ extrapolateRight: "clamp",+ },+ );++ // A <AbsoluteFill> is just a absolutely positioned <div>!+ return (+ <AbsoluteFill style={{ backgroundColor: "white" }}>+ <AbsoluteFill style={{ opacity }}>+ <AbsoluteFill style={{ transform: `translateY(${logoTranslation}px)` }}>+ <Logo logoColor1={logoColor1} logoColor2={logoColor2} />+ </AbsoluteFill>+ {/* Sequences can shift the time for its children! */}+ <Sequence from={35}>+ <Title titleText={propOne} titleColor={propTwo} />+ </Sequence>+ {/* The subtitle will only enter on the 75th frame. */}+ <Sequence from={75}>+ <Subtitle />+ </Sequence>+ </AbsoluteFill>+ </AbsoluteFill>+ );+};diff --git a/packages/template-helloworld/src/HelloWorld/Arc.tsx b/packages/template-helloworld/src/HelloWorld/Arc.tsxnew file mode 100644index 0000000000..e580b47d09--- /dev/null+++ b/packages/template-helloworld/src/HelloWorld/Arc.tsx@@ -0,0 +1,55 @@+import { useState } from "react";+import { random, useVideoConfig } from "remotion";++const getCircumferenceOfArc = (rx: number, ry: number) => {+ return Math.PI * 2 * Math.sqrt((rx * rx + ry * ry) / 2);+};++const rx = 135;+const ry = 300;+const cx = 960;+const cy = 540;+const arcLength = getCircumferenceOfArc(rx, ry);+const strokeWidth = 30;++export const Arc: React.FC<{+ progress: number;+ rotation: number;+ rotateProgress: number;+ color1: string;+ color2: string;+}> = ({ progress, rotation, rotateProgress, color1, color2 }) => {+ const { width, height } = useVideoConfig();++ // Each svg Id must be unique to not conflict with each other+ const [gradientId] = useState(() => String(random(null)));++ return (+ <svg+ viewBox={`0 0 ${width} ${height}`}+ style={{+ position: "absolute",+ transform: `rotate(${rotation * rotateProgress}deg)`,+ }}+ >+ <defs>+ <linearGradient id={gradientId} x1="0%" y1="0%" x2="0%" y2="100%">+ <stop offset="0%" stopColor={color1} />+ <stop offset="100%" stopColor={color2} />+ </linearGradient>+ </defs>+ <ellipse+ cx={cx}+ cy={cy}+ rx={rx}+ ry={ry}+ fill="none"+ stroke={`url(#${gradientId})`}+ strokeDasharray={arcLength}+ strokeDashoffset={arcLength - arcLength * progress}+ strokeLinecap="round"+ strokeWidth={strokeWidth}+ />+ </svg>+ );+};diff --git a/packages/template-helloworld/src/HelloWorld/Atom.tsx b/packages/template-helloworld/src/HelloWorld/Atom.tsxnew file mode 100644index 0000000000..5fdb507f70--- /dev/null+++ b/packages/template-helloworld/src/HelloWorld/Atom.tsx@@ -0,0 +1,36 @@+import { useState } from "react";+import { random, useVideoConfig } from "remotion";++export const Atom: React.FC<{+ scale: number;+ color1: string;+ color2: string;+}> = ({ scale, color1, color2 }) => {+ const config = useVideoConfig();++ // Each SVG ID must be unique to not conflict with each other+ const [gradientId] = useState(() => String(random(null)));++ return (+ <svg+ viewBox={`0 0 ${config.width} ${config.height}`}+ style={{+ position: "absolute",+ transform: `scale(${scale})`,+ }}+ >+ <defs>+ <linearGradient id={gradientId} x1="0%" y1="0%" x2="100%" y2="0%">+ <stop offset="0%" stopColor={color1} />+ <stop offset="100%" stopColor={color2} />+ </linearGradient>+ </defs>+ <circle+ r={70}+ cx={config.width / 2}+ cy={config.height / 2}+ fill={`url(#${gradientId})`}+ />+ </svg>+ );+};diff --git a/packages/template-helloworld/src/HelloWorld/Logo.tsx b/packages/template-helloworld/src/HelloWorld/Logo.tsxnew file mode 100644index 0000000000..00d369be7a--- /dev/null+++ b/packages/template-helloworld/src/HelloWorld/Logo.tsx@@ -0,0 +1,87 @@+import {+ AbsoluteFill,+ interpolate,+ spring,+ useCurrentFrame,+ useVideoConfig,+} from "remotion";+import { Arc } from "./Arc";+import { Atom } from "./Atom";+import { z } from "zod";+import { zColor } from "@remotion/zod-types";++export const myCompSchema2 = z.object({+ logoColor1: zColor(),+ logoColor2: zColor(),+});++export const Logo: React.FC<z.infer<typeof myCompSchema2>> = ({+ logoColor1: color1,+ logoColor2: color2,+}) => {+ const videoConfig = useVideoConfig();+ const frame = useCurrentFrame();++ const development = spring({+ config: {+ damping: 100,+ mass: 0.5,+ },+ fps: videoConfig.fps,+ frame,+ });++ const rotationDevelopment = spring({+ config: {+ damping: 100,+ mass: 0.5,+ },+ fps: videoConfig.fps,+ frame,+ });++ const scale = spring({+ frame,+ config: {+ mass: 0.5,+ },+ fps: videoConfig.fps,+ });++ const logoRotation = interpolate(+ frame,+ [0, videoConfig.durationInFrames],+ [0, 360],+ );++ return (+ <AbsoluteFill+ style={{+ transform: `scale(${scale}) rotate(${logoRotation}deg)`,+ }}+ >+ <Arc+ rotateProgress={rotationDevelopment}+ progress={development}+ rotation={30}+ color1={color1}+ color2={color2}+ />+ <Arc+ rotateProgress={rotationDevelopment}+ rotation={90}+ progress={development}+ color1={color1}+ color2={color2}+ />+ <Arc+ rotateProgress={rotationDevelopment}+ rotation={-30}+ progress={development}+ color1={color1}+ color2={color2}+ />+ <Atom scale={rotationDevelopment} color1={color1} color2={color2} />+ </AbsoluteFill>+ );+};diff --git a/packages/template-helloworld/src/HelloWorld/Subtitle.tsx b/packages/template-helloworld/src/HelloWorld/Subtitle.tsxnew file mode 100644index 0000000000..9ccbe5da78--- /dev/null+++ b/packages/template-helloworld/src/HelloWorld/Subtitle.tsx@@ -0,0 +1,26 @@+import React from "react";+import { interpolate, useCurrentFrame } from "remotion";+import { COLOR_1, FONT_FAMILY } from "./constants";++const subtitle: React.CSSProperties = {+ fontFamily: FONT_FAMILY,+ fontSize: 40,+ textAlign: "center",+ position: "absolute",+ bottom: 140,+ width: "100%",+};++const codeStyle: React.CSSProperties = {+ color: COLOR_1,+};++export const Subtitle: React.FC = () => {+ const frame = useCurrentFrame();+ const opacity = interpolate(frame, [0, 30], [0, 1]);+ return (+ <div style={{ ...subtitle, opacity }}>+ Edit <code style={codeStyle}>src/Root.tsx</code> and save to reload.+ </div>+ );+};diff --git a/packages/template-helloworld/src/HelloWorld/Title.tsx b/packages/template-helloworld/src/HelloWorld/Title.tsxnew file mode 100644index 0000000000..b4f34cde74--- /dev/null+++ b/packages/template-helloworld/src/HelloWorld/Title.tsx@@ -0,0 +1,58 @@+import React from "react";+import { spring, useCurrentFrame, useVideoConfig } from "remotion";+import { FONT_FAMILY } from "./constants";++const title: React.CSSProperties = {+ fontFamily: FONT_FAMILY,+ fontWeight: "bold",+ fontSize: 100,+ textAlign: "center",+ position: "absolute",+ bottom: 160,+ width: "100%",+};++const word: React.CSSProperties = {+ marginLeft: 10,+ marginRight: 10,+ display: "inline-block",+};++export const Title: React.FC<{+ titleText: string;+ titleColor: string;+}> = ({ titleText, titleColor }) => {+ const videoConfig = useVideoConfig();+ const frame = useCurrentFrame();++ const words = titleText.split(" ");++ return (+ <h1 style={title}>+ {words.map((t, i) => {+ const delay = i * 5;++ const scale = spring({+ fps: videoConfig.fps,+ frame: frame - delay,+ config: {+ damping: 200,+ },+ });++ return (+ <span+ key={t}+ style={{+ ...word,+ color: titleColor,+ transform: `scale(${scale})`,+ }}+ >+ {t}+ </span>+ );+ })}+ </h1>+ );+};diff --git a/packages/template-helloworld/src/HelloWorld/constants.ts b/packages/template-helloworld/src/HelloWorld/constants.tsnew file mode 100644index 0000000000..e20c050a54--- /dev/null+++ b/packages/template-helloworld/src/HelloWorld/constants.ts@@ -0,0 +1,5 @@+// Change any of these to update your video live.++export const COLOR_1 = "#86A8E7";++export const FONT_FAMILY = "SF Pro Text, Helvetica, Arial, sans-serif";diff --git a/packages/template-helloworld/src/Root.tsx b/packages/template-helloworld/src/Root.tsxnew file mode 100644index 0000000000..7a09caa656--- /dev/null+++ b/packages/template-helloworld/src/Root.tsx@@ -0,0 +1,46 @@+import { Composition } from "remotion";+import { HelloWorld, myCompSchema } from "./HelloWorld";+import { Logo, myCompSchema2 } from "./HelloWorld/Logo";++// Each <Composition> is an entry in the sidebar!++export const RemotionRoot: React.FC = () => {+ return (+ <>+ <Composition+ // You can take the "id" to render a video:+ // npx remotion render src/index.ts <id> out/video.mp4+ id="HelloWorld"+ component={HelloWorld}+ durationInFrames={150}+ fps={30}+ width={1920}+ height={1080}+ // You can override these props for each render:+ // https://www.remotion.dev/docs/parametrized-rendering+ schema={myCompSchema}+ defaultProps={{+ titleText: "Welcome to Remotion",+ titleColor: "#000000",+ logoColor1: "#91EAE4",+ logoColor2: "#86A8E7",+ }}+ />++ {/* Mount any React component to make it show up in the sidebar and work on it individually! */}+ <Composition+ id="OnlyLogo"+ component={Logo}+ durationInFrames={150}+ fps={30}+ width={1920}+ height={1080}+ schema={myCompSchema2}+ defaultProps={{+ logoColor1: "#91dAE2" as const,+ logoColor2: "#86A8E7" as const,+ }}+ />+ </>+ );+};diff --git a/packages/template-helloworld/src/index.ts b/packages/template-helloworld/src/index.tsnew file mode 100644index 0000000000..14dff4c457--- /dev/null+++ b/packages/template-helloworld/src/index.ts@@ -0,0 +1,7 @@+// This is your entry file! Refer to it when you render:+// npx remotion render <entry-file> HelloWorld out/video.mp4++import { registerRoot } from "remotion";+import { RemotionRoot } from "./Root";++registerRoot(RemotionRoot);diff --git a/packages/template-helloworld/tsconfig.json b/packages/template-helloworld/tsconfig.jsonnew file mode 100644index 0000000000..bb881cc903--- /dev/null+++ b/packages/template-helloworld/tsconfig.json@@ -0,0 +1,15 @@+{+ "compilerOptions": {+ "target": "ES2018",+ "module": "commonjs",+ "jsx": "react-jsx",+ "outDir": "./dist",+ "strict": true,+ "noEmit": true,+ "lib": ["es2015"],+ "esModuleInterop": true,+ "skipLibCheck": true,+ "forceConsistentCasingInFileNames": true,+ "noUnusedLocals": true+ }+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 04988cea3f..73e2b9846a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1641,6 +1641,49 @@ importers:specifier: 5.3.3version: 5.3.3+ packages/template-helloworld:+ dependencies:+ '@remotion/cli':+ specifier: workspace:*+ version: link:../cli+ '@remotion/lambda':+ specifier: workspace:*+ version: link:../lambda+ '@remotion/zod-types':+ specifier: workspace:*+ version: link:../zod-types+ 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/react':+ specifier: 18.3.1+ version: 18.3.1+ '@types/web':+ specifier: 0.0.78+ version: 0.0.78+ eslint:+ specifier: 8.56.0+ version: 8.56.0+ prettier:+ specifier: 3.2.5+ version: 3.2.5+ typescript:+ specifier: 5.3.3+ version: 5.3.3+packages/test-utils:devDependencies:react:@@ -12085,6 +12128,13 @@ packages:dependencies:acorn: 8.11.3+ resolution: {integrity: sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ==}+ peerDependencies:+ acorn: ^8+ dependencies:+ acorn: 8.12.1+resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}peerDependencies:@@ -25040,8 +25090,8 @@ packages:'@webassemblyjs/ast': 1.12.1'@webassemblyjs/wasm-edit': 1.12.1'@webassemblyjs/wasm-parser': 1.12.1- acorn: 8.11.3- acorn-import-attributes: 1.9.5([email protected])+ acorn: 8.12.1+ acorn-import-attributes: 1.9.5([email protected])browserslist: 4.23.2chrome-trace-event: 1.0.3enhanced-resolve: 5.17.1diff --git a/tsconfig.json b/tsconfig.jsonindex 887203a38e..5f7be48126 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -117,6 +117,9 @@{"path": "./packages/template-blank"},+ {+ "path": "./packages/template-helloworld"+ },{"path": "./packages/studio"},