Skip to content

🎥 Make videos programmatically with React

awesome

Jonny Burger394ea2997000
diff --git a/packages/example/src/3DContext/DivExtrusion.tsx b/packages/example/src/3DContext/DivExtrusion.tsx
index 62167262be..612b70a514 100644
--- a/packages/example/src/3DContext/DivExtrusion.tsx
+++ b/packages/example/src/3DContext/DivExtrusion.tsx
@@ -15,7 +15,6 @@ export const DivExtrusion: React.FC<{
width,
position: 'absolute',
top: 0,
- filter: 'drop-shadow(0 0 10px rgba(0, 0, 0, 0.1))',
}}
pointerEvents="none"
>
diff --git a/packages/example/src/3DContext/transformation-context.tsx b/packages/example/src/3DContext/transformation-context.tsx
index 3005e9c13b..420f51faae 100644
--- a/packages/example/src/3DContext/transformation-context.tsx
+++ b/packages/example/src/3DContext/transformation-context.tsx
@@ -3,9 +3,11 @@ import {
reduceMatrices,
rotateX,
rotateY,
+ rotateZ,
scaled,
translateX,
translateY,
+ translateZ,
} from '@remotion/svg-3d-engine';
import React, {useContext, useMemo} from 'react';
@@ -40,6 +42,16 @@ export const RotateX: React.FC<{
</NewTransform>
);
};
+export const RotateZ: React.FC<{
+ readonly children: React.ReactNode;
+ readonly radians: number;
+}> = ({children, radians}) => {
+ return (
+ <NewTransform transform={useMemo(() => rotateZ(radians), [radians])}>
+ {children}
+ </NewTransform>
+ );
+};
export const TranslateY: React.FC<{
readonly children: React.ReactNode;
@@ -63,6 +75,17 @@ export const TranslateX: React.FC<{
);
};
+export const TranslateZ: React.FC<{
+ readonly children: React.ReactNode;
+ readonly px: number;
+}> = ({children, px}) => {
+ return (
+ <NewTransform transform={useMemo(() => translateZ(px), [px])}>
+ {children}
+ </NewTransform>
+ );
+};
+
export const RotateY: React.FC<{
readonly children: React.ReactNode;
readonly radians: number;
diff --git a/packages/example/src/Compose/CaptionsContent.tsx b/packages/example/src/Compose/CaptionsContent.tsx
new file mode 100644
index 0000000000..c6c832dde3
--- /dev/null
+++ b/packages/example/src/Compose/CaptionsContent.tsx
@@ -0,0 +1,10 @@
+import React from 'react';
+
+export const CaptionsContent: React.FC = () => {
+ return (
+ <div>
+ Hallo{' '}
+ <span className="bg-blue-600 px-2 py-1 rounded text-white">IPT!</span>
+ </div>
+ );
+};
diff --git a/packages/example/src/Compose/Compose.tsx b/packages/example/src/Compose/Compose.tsx
index 410e07453d..4fb53b1236 100644
--- a/packages/example/src/Compose/Compose.tsx
+++ b/packages/example/src/Compose/Compose.tsx
@@ -1,155 +1,216 @@
-import {AbsoluteFill, Img, staticFile, useCurrentFrame} from 'remotion';
+import React from 'react';
+import {
+ AbsoluteFill,
+ Easing,
+ interpolate,
+ spring,
+ useCurrentFrame,
+ useVideoConfig,
+} from 'remotion';
import {ExtrudeDiv} from '../3DContext/Div3D';
import {
RotateX,
RotateY,
+ RotateZ,
Scale,
TranslateX,
TranslateY,
+ TranslateZ,
} from '../3DContext/transformation-context';
const height = 700;
const width = (height / 16) * 9;
+const cornerRadius = 10;
+const depth = 60;
+
+const Label: React.FC<{
+ children: React.ReactNode;
+}> = ({children}) => {
+ return (
+ <div
+ className="text-white "
+ style={{
+ fontFamily: 'GT Planar',
+ height: '100%',
+ display: 'flex',
+ flexDirection: 'column',
+ justifyContent: 'center',
+ paddingLeft: 20,
+ fontSize: 24,
+ }}
+ >
+ {children}
+ </div>
+ );
+};
+
+const VideoLayers: React.FC<{
+ label: string;
+}> = ({label}) => {
+ return (
+ <AbsoluteFill className="flex justify-center items-center">
+ <Rotations delay={0}>
+ <ExtrudeDiv
+ width={width}
+ height={height}
+ depth={depth}
+ cornerRadius={10}
+ backFace={<AbsoluteFill className="bg-black"></AbsoluteFill>}
+ bottomFace={<Label>{label}</Label>}
+ >
+ <div
+ style={{
+ borderRadius: cornerRadius,
+ overflow: 'hidden',
+ fontFamily: 'GT Planar',
+ backgroundColor: 'white',
+ border: '3px solid black',
+ }}
+ className="text-black flex justify-center items-center font-sans text-2xl font-bold flex-1"
+ >
+ <div
+ style={{
+ backgroundColor: 'white',
+ width: '100%',
+ height: '100%',
+ }}
+ ></div>
+ </div>
+ </ExtrudeDiv>
+ </Rotations>
+ </AbsoluteFill>
+ );
+};
+
+const CaptionLayers = () => {
+ return (
+ <AbsoluteFill className="flex justify-center items-center">
+ <Rotations delay={1}>
+ <ExtrudeDiv
+ width={300}
+ height={60}
+ depth={depth}
+ cornerRadius={10}
+ backFace={<AbsoluteFill className="bg-black"></AbsoluteFill>}
+ bottomFace={<Label>&lt;Captions /&gt;</Label>}
+ >
+ <div
+ style={{
+ borderRadius: cornerRadius,
+ overflow: 'hidden',
+ fontFamily: 'GT Planar',
+ backgroundColor: 'white',
+ border: '3px solid black',
+ }}
+ className="text-black flex justify-center items-center font-sans text-2xl font-bold flex-1"
+ >
+ <div>
+ Hallo{' '}
+ <span className="bg-blue-600 px-2 py-1 rounded text-white">
+ IPT!
+ </span>
+ </div>
+ </div>
+ </ExtrudeDiv>
+ </Rotations>
+ </AbsoluteFill>
+ );
+};
+
+const Rotations: React.FC<{
+ children: React.ReactNode;
+ delay: number;
+}> = ({children, delay}) => {
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+
+ const spr = spring({
+ fps,
+ frame,
+ delay,
+ });
+
+ const rotate = interpolate(spr, [0, 1], [Math.PI, 0]);
+
+ return (
+ <RotateY radians={rotate - 0.4}>
+ <RotateX radians={-0.6}>
+ <RotateZ radians={-0.5}>{children}</RotateZ>
+ </RotateX>
+ </RotateY>
+ );
+};
export const Compose = () => {
- const cornerRadius = 10;
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+ const bRollEnter = spring({
+ fps,
+ frame,
+ config: {
+ damping: 200,
+ },
+ delay: 50,
+ durationInFrames: 25,
+ durationRestThreshold: 0.0001,
+ });
+ const bRollExit = spring({
+ fps,
+ frame,
+ config: {
+ damping: 200,
+ },
+ delay: 90,
+ durationInFrames: 25,
+ durationRestThreshold: 0.0001,
+ });
+
+ const endCard = interpolate(frame, [120, 145], [0, 1], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ easing: Easing.bezier(0.42, 0, 0.58, 1),
+ });
+
+ const layerDownProgress =
+ interpolate(bRollEnter, [0, 0.5], [0, 1], {
+ extrapolateRight: 'clamp',
+ }) -
+ interpolate(bRollExit, [0.5, 1], [0, 1], {
+ extrapolateLeft: 'clamp',
+ });
- const angle = Math.PI / 4;
+ const firstX = interpolate(endCard, [0.7, 1], [0, -1500], {
+ extrapolateLeft: 'clamp',
+ });
+ const secondX = interpolate(endCard, [0, 1], [1500, 0], {
+ extrapolateLeft: 'clamp',
+ });
- const progress = useCurrentFrame();
+ const liftCaptions = interpolate(endCard, [0, 1], [0, -2000]);
return (
<AbsoluteFill className="flex justify-center items-center">
<Scale factor={1.3}>
- <RotateX radians={progress / 10}>
- <RotateX radians={Math.sin(angle) / 4}>
- <RotateY radians={-Math.cos(angle) / 4}>
- <AbsoluteFill className="flex justify-center items-center">
- <ExtrudeDiv
- width={width}
- height={height}
- depth={40}
- cornerRadius={10}
- bottomFace={
- <div
- className="text-white "
- style={{
- fontFamily: 'GT Planar',
- height: '100%',
- display: 'flex',
- flexDirection: 'column',
- justifyContent: 'center',
- paddingLeft: 10,
- }}
- >
- &lt;Video /&gt;
- </div>
- }
- >
- <div
- style={{
- borderRadius: cornerRadius,
- overflow: 'hidden',
- fontFamily: 'GT Planar',
- backgroundColor: 'white',
- }}
- className="text-black flex justify-center items-center font-sans text-2xl font-bold flex-1"
- >
- <Img src={staticFile('bg.png')}></Img>
- </div>
- </ExtrudeDiv>
- </AbsoluteFill>
- <TranslateX px={30}>
- <TranslateY px={120}>
- <AbsoluteFill className="flex justify-center items-center">
- <ExtrudeDiv
- width={300}
- height={60}
- depth={40}
- cornerRadius={10}
- bottomFace={
- <div
- className="text-white "
- style={{
- fontFamily: 'GT Planar',
- height: '100%',
- display: 'flex',
- flexDirection: 'column',
- justifyContent: 'center',
- paddingLeft: 10,
- }}
- >
- &lt;Captions /&gt;
- </div>
- }
- >
- <div
- style={{
- borderRadius: cornerRadius,
- overflow: 'hidden',
- fontFamily: 'GT Planar',
- backgroundColor: 'white',
- }}
- className="text-black flex justify-center items-center font-sans text-2xl font-bold flex-1"
- >
- <div>
- Hallo{' '}
- <span className="bg-blue-600 px-2 py-1 rounded text-white">
- IPT!
- </span>
- </div>
- </div>
- </ExtrudeDiv>
- </AbsoluteFill>
- </TranslateY>
- </TranslateX>
- <TranslateX px={110}>
- <TranslateY px={-280}>
- <AbsoluteFill className="flex justify-center items-center">
- <ExtrudeDiv
- width={120}
- height={120}
- depth={40}
- cornerRadius={10}
- bottomFace={
- <div
- className="text-white "
- style={{
- fontFamily: 'GT Planar',
- height: '100%',
- display: 'flex',
- flexDirection: 'column',
- justifyContent: 'center',
- paddingLeft: 10,
- }}
- >
- &lt;Img /&gt;
- </div>
- }
- >
- <div
- style={{
- borderRadius: cornerRadius,
- overflow: 'hidden',
- fontFamily: 'GT Planar',
- backgroundColor: 'white',
- }}
- className="text-black flex justify-center items-center font-sans text-2xl font-bold flex-1"
- >
- <Img
- style={{
- width: '80%',
- }}
- src="https://ipt.ch/static/img/logo_ipt.e41536c42e31.svg"
- ></Img>
- </div>
- </ExtrudeDiv>
- </AbsoluteFill>
- </TranslateY>
- </TranslateX>
- </RotateY>
- </RotateX>
- </RotateX>
+ <TranslateX px={firstX}>
+ <TranslateZ px={1.5 * depth * layerDownProgress}>
+ <VideoLayers label="<Video />" />
+ </TranslateZ>
+ </TranslateX>
+ <TranslateY
+ px={interpolate(bRollEnter + bRollExit, [0, 1, 2], [1500, 0, -1500])}
+ >
+ <VideoLayers label="<BRoll />" />
+ </TranslateY>
+ {endCard > 0 && (
+ <TranslateX px={secondX}>
+ <VideoLayers label="<EndCard />" />
+ </TranslateX>
+ )}
+ <TranslateY px={190}>
+ <TranslateZ px={-depth + liftCaptions}>
+ <CaptionLayers />
+ </TranslateZ>
+ </TranslateY>
</Scale>
</AbsoluteFill>
);