🎥 Make videos programmatically with React
nice
Jonny Burger00d639cf41b6
diff --git a/packages/example/src/Compose/CodeFrame.tsx b/packages/example/src/Compose/CodeFrame.tsxnew file mode 100644index 0000000000..4c678cb7b2--- /dev/null+++ b/packages/example/src/Compose/CodeFrame.tsx@@ -0,0 +1,99 @@+import React from 'react';+import {staticFile} from 'remotion';++const Tab: React.FC = () => {+ return <span style={{width: 18, display: 'inline-block'}}></span>;+};+export const CodeFrame = () => {+ staticFile('video.mp4');+ return (+ <div+ style={{whiteSpace: 'pre', fontFamily: 'Fira Code'}}+ className="text-white p-8 text-2xl"+ >+ <span style={{color: '#F87683'}}>const</span>{' '}+ <span style={{color: '#B392F0'}}>MyVideo</span>{' '}+ <span style={{color: '#F87683'}}>=</span> (){' '}+ <span style={{color: '#F87683'}}>{'=> '}</span>+ {'{ '}+ <br />+ <span style={{color: '#F87683'}}>+ <Tab />+ {'return '}+ </span>+ {'( \n'}+ <span>+ <Tab />+ <Tab />+ <span>{'<'}</span>+ <span style={{color: '#79B8FF'}}>{'AbsoluteFill'}</span>+ </span>+ {'>\n'}+ <Tab />+ <Tab />+ <Tab />+ {'<'}+ <span style={{color: '#79B8FF'}}>{'Video\n'}</span>+ <Tab />+ <Tab />+ <Tab />+ <Tab />+ <span style={{color: '#B392F0'}}>{'src='}</span>+ {'{'}+ <span style={{color: '#B392F0'}}>{'staticFile'}</span>+ {'('}+ <span style={{color: '#9ECBFF'}}>{"'video.mp4'"}</span>+ {')}\n'}+ <Tab />+ <Tab /> {'/>\n'}+ <Tab />+ <Tab /> {'<'}+ <span style={{color: '#79B8FF'}}>{'Sequence'}</span>+ <span style={{color: '#B392F0'}}>{' from'}</span>+ {'={'}+ <span style={{color: '#79B8FF'}}>{'60'}</span>+ {'}>'}+ <br />+ <Tab />+ <Tab />+ <Tab />+ <Tab />+ {'<'}+ <span style={{color: '#79B8FF'}}>{'BRoll'}</span>+ {' />\n'}+ <Tab />+ <Tab />+ <Tab />+ {'</'}+ <span style={{color: '#79B8FF'}}>{'Sequence'}</span>+ {'>\n'}+ <Tab />+ <Tab />+ <Tab />+ {'<'}+ <span style={{color: '#79B8FF'}}>{'AbsoluteFill'}</span>+ {'>\n'}+ <Tab />+ <Tab />+ <Tab />+ <Tab />+ {'<'}+ <span style={{color: '#79B8FF'}}>{'Captions'}</span>+ {' />\n'}+ <Tab />+ <Tab />+ <Tab />+ {'</'}+ <span style={{color: '#79B8FF'}}>{'AbsoluteFill'}</span>+ {'>\n'}+ <Tab />+ <Tab />+ {'</'}+ <span style={{color: '#79B8FF'}}>{'AbsoluteFill'}</span>+ {'>\n'}+ <Tab />+ {');\n'}+ {'};'}+ </div>+ );+};diff --git a/packages/example/src/Compose/Compose.tsx b/packages/example/src/Compose/Compose.tsxindex 8a4f95fd07..60403b7def 100644--- a/packages/example/src/Compose/Compose.tsx+++ b/packages/example/src/Compose/Compose.tsx@@ -3,6 +3,7 @@ import {AbsoluteFill,Easing,interpolate,+ measureSpring,OffthreadVideo,Sequence,spring,@@ -21,6 +22,7 @@ import {TranslateZ,} from '../3DContext/transformation-context';import {Captions} from './Captions';+import {CodeFrame} from './CodeFrame';const height = 700;const width = (height / 16) * 9;@@ -48,16 +50,25 @@ const Label: React.FC<React.HTMLAttributes<HTMLDivElement>> = (rest) => {);};+const getActualLayerWidth = (progress: number) => {+ return {+ width: interpolate(progress, [0, 1], [width * 1.5, width]),+ height: interpolate(progress, [0, 1], [height, height]),+ };+};+const VideoLayers: React.FC<{label: string;delay: number;footage?: boolean;-}> = ({label, delay, footage}) => {+ boxWidth: number;+ boxHeight: number;+}> = ({label, delay, footage, boxHeight, boxWidth}) => {return (<Rotations zIndexHack={false} delay={delay}><ExtrudeDiv- width={width}- height={height}+ width={boxWidth}+ height={boxHeight}depth={depth}cornerRadius={10}backFace={@@ -67,7 +78,9 @@ const VideoLayers: React.FC<{borderRadius: cornerRadius,border: '3px solid black',}}- ></AbsoluteFill>+ >+ <CodeFrame />+ </AbsoluteFill>}bottomFace={<Label>{label}</Label>}>@@ -247,24 +260,53 @@ export const Compose = () => {durationInFrames: 20,});+ const spr = spring({+ fps,+ frame,+ delay: animationStart,+ config: {+ damping: 200,+ },+ durationInFrames: measureSpring({fps, config: {}}),+ });+ const actual = getActualLayerWidth(spr);++ const outActual = getActualLayerWidth(1 - outAnimation);+return (<AbsoluteFill className="flex justify-center items-center"><Scale factor={1.3}><TranslateX px={firstX}><TranslateZ px={1.5 * depth * layerDownProgress}>- <VideoLayers footage delay={animationStart} label="<Video />" />+ <VideoLayers+ footage+ delay={animationStart}+ boxHeight={actual.height}+ boxWidth={actual.width}+ label="<Video />"+ /></TranslateZ></TranslateX><TranslateYpx={interpolate(bRollEnter + bRollExit, [0, 1, 2], [1500, 0, -1500])}>- <VideoLayers delay={animationStart} label="<BRoll />" />+ <VideoLayers+ boxWidth={width}+ boxHeight={height}+ delay={animationStart}+ label="<BRoll />"+ /></TranslateY>{endCard > 0 && (<TranslateX px={secondX}><RotateY radians={Math.PI * outAnimation}><LabelOpacityContext.Provider value={1 - outAnimation}>- <VideoLayers delay={animationStart} label="<EndCard />" />+ <VideoLayers+ boxHeight={outActual.height}+ boxWidth={outActual.width}+ delay={animationStart}+ label="<EndCard />"+ /></LabelOpacityContext.Provider></RotateY></TranslateX>