Skip to content

🎥 Make videos programmatically with React

progress

Jonny Burgerdd36d4cce4a0
diff --git a/packages/docs/components/LandingPage/CodeExample.tsx b/packages/docs/components/LandingPage/CodeExample.tsx
new file mode 100644
index 0000000000..4de2781fbf
--- /dev/null
+++ b/packages/docs/components/LandingPage/CodeExample.tsx
@@ -0,0 +1,85 @@
+import { Player } from "@remotion/player";
+import React, { useState } from "react";
+import { interpolate, useCurrentFrame } from "remotion";
+import styled from "styled-components";
+
+const IMG_WIDTH = 1120;
+const IMG_HEIGHT = 760;
+const ASPECT = IMG_WIDTH / IMG_HEIGHT;
+
+const Demo: React.FC = () => {
+ const frame = useCurrentFrame();
+ const scale = interpolate(frame, [0, 10, 40, 49], [0, 1, 1, 0]);
+ return (
+ <div
+ style={{
+ display: "flex",
+ justifyContent: "center",
+ alignItems: "center",
+ flex: 1,
+ }}
+ >
+ <img
+ style={{ transform: `scale(${scale})` }}
+ src="http://localhost:3000/img/logo-small.png"
+ />
+ </div>
+ );
+};
+
+const container = {
+ width: 500,
+ height: (1 / ASPECT) * 500,
+ position: "relative" as const,
+};
+
+const Preview: React.FC = () => {
+ return (
+ <Player
+ component={Demo}
+ compositionHeight={IMG_HEIGHT}
+ compositionWidth={IMG_WIDTH}
+ durationInFrames={50}
+ style={container}
+ controls
+ fps={30}
+ ></Player>
+ );
+};
+
+const Tab = styled.button<{
+ active: boolean;
+}>`
+ appearance: none;
+ background-color: transparent;
+ font-family: inherit;
+ border: none;
+ cursor: pointer;
+ color: var(--text-color);
+ opacity: ${(props) => (props.active ? 1 : 0.5)};
+`;
+
+type Tab = "code" | "preview";
+
+export const CodeExample: React.FC = () => {
+ const [tab, setTab] = useState<Tab>("code");
+ return (
+ <div style={{ flex: 1, textAlign: "left", width: 500 }}>
+ <Tab active={tab === "code"} onClick={() => setTab("code")}>
+ Code
+ </Tab>
+ |
+ <Tab active={tab === "preview"} onClick={() => setTab("preview")}>
+ Preview
+ </Tab>
+ <div>
+ {tab === "code" && (
+ <div style={container}>
+ <img src="/img/code-sample.png"></img>
+ </div>
+ )}
+ {tab === "preview" && <Preview></Preview>}
+ </div>
+ </div>
+ );
+};
diff --git a/packages/docs/components/LandingPage/if-you-know-react.tsx b/packages/docs/components/LandingPage/if-you-know-react.tsx
index d8f322207e..26278eedb1 100644
--- a/packages/docs/components/LandingPage/if-you-know-react.tsx
+++ b/packages/docs/components/LandingPage/if-you-know-react.tsx
@@ -1,11 +1,13 @@
import React from "react";
import styled from "styled-components";
+import { CodeExample } from "./CodeExample";
const Row = styled.div`
display: flex;
flex-direction: row;
justify-content: flex-end;
text-align: right;
+ align-items: center;
`;
const Title = styled.h2`
@@ -35,14 +37,16 @@ const Button = styled.div`
export const IfYouKnowReact: React.FC = () => {
return (
<Row>
+ <CodeExample></CodeExample>
+ <div style={{ width: 80 }}></div>
<div>
<Title>
If you know <Rea>React</Rea> <br />
you can make videos.
</Title>
<p>
- Remotion is a small set of utilities for video creation in React.{" "}
- <br /> The rules of React stay the same. <br />
+ Remotion is a set of utilities for video creation in React. <br /> The
+ rules of React stay the same. <br />
Learn the fundamentals in just a few minutes:
</p>
<Button>Learn Remotion</Button>
diff --git a/packages/docs/components/LandingPage/real-mp4-videos.tsx b/packages/docs/components/LandingPage/real-mp4-videos.tsx
index 74c99c33bb..0aa33ae87a 100644
--- a/packages/docs/components/LandingPage/real-mp4-videos.tsx
+++ b/packages/docs/components/LandingPage/real-mp4-videos.tsx
@@ -1,5 +1,10 @@
-import React from "react";
-import styled from "styled-components";
+import React, { useCallback, useEffect, useRef, useState } from "react";
+import styled, { keyframes } from "styled-components";
+
+const Row = styled.div`
+ display: flex;
+ flex-direction: row;
+`;
const Title = styled.h2`
font-size: 2.5em;
@@ -15,17 +20,72 @@ const Mp4 = styled.span`
-webkit-background-clip: text;
`;
+const animation = keyframes`
+ from {
+ opacity: 0;
+ transform: translateY(50px);
+ }
+ to {
+ opacity: 1;
+ transform: translateY(0px);
+ }
+`;
+
+const Icon = styled.img<{
+ playing: boolean;
+}>`
+ animation: ${animation} 0.6s;
+ animation-play-state: ${(props) => (props.playing ? "running" : "paused")};
+`;
+
export const RealMP4Videos: React.FC = () => {
+ const ref = useRef<HTMLDivElement>(null);
+ const [isIntersecting, setIsIntersecting] = useState(false);
+
+ const callback: IntersectionObserverCallback = useCallback((data) => {
+ setIsIntersecting(data[0].isIntersecting);
+ }, []);
+
+ useEffect(() => {
+ const { current } = ref;
+ if (!current) {
+ return;
+ }
+ const observer = new IntersectionObserver(callback, {
+ root: null,
+ threshold: 0.5,
+ });
+ observer.observe(current);
+
+ return () => observer.unobserve(current);
+ }, []);
+
return (
- <div>
- <Title>
- Real <Mp4>.mp4</Mp4> videos
- </Title>
- <p>
- Remotion renders all frames to images <br /> and encodes them to a real
- video - audio support included. <br /> WebM and other formats are also
- supported.
- </p>
- </div>
+ <Row ref={ref}>
+ <div>
+ <Title>
+ Real <Mp4>.mp4</Mp4> videos
+ </Title>
+ <p>
+ Remotion renders all frames to images and <br /> encodes them to a
+ real video - audio support included. <br /> WebM and other formats are
+ also supported.
+ </p>
+ </div>
+ <div
+ style={{
+ flex: 1,
+ justifyContent: "flex-end",
+ alignItems: "center",
+ display: "flex",
+ }}
+ >
+ <Icon
+ playing={isIntersecting}
+ src="/img/mp4.png"
+ style={{ width: 140 }}
+ ></Icon>
+ </div>
+ </Row>
);
};
diff --git a/packages/docs/static/img/code-sample.png b/packages/docs/static/img/code-sample.png
new file mode 100644
index 0000000000..9fbbe339cd
Binary files /dev/null and b/packages/docs/static/img/code-sample.png differ
diff --git a/packages/docs/static/img/mp4.png b/packages/docs/static/img/mp4.png
new file mode 100644
index 0000000000..77db1fc8a6
Binary files /dev/null and b/packages/docs/static/img/mp4.png differ
diff --git a/packages/docs/static/img/player-demo.mp4 b/packages/docs/static/img/player-demo.mp4
new file mode 100644
index 0000000000..0c5fa9b6c0
Binary files /dev/null and b/packages/docs/static/img/player-demo.mp4 differ
diff --git a/packages/docs/static/img/remotion.mp4 b/packages/docs/static/img/remotion.mp4
new file mode 100644
index 0000000000..f5d9614bd6
Binary files /dev/null and b/packages/docs/static/img/remotion.mp4 differ
diff --git a/packages/example/out.mp4 b/packages/example/out.mp4
new file mode 100644
index 0000000000..4d5e43b66a
Binary files /dev/null and b/packages/example/out.mp4 differ
diff --git a/packages/player/src/PlayerUI.tsx b/packages/player/src/PlayerUI.tsx
index dde8ea87fa..9ff03c5504 100644
--- a/packages/player/src/PlayerUI.tsx
+++ b/packages/player/src/PlayerUI.tsx
@@ -294,7 +294,7 @@ const PlayerUI: React.ForwardRefRenderFunction<
return content;
}
- return <Suspense fallback={<h1>Loading...</h1>}>{content}</Suspense>;
+ return <Suspense fallback={<div style={outerStyle} />}>{content}</Suspense>;
};
export default forwardRef(PlayerUI);
diff --git a/packages/player/src/utils/use-element-size.ts b/packages/player/src/utils/use-element-size.ts
index 96e42636c2..9efccb05d3 100644
--- a/packages/player/src/utils/use-element-size.ts
+++ b/packages/player/src/utils/use-element-size.ts
@@ -18,7 +18,7 @@ export const useElementSize = (
return new ResizeObserver((entries) => {
const newSize = entries[0].target.getClientRects();
- if (!newSize) {
+ if (!newSize || !newSize[0]) {
setSize(null);
return;
}