Skip to content

🎥 Make videos programmatically with React

add template-javascript

Jonny Burger10fec4e38075
diff --git a/packages/create-video/src/templates.tsx b/packages/create-video/src/templates.tsx
index ce7dec33b3..907cc3a4be 100644
--- a/packages/create-video/src/templates.tsx
+++ b/packages/create-video/src/templates.tsx
@@ -182,7 +182,7 @@ export const FEATURED_TEMPLATES: Template[] = [
featuredOnHomePage: 'JavaScript',
previewURL:
'https://template-helloworld-javascript.vercel.app/?/HelloWorld',
- templateInMonorepo: null,
+ templateInMonorepo: 'template-javascript',
allowEnableTailwind: false,
},
{
diff --git a/packages/template-javascript/.gitignore b/packages/template-javascript/.gitignore
new file mode 100644
index 0000000000..4beb836bb8
--- /dev/null
+++ b/packages/template-javascript/.gitignore
@@ -0,0 +1,6 @@
+node_modules
+dist
+.DS_Store
+.env
+
+out
diff --git a/packages/template-javascript/.prettierrc b/packages/template-javascript/.prettierrc
new file mode 100644
index 0000000000..842bfb78cb
--- /dev/null
+++ b/packages/template-javascript/.prettierrc
@@ -0,0 +1,13 @@
+{
+ "singleQuote": true,
+ "bracketSpacing": false,
+ "useTabs": true,
+ "overrides": [
+ {
+ "files": ["*.yml"],
+ "options": {
+ "singleQuote": false
+ }
+ }
+ ]
+}
diff --git a/packages/template-javascript/README.md b/packages/template-javascript/README.md
new file mode 100644
index 0000000000..a2da46a1ed
--- /dev/null
+++ b/packages/template-javascript/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/JonnyBurger/remotion/issues/new).
+
+## License
+
+Note that for some entities a company license is needed. [Read the terms here](https://github.com/JonnyBurger/remotion/blob/main/LICENSE.md).
diff --git a/packages/template-javascript/package.json b/packages/template-javascript/package.json
new file mode 100644
index 0000000000..c017a8cb5f
--- /dev/null
+++ b/packages/template-javascript/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "template-javascript",
+ "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"
+ },
+ "repository": {},
+ "license": "UNLICENSED",
+ "dependencies": {
+ "@remotion/cli": "workspace:*",
+ "react": "18.3.1",
+ "react-dom": "18.3.1",
+ "remotion": "workspace:*",
+ "zod": "3.22.3"
+ },
+ "devDependencies": {
+ "prettier": "3.2.5"
+ },
+ "private": true
+}
diff --git a/packages/template-javascript/remotion.config.js b/packages/template-javascript/remotion.config.js
new file mode 100644
index 0000000000..38db4bfd3c
--- /dev/null
+++ b/packages/template-javascript/remotion.config.js
@@ -0,0 +1,8 @@
+// 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-javascript/src/HelloWorld/Arc.jsx b/packages/template-javascript/src/HelloWorld/Arc.jsx
new file mode 100644
index 0000000000..0bbd147cba
--- /dev/null
+++ b/packages/template-javascript/src/HelloWorld/Arc.jsx
@@ -0,0 +1,50 @@
+import {useState} from 'react';
+import {random, useVideoConfig} from 'remotion';
+import {COLOR_1, COLOR_2} from './constants';
+
+const getCircumferenceOfArc = (rx, ry) => {
+ 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 = ({progress, rotation, rotateProgress}) => {
+ 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={COLOR_1} />
+ <stop offset="100%" stopColor={COLOR_2} />
+ </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-javascript/src/HelloWorld/Atom.jsx b/packages/template-javascript/src/HelloWorld/Atom.jsx
new file mode 100644
index 0000000000..e49a577470
--- /dev/null
+++ b/packages/template-javascript/src/HelloWorld/Atom.jsx
@@ -0,0 +1,33 @@
+import {useState} from 'react';
+import {random, useVideoConfig} from 'remotion';
+import {COLOR_1, COLOR_2} from './constants';
+
+export const Atom = ({scale}) => {
+ 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={COLOR_1} />
+ <stop offset="100%" stopColor={COLOR_2} />
+ </linearGradient>
+ </defs>
+ <circle
+ r={70}
+ cx={config.width / 2}
+ cy={config.height / 2}
+ fill={`url(#${gradientId})`}
+ />
+ </svg>
+ );
+};
diff --git a/packages/template-javascript/src/HelloWorld/Logo.jsx b/packages/template-javascript/src/HelloWorld/Logo.jsx
new file mode 100644
index 0000000000..867cbf45a9
--- /dev/null
+++ b/packages/template-javascript/src/HelloWorld/Logo.jsx
@@ -0,0 +1,71 @@
+import {
+ AbsoluteFill,
+ interpolate,
+ spring,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+import {Arc} from './Arc';
+import {Atom} from './Atom';
+
+export const Logo = () => {
+ 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}
+ />
+ <Arc
+ rotateProgress={rotationDevelopment}
+ rotation={90}
+ progress={development}
+ />
+ <Arc
+ rotateProgress={rotationDevelopment}
+ rotation={-30}
+ progress={development}
+ />
+ <Atom scale={rotationDevelopment} />
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/template-javascript/src/HelloWorld/Subtitle.jsx b/packages/template-javascript/src/HelloWorld/Subtitle.jsx
new file mode 100644
index 0000000000..e648b06d8c
--- /dev/null
+++ b/packages/template-javascript/src/HelloWorld/Subtitle.jsx
@@ -0,0 +1,26 @@
+import React from 'react';
+import {interpolate, useCurrentFrame} from 'remotion';
+import {COLOR_1, FONT_FAMILY} from './constants';
+
+const subtitle = {
+ fontFamily: FONT_FAMILY,
+ fontSize: 40,
+ textAlign: 'center',
+ position: 'absolute',
+ bottom: 140,
+ width: '100%',
+};
+
+const codeStyle = {
+ color: COLOR_1,
+};
+
+export const Subtitle = () => {
+ const frame = useCurrentFrame();
+ const opacity = interpolate(frame, [0, 30], [0, 1]);
+ return (
+ <div style={{...subtitle, opacity}}>
+ Edit <code style={codeStyle}>src/Root.jsx</code> and save to reload.
+ </div>
+ );
+};
diff --git a/packages/template-javascript/src/HelloWorld/Title.jsx b/packages/template-javascript/src/HelloWorld/Title.jsx
new file mode 100644
index 0000000000..0bb50ec581
--- /dev/null
+++ b/packages/template-javascript/src/HelloWorld/Title.jsx
@@ -0,0 +1,55 @@
+import React from 'react';
+import {spring, useCurrentFrame, useVideoConfig} from 'remotion';
+import {FONT_FAMILY} from './constants';
+
+const title = {
+ fontFamily: FONT_FAMILY,
+ fontWeight: 'bold',
+ fontSize: 100,
+ textAlign: 'center',
+ position: 'absolute',
+ bottom: 160,
+ width: '100%',
+};
+
+const word = {
+ marginLeft: 10,
+ marginRight: 10,
+ display: 'inline-block',
+};
+
+export const Title = ({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-javascript/src/HelloWorld/constants.js b/packages/template-javascript/src/HelloWorld/constants.js
new file mode 100644
index 0000000000..8c0fff4ca1
--- /dev/null
+++ b/packages/template-javascript/src/HelloWorld/constants.js
@@ -0,0 +1,6 @@
+// Change any of these to update your video live.
+
+export const COLOR_1 = '#86A8E7';
+export const COLOR_2 = '#91EAE4';
+
+export const FONT_FAMILY = 'SF Pro Text, Helvetica, Arial, sans-serif';
diff --git a/packages/template-javascript/src/HelloWorld/index.jsx b/packages/template-javascript/src/HelloWorld/index.jsx
new file mode 100644
index 0000000000..06bef74950
--- /dev/null
+++ b/packages/template-javascript/src/HelloWorld/index.jsx
@@ -0,0 +1,62 @@
+import {spring} from 'remotion';
+import {
+ AbsoluteFill,
+ interpolate,
+ Sequence,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
+import {Logo} from './Logo';
+import {Subtitle} from './Subtitle';
+import {Title} from './Title';
+
+export const HelloWorld = ({titleText, titleColor}) => {
+ 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 />
+ </AbsoluteFill>
+ {/* Sequences can shift the time for its children! */}
+ <Sequence from={35}>
+ <Title titleText={titleText} titleColor={titleColor} />
+ </Sequence>
+ {/* The subtitle will only enter on the 75th frame. */}
+ <Sequence from={75}>
+ <Subtitle />
+ </Sequence>
+ </AbsoluteFill>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/template-javascript/src/Root.jsx b/packages/template-javascript/src/Root.jsx
new file mode 100644
index 0000000000..d07ea2bf04
--- /dev/null
+++ b/packages/template-javascript/src/Root.jsx
@@ -0,0 +1,37 @@
+import {Composition} from 'remotion';
+import {HelloWorld} from './HelloWorld';
+import {Logo} from './HelloWorld/Logo';
+
+// Each <Composition> is an entry in the sidebar!
+
+export const RemotionRoot = () => {
+ return (
+ <>
+ <Composition
+ // You can take the "id" to render a video:
+ // npx remotion render src/index.jsx <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
+ defaultProps={{
+ titleText: 'Welcome to Remotion',
+ titleColor: 'black',
+ }}
+ />
+ {/* 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}
+ />
+ </>
+ );
+};
diff --git a/packages/template-javascript/src/index.js b/packages/template-javascript/src/index.js
new file mode 100644
index 0000000000..8f5deb6df8
--- /dev/null
+++ b/packages/template-javascript/src/index.js
@@ -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/pnpm-lock.yaml b/pnpm-lock.yaml
index 7522a35a07..6d278fec70 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1681,6 +1681,28 @@ importers:
specifier: 5.3.3
version: 5.3.3
+ packages/template-javascript:
+ dependencies:
+ '@remotion/cli':
+ specifier: workspace:*
+ version: link:../cli
+ 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:
+ prettier:
+ specifier: 3.2.5
+ version: 3.2.5
+
packages/template-next-app:
dependencies:
'@remotion/bundler':