🎥 Make videos programmatically with React
nice
Jonny Burgeraa47d9b35722
diff --git a/packages/example/src/3DContext/path-context.tsx b/packages/example/src/3DContext/path-context.tsxindex 2eb0937a27..fd7a73a21b 100644--- a/packages/example/src/3DContext/path-context.tsx+++ b/packages/example/src/3DContext/path-context.tsx@@ -19,7 +19,8 @@ export const RectProvider: React.FC<{readonly cornerRadius: number;readonly children: React.ReactNode;}> = ({cornerRadius, height, width, children}) => {- const {path} = makeRect({height, width, cornerRadius});+ const maxCornerRadius = Math.min(cornerRadius, width / 2, height / 2);+ const {path} = makeRect({height, width, cornerRadius: maxCornerRadius});const viewBox = `0 0 ${width} ${height}`;diff --git a/packages/example/src/Compose/AtRemotionButton.tsx b/packages/example/src/Compose/AtRemotionButton.tsxnew file mode 100644index 0000000000..046f2e1205--- /dev/null+++ b/packages/example/src/Compose/AtRemotionButton.tsx@@ -0,0 +1,16 @@+import {AbsoluteFill} from 'remotion';++export const AtRemotionButton: React.FC = () => {+ return (+ <AbsoluteFill className="bg-black justify-center items-center border-2 border-solid border-white rounded-full">+ <div+ className="text-white text-3xl font-brand"+ style={{+ fontFamily: 'GT Planar',+ }}+ >+ @remotion+ </div>+ </AbsoluteFill>+ );+};diff --git a/packages/example/src/Compose/Compose.tsx b/packages/example/src/Compose/Compose.tsxindex 8699ec89dc..6bb2fa6eab 100644--- a/packages/example/src/Compose/Compose.tsx+++ b/packages/example/src/Compose/Compose.tsx@@ -241,7 +241,7 @@ export const Compose = () => {config: {damping: 200,},- delay: 220,+ delay: 250,durationInFrames: 20,});@@ -299,24 +299,34 @@ export const Compose = () => {</RotateY></TranslateX>)}- <TranslateX px={secondX}>- <AbsoluteFill- style={{- justifyContent: 'center',- alignItems: 'center',- }}- >- <div+ <AbsoluteFill+ style={{+ maskImage: 'linear-gradient(to bottom, transparent , black 10%)',+ }}+ >+ <TranslateX px={secondX}>+ <AbsoluteFillstyle={{- width: width,- height: height,- position: 'relative',+ justifyContent: 'center',+ alignItems: 'center',}}>- {endCard ? <EndCard cornerRadius={cornerRadius}></EndCard> : null}- </div>- </AbsoluteFill>- </TranslateX>+ <Sequence layout="none" from={100}>+ <div+ style={{+ width: width,+ height: height,+ position: 'relative',+ }}+ >+ {endCard ? (+ <EndCard cornerRadius={cornerRadius}></EndCard>+ ) : null}+ </div>+ </Sequence>+ </AbsoluteFill>+ </TranslateX>+ </AbsoluteFill><TranslateY px={190}><TranslateZ px={-depth * 2 + liftCaptions}><CaptionLayers delay={animationStart} />diff --git a/packages/example/src/Compose/EndCard.tsx b/packages/example/src/Compose/EndCard.tsxindex dce55b4a69..a247816814 100644--- a/packages/example/src/Compose/EndCard.tsx+++ b/packages/example/src/Compose/EndCard.tsx@@ -1,16 +1,20 @@-import React from 'react';+import React, {useContext} from 'react';import {AbsoluteFill} from 'remotion';import {ExtrudeDiv} from '../3DContext/Div3D';import {TranslateX, TranslateY} from '../3DContext/transformation-context';+import {AtRemotionButton} from './AtRemotionButton';+import {DepthContext, JumpThenDisappear} from './JumpThenDisappear';import {Rotations} from './Rotations';const Item: React.FC<{cornerRadius: number;children: React.ReactNode;}> = ({cornerRadius, children}) => {+ const context = useContext(DepthContext);+return (<Rotations zIndexHack={false} delay={0}>- <ExtrudeDiv width={150} height={150} depth={40} cornerRadius={10}>+ <ExtrudeDiv width={150} height={150} depth={context} cornerRadius={10}><AbsoluteFillclassName="bg-white justify-center items-center"style={{@@ -29,12 +33,14 @@ const CallToAction: React.FC<{cornerRadius: number;children: React.ReactNode;}> = ({cornerRadius, children}) => {+ const depth = useContext(DepthContext);+return (<Rotations zIndexHack={false} delay={0}><ExtrudeDiv- width={400}- height={150}- depth={40}+ width={300}+ height={100}+ depth={depth}cornerRadius={cornerRadius}><AbsoluteFill@@ -42,6 +48,7 @@ const CallToAction: React.FC<{style={{borderRadius: cornerRadius,border: '3px solid black',+ overflow: 'hidden',}}>{children}@@ -60,63 +67,73 @@ export const EndCard: React.FC<{borderRadius: 10,}}>- <TranslateX px={-40}>- <TranslateY px={70}>- <div className="flex flex-row">- <div style={{position: 'absolute'}}>+ <div className="flex flex-row">+ <TranslateX px={220}>+ <div style={{position: 'absolute'}}>+ <JumpThenDisappear delay={2}><Item cornerRadius={cornerRadius}>- <svg style={{height: 70}} viewBox="0 0 448 512">- <path d="M448 209.9a210.1 210.1 0 0 1 -122.8-39.3V349.4A162.6 162.6 0 1 1 185 188.3V278.2a74.6 74.6 0 1 0 52.2 71.2V0l88 0a121.2 121.2 0 0 0 1.9 22.2h0A122.2 122.2 0 0 0 381 102.4a121.4 121.4 0 0 0 67 20.1z" />+ <svg+ style={{height: 70}}+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 448 512"+ >+ <path d="M224.1 141c-63.6 0-114.9 51.3-114.9 114.9s51.3 114.9 114.9 114.9S339 319.5 339 255.9 287.7 141 224.1 141zm0 189.6c-41.1 0-74.7-33.5-74.7-74.7s33.5-74.7 74.7-74.7 74.7 33.5 74.7 74.7-33.6 74.7-74.7 74.7zm146.4-194.3c0 14.9-12 26.8-26.8 26.8-14.9 0-26.8-12-26.8-26.8s12-26.8 26.8-26.8 26.8 12 26.8 26.8zm76.1 27.2c-1.7-35.9-9.9-67.7-36.2-93.9-26.2-26.2-58-34.4-93.9-36.2-37-2.1-147.9-2.1-184.9 0-35.8 1.7-67.6 9.9-93.9 36.1s-34.4 58-36.2 93.9c-2.1 37-2.1 147.9 0 184.9 1.7 35.9 9.9 67.7 36.2 93.9s58 34.4 93.9 36.2c37 2.1 147.9 2.1 184.9 0 35.9-1.7 67.7-9.9 93.9-36.2 26.2-26.2 34.4-58 36.2-93.9 2.1-37 2.1-147.8 0-184.8zM398.8 388c-7.8 19.6-22.9 34.7-42.6 42.6-29.5 11.7-99.5 9-132.1 9s-102.7 2.6-132.1-9c-19.6-7.8-34.7-22.9-42.6-42.6-11.7-29.5-9-99.5-9-132.1s-2.6-102.7 9-132.1c7.8-19.6 22.9-34.7 42.6-42.6 29.5-11.7 99.5-9 132.1-9s102.7-2.6 132.1 9c19.6 7.8 34.7 22.9 42.6 42.6 11.7 29.5 9 99.5 9 132.1s2.7 102.7-9 132.1z" /></svg></Item>- </div>- <TranslateX px={220}>- <div style={{position: 'absolute'}}>- <Item cornerRadius={cornerRadius}>- <svg- style={{height: 70}}- xmlns="http://www.w3.org/2000/svg"- viewBox="0 0 448 512"- >- <path d="M224.1 141c-63.6 0-114.9 51.3-114.9 114.9s51.3 114.9 114.9 114.9S339 319.5 339 255.9 287.7 141 224.1 141zm0 189.6c-41.1 0-74.7-33.5-74.7-74.7s33.5-74.7 74.7-74.7 74.7 33.5 74.7 74.7-33.6 74.7-74.7 74.7zm146.4-194.3c0 14.9-12 26.8-26.8 26.8-14.9 0-26.8-12-26.8-26.8s12-26.8 26.8-26.8 26.8 12 26.8 26.8zm76.1 27.2c-1.7-35.9-9.9-67.7-36.2-93.9-26.2-26.2-58-34.4-93.9-36.2-37-2.1-147.9-2.1-184.9 0-35.8 1.7-67.6 9.9-93.9 36.1s-34.4 58-36.2 93.9c-2.1 37-2.1 147.9 0 184.9 1.7 35.9 9.9 67.7 36.2 93.9s58 34.4 93.9 36.2c37 2.1 147.9 2.1 184.9 0 35.9-1.7 67.7-9.9 93.9-36.2 26.2-26.2 34.4-58 36.2-93.9 2.1-37 2.1-147.8 0-184.8zM398.8 388c-7.8 19.6-22.9 34.7-42.6 42.6-29.5 11.7-99.5 9-132.1 9s-102.7 2.6-132.1-9c-19.6-7.8-34.7-22.9-42.6-42.6-11.7-29.5-9-99.5-9-132.1s-2.6-102.7 9-132.1c7.8-19.6 22.9-34.7 42.6-42.6 29.5-11.7 99.5-9 132.1-9s102.7-2.6 132.1 9c19.6 7.8 34.7 22.9 42.6 42.6 11.7 29.5 9 99.5 9 132.1s2.7 102.7-9 132.1z" />- </svg>- </Item>- </div>- </TranslateX>- <TranslateY px={220}>- <div style={{position: 'absolute'}}>+ </JumpThenDisappear>+ </div>+ </TranslateX>+ <TranslateY px={220}>+ <TranslateX px={220}>+ <div style={{position: 'absolute'}}>+ <JumpThenDisappear delay={6}><Item cornerRadius={cornerRadius}>- <svg- style={{height: 70}}- xmlns="http://www.w3.org/2000/svg"- viewBox="0 0 576 512"- >- <path d="M549.7 124.1c-6.3-23.7-24.8-42.3-48.3-48.6C458.8 64 288 64 288 64S117.2 64 74.6 75.5c-23.5 6.3-42 24.9-48.3 48.6-11.4 42.9-11.4 132.3-11.4 132.3s0 89.4 11.4 132.3c6.3 23.7 24.8 41.5 48.3 47.8C117.2 448 288 448 288 448s170.8 0 213.4-11.5c23.5-6.3 42-24.2 48.3-47.8 11.4-42.9 11.4-132.3 11.4-132.3s0-89.4-11.4-132.3zm-317.5 213.5V175.2l142.7 81.2-142.7 81.2z" />+ <svg style={{height: 70}} viewBox="0 0 512 512">+ <path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z" /></svg></Item>- </div>- </TranslateY>- <TranslateY px={220}>- <TranslateX px={220}>- <div style={{position: 'absolute'}}>- <Item cornerRadius={cornerRadius}>- <svg style={{height: 70}} viewBox="0 0 512 512">- <path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z" />- </svg>- </Item>- </div>- </TranslateX>- </TranslateY>- <TranslateY px={550}>- <TranslateX px={110}>- <div style={{position: 'absolute'}}>- <CallToAction cornerRadius={75} children />- </div>- </TranslateX>- </TranslateY>+ </JumpThenDisappear>+ </div>+ </TranslateX>+ </TranslateY>+ <div style={{position: 'absolute'}}>+ <JumpThenDisappear delay={0}>+ <Item cornerRadius={cornerRadius}>+ <svg style={{height: 70}} viewBox="0 0 448 512">+ <path d="M448 209.9a210.1 210.1 0 0 1 -122.8-39.3V349.4A162.6 162.6 0 1 1 185 188.3V278.2a74.6 74.6 0 1 0 52.2 71.2V0l88 0a121.2 121.2 0 0 0 1.9 22.2h0A122.2 122.2 0 0 0 381 102.4a121.4 121.4 0 0 0 67 20.1z" />+ </svg>+ </Item>+ </JumpThenDisappear>+ </div>++ <TranslateY px={220}>+ <div style={{position: 'absolute'}}>+ <JumpThenDisappear delay={4}>+ <Item cornerRadius={cornerRadius}>+ <svg+ style={{height: 70}}+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 576 512"+ >+ <path d="M549.7 124.1c-6.3-23.7-24.8-42.3-48.3-48.6C458.8 64 288 64 288 64S117.2 64 74.6 75.5c-23.5 6.3-42 24.9-48.3 48.6-11.4 42.9-11.4 132.3-11.4 132.3s0 89.4 11.4 132.3c6.3 23.7 24.8 41.5 48.3 47.8C117.2 448 288 448 288 448s170.8 0 213.4-11.5c23.5-6.3 42-24.2 48.3-47.8 11.4-42.9 11.4-132.3 11.4-132.3s0-89.4-11.4-132.3zm-317.5 213.5V175.2l142.7 81.2-142.7 81.2z" />+ </svg>+ </Item>+ </JumpThenDisappear></div></TranslateY>- </TranslateX>++ <TranslateY px={550}>+ <TranslateX px={110}>+ <div style={{position: 'absolute'}}>+ <JumpThenDisappear delay={8}>+ <CallToAction cornerRadius={75}>+ <AtRemotionButton />+ </CallToAction>+ </JumpThenDisappear>+ </div>+ </TranslateX>+ </TranslateY>+ </div></AbsoluteFill>);};diff --git a/packages/example/src/Compose/JumpThenDisappear.tsx b/packages/example/src/Compose/JumpThenDisappear.tsxnew file mode 100644index 0000000000..26e0d856dd--- /dev/null+++ b/packages/example/src/Compose/JumpThenDisappear.tsx@@ -0,0 +1,56 @@+import {createContext} from 'react';+import {interpolate, spring, useCurrentFrame, useVideoConfig} from 'remotion';+import {+ TranslateX,+ TranslateY,+ TranslateZ,+} from '../3DContext/transformation-context';++export const takeOffSpeedFucntion = (f: number) =>+ 10 ** interpolate(f, [0, 120], [-1, 4]);++export const remapSpeed = (frame: number, speed: (fr: number) => number) => {+ let framesPassed = 0;+ for (let i = 0; i <= frame; i++) {+ framesPassed += speed(i);+ }++ return framesPassed;+};++export const JumpThenDisappear: React.FC<{+ children: React.ReactNode;+ delay: number;+}> = ({children, delay}) => {+ const {fps} = useVideoConfig();+ const frame = useCurrentFrame();++ const acceleratedFrame = remapSpeed(+ frame - 130 - delay,+ takeOffSpeedFucntion,+ );++ const translateZ = interpolate(acceleratedFrame, [0, 30], [0, -1400]);++ const depth = Math.max(+ 0.01,+ spring({+ fps,+ frame,+ delay: 87 + delay,+ durationInFrames: 20,+ }) * 40,+ );++ return (+ <TranslateX px={-40}>+ <TranslateY px={70}>+ <TranslateZ px={translateZ}>+ <DepthContext value={depth}>{children}</DepthContext>+ </TranslateZ>+ </TranslateY>+ </TranslateX>+ );+};++export const DepthContext = createContext<number>(0);diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex a51532698a..2ad3d2e6c7 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -1525,7 +1525,7 @@ export const Index: React.FC = () => {width={1080}height={1080}fps={30}- durationInFrames={240}+ durationInFrames={273}/><Compositionid="3DContext"diff --git a/packages/example/src/style.css b/packages/example/src/style.cssindex d4b5078586..5633b0a1e5 100644--- a/packages/example/src/style.css+++ b/packages/example/src/style.css@@ -1 +1,6 @@@import 'tailwindcss';++@theme inline {+ --color-brand: #0b84f3;+ --font-brand: 'GT Planar', sans-serif;+}