🎥 Make videos programmatically with React
implement rendering
Jonny Burger9dab4ac038b2
diff --git a/packages/docs/src/components/Demo/Demo.tsx b/packages/docs/src/components/Demo/Demo.tsxindex f4188d61b2..27fa1629f7 100644--- a/packages/docs/src/components/Demo/Demo.tsx+++ b/packages/docs/src/components/Demo/Demo.tsx@@ -21,6 +21,7 @@ import {getDataAndProps,} from '../../remotion/HomepageVideo/Comp';import {ActionRow} from './ActionRow';+import {RenderButton} from './DemoRender';import {PlayerControls} from './PlayerControls';preloadAudio(staticFile('Utope-nature-5s.mp3'));@@ -84,10 +85,8 @@ export const Demo: React.FC = () => {},cardOrder,updateCardOrder,- playerData: {- location: data?.location ?? null,- trending: data?.trending ?? null,- },+ location: data?.location ?? null,+ trending: data?.trending ?? null,onClickLeft: () => {setEmojiIndex((e) => e - 1);},@@ -121,6 +120,15 @@ export const Demo: React.FC = () => {/><PlayerControls playerRef={ref} durationInFrames={120} fps={30} /></div>+ {data ? (+ <RenderButton+ cardOrder={cardOrder}+ emojiIndex={emojiIndex}+ location={data.location!}+ theme={colorMode}+ trending={data.trending!}+ />+ ) : null}</div>);};diff --git a/packages/docs/src/components/Demo/DemoRender.tsx b/packages/docs/src/components/Demo/DemoRender.tsxnew file mode 100644index 0000000000..12162bb907--- /dev/null+++ b/packages/docs/src/components/Demo/DemoRender.tsx@@ -0,0 +1,92 @@+import type {EnhancedErrorInfo} from '@remotion/lambda';+import React, {useCallback} from 'react';+import {z} from 'zod';++const countryPath = z.object({+ d: z.string(),+ class: z.string(),+});++const remoteData = z.object({+ repos: z.array(z.string()),+ date: z.string(),+ temperatureInCelsius: z.number(),+ countryLabel: z.string(),+ countryPaths: z.array(countryPath),+});++const location = z.object({+ country: z.string(),+ city: z.string(),+ latitude: z.number(),+ longitude: z.number(),+});++const data = z.object({+ trending: remoteData,+ location,+ emojiIndex: z.number(),+ theme: z.enum(['light', 'dark']),+ cardOrder: z.array(z.number()),+});++type State =+ | {+ type: 'idle';+ }+ | {+ type: 'invoking';+ }+ | {+ type: 'progress';+ progress: number;+ }+ | {+ type: 'done';+ };++export const RenderButton: React.FC<z.infer<typeof data>> = (props) => {+ const [state, setState] = React.useState<State>({type: 'idle'});++ const triggerRender = useCallback(async () => {+ setState({type: 'invoking'});++ const {renderId, bucketName} = await (+ await fetch('http://localhost:4000/render', {+ method: 'post',+ headers: {'content-type': 'application/json'},+ body: JSON.stringify(props),+ })+ ).json();+ console.log({renderId, bucketName});+ let done = false;++ while (!done) {+ const progress = (await (+ await fetch('http://localhost:4000/progress', {+ method: 'post',+ headers: {'content-type': 'application/json'},+ body: JSON.stringify({renderId, bucketName}),+ })+ ).json()) as {+ overallProgress: number;+ outputFile: string | null;+ errors: EnhancedErrorInfo[];+ fatalErrorEncountered: boolean;+ };++ console.log({progress});+ if (progress.outputFile || progress.fatalErrorEncountered) {+ done = true;+ }+ }++ setState({type: 'progress', progress: 0});+ }, [props]);++ return (+ <button type="button" onClick={triggerRender}>+ Render lol+ </button>+ );+};diff --git a/packages/docs/src/remotion/HomepageVideo/Comp.tsx b/packages/docs/src/remotion/HomepageVideo/Comp.tsxindex 759c8e910b..b21d4a1ac4 100644--- a/packages/docs/src/remotion/HomepageVideo/Comp.tsx+++ b/packages/docs/src/remotion/HomepageVideo/Comp.tsx@@ -24,8 +24,8 @@ export type RemoteData = {};export type LocationAndTrending = {- location: Location | null;- trending: RemoteData | null;+ readonly location: Location | null;+ readonly trending: RemoteData | null;};export const getDataAndProps = async () => {@@ -72,7 +72,6 @@ export const calculateMetadata: CalculateMetadataFunction<};export type DemoPlayerProps = {- readonly playerData: LocationAndTrending;readonly onToggle: () => void;readonly cardOrder: number[];readonly updateCardOrder: (newCardOrder: number[]) => void;@@ -80,7 +79,7 @@ export type DemoPlayerProps = {readonly onClickLeft: () => void;readonly onClickRight: () => void;readonly emojiIndex: number;-};+} & LocationAndTrending;const fireAudio = staticFile('fire.mp3');const partyHornAudio = staticFile('partyhorn.mp3');@@ -91,7 +90,8 @@ export const HomepageVideoComp: React.FC<DemoPlayerProps> = ({onToggle,cardOrder,updateCardOrder,- playerData,+ location,+ trending,emojiIndex,onClickLeft,onClickRight,@@ -156,7 +156,8 @@ export const HomepageVideoComp: React.FC<DemoPlayerProps> = ({onUpdate={onUpdate}indices={cardOrder}theme={theme}- data={playerData}+ location={location}+ trending={trending}onToggle={onToggle}onLeft={onClickLeft}onRight={onClickRight}diff --git a/packages/docs/src/remotion/HomepageVideo/cards/Cards.tsx b/packages/docs/src/remotion/HomepageVideo/cards/Cards.tsxindex 2d2ebf4168..ac63b2feee 100644--- a/packages/docs/src/remotion/HomepageVideo/cards/Cards.tsx+++ b/packages/docs/src/remotion/HomepageVideo/cards/Cards.tsx@@ -7,12 +7,13 @@ import React, {useState,} from 'react';import {AbsoluteFill, getRemotionEnvironment} from 'remotion';-import type {LocationAndTrending} from '../Comp';+import type {RemoteData} from '../Comp';import {CurrentCountry} from '../CurrentCountry';import {Temperature} from '../Temperature';import {TrendingRepos} from '../TrendingRepos';import type {EmojiCardRef} from '../emoji/EmojiCard';import {EmojiCard} from '../emoji/EmojiCard';+import type {Location} from '../types';import {Card} from './Card';import {getInitialPositions} from './math';@@ -20,7 +21,8 @@ export const Cards: React.FC<{readonly onUpdate: (newIndices: number[]) => void;readonly indices: number[];readonly theme: 'dark' | 'light';- readonly data: LocationAndTrending;+ readonly location: Location | null;+ readonly trending: RemoteData | null;readonly onToggle: () => void;readonly onLeft: () => void;readonly onRight: () => void;@@ -30,10 +32,11 @@ export const Cards: React.FC<{indices,theme,onToggle,- data,onLeft: onLeftPress,onRight: onRightPress,emojiName,+ location,+ trending,}) => {const container = useRef<HTMLDivElement>(null);@@ -86,17 +89,17 @@ export const Cards: React.FC<{const index = indices[i];const content =index === 0 ? (- <TrendingRepos trending={data.trending} theme={theme} />+ <TrendingRepos trending={trending} theme={theme} />) : index === 1 ? (<Temperature- city={data.location?.city ?? null}+ city={location?.city ?? null}theme={theme}- temperatureInCelsius={data.trending?.temperatureInCelsius ?? null}+ temperatureInCelsius={trending?.temperatureInCelsius ?? null}/>) : index === 2 ? (<CurrentCountry- countryPaths={data.trending?.countryPaths ?? null}- countryLabel={data.trending?.countryLabel ?? null}+ countryPaths={trending?.countryPaths ?? null}+ countryLabel={trending?.countryLabel ?? null}theme={theme}/>) : (diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsxindex 66eac9a247..a6d8746bcd 100644--- a/packages/docs/src/remotion/Root.tsx+++ b/packages/docs/src/remotion/Root.tsx@@ -80,20 +80,18 @@ export const RemotionRoot: React.FC = () => {updateCardOrder: () => undefined,onClickLeft: () => undefined,onClickRight: () => undefined,- playerData: {- trending: {- temperatureInCelsius: 14,- countryLabel: 'Switzerland',- countryPaths: [],- date: '2024-12-31',- repos: [],- },- location: {- city: 'New York',- country: 'US',- latitude: 40.7128,- longitude: -74.006,- },+ trending: {+ temperatureInCelsius: 14,+ countryLabel: 'Switzerland',+ countryPaths: [],+ date: '2024-12-31',+ repos: [],+ },+ location: {+ city: 'New York',+ country: 'US',+ latitude: 40.7128,+ longitude: -74.006,},emojiIndex: 0,}}