Skip to content

🎥 Make videos programmatically with React

update docs

Jonny Burger80f21505bad4
diff --git a/packages/docs/components/FreezeExample/FreezeExample.tsx b/packages/docs/components/FreezeExample/FreezeExample.tsx
index 3480423b19..eb11201d85 100644
--- a/packages/docs/components/FreezeExample/FreezeExample.tsx
+++ b/packages/docs/components/FreezeExample/FreezeExample.tsx
@@ -1,12 +1,10 @@
import { Player } from "@remotion/player";
-import React,{useState} from "react";
+import React, { useState } from "react";
import {
AbsoluteFill,
- interpolate,
- Sequence,
Freeze,
+ interpolate,
spring,
- getInputProps,
useCurrentFrame,
} from "remotion";
@@ -45,23 +43,25 @@ const BlueSquare: React.FC = () => {
);
};
-const BlueSquareFreeze: React.FC<{frame:number}> = ({frame}) => {
- return (
- <Freeze frame={frame}>
- <BlueSquare />
- </Freeze>
- );
-};
-
+const BlueSquareFreeze: React.FC<{ frozen: number | null }> = ({ frozen }) => {
+ if (frozen !== null) {
+ return (
+ <Freeze frame={frozen}>
+ <BlueSquare />
+ </Freeze>
+ );
+ }
+ return <BlueSquare />;
+};
-export const FreezeExample: React.FC = ( ) =>{
- const [isFreeze,setIsFreeze] = useState(false);
- const [frame,setFrameNumber] = useState(30);
+export const FreezeExample: React.FC = () => {
+ const [isFreeze, setIsFreeze] = useState(false);
+ const [frame, setFrameNumber] = useState(30);
return (
<div>
<Player
- component={isFreeze? BlueSquareFreeze:BlueSquare}
+ component={BlueSquareFreeze}
compositionWidth={1280}
compositionHeight={720}
controls
@@ -71,22 +71,33 @@ export const FreezeExample: React.FC = ( ) =>{
width: "100%",
}}
inputProps={{
- frame
+ frozen: isFreeze ? frame : null,
}}
loop
- />
- <div>
+ />
+ <div>
<label>
- <input type='checkbox' checked={isFreeze} onChange={ (e) => setIsFreeze(!isFreeze)} />
+ <input
+ type="checkbox"
+ checked={isFreeze}
+ onChange={() => setIsFreeze(!isFreeze)}
+ />
Use Freeze component
</label>
- </div>
+ </div>
+ {isFreeze ? (
<div>
- <label>
- <input type='number' value={frame} onChange={ (e) => setFrameNumber(Number(e.target.value))} />
- Frame of the Freeze
- </label>
- </div>
+ <label>
+ <input
+ type="number"
+ value={frame}
+ style={{ width: 50, marginRight: 8, padding: 8 }}
+ onChange={(e) => setFrameNumber(Number(e.target.value))}
+ />
+ Frame of the Freeze
+ </label>
+ </div>
+ ) : null}
</div>
);
-};
\ No newline at end of file
+};
diff --git a/packages/docs/components/Player.tsx b/packages/docs/components/Player.tsx
index b20919ed19..b44191ee1e 100644
--- a/packages/docs/components/Player.tsx
+++ b/packages/docs/components/Player.tsx
@@ -24,7 +24,7 @@ export const PlayerExample: React.FC = () => {
width: "100%",
}}
loop
- ></Player>
+ />
<br />
<p>
Enter your name:{" "}
diff --git a/packages/docs/docs/freeze.mdx b/packages/docs/docs/freeze.mdx
index c81ccf561b..38e62b4f4b 100644
--- a/packages/docs/docs/freeze.mdx
+++ b/packages/docs/docs/freeze.mdx
@@ -3,29 +3,35 @@ id: freeze
title: <Freeze />
sidebar_label: <Freeze />
---
-import { FreezeExample } from "../components/FreezeExample/FreezeExample";
+import { FreezeExample } from "../components/FreezeExample/FreezeExample";
```twoslash include example
const BlueSquare: React.FC = () => <div></div>
// - BlueSquare
```
-_Available from v2.2.0_
-Using a Freeze, you can freeze a video to a certain frame.
+_Available from v2.2.0._
+
+When using the `<Freeze/>` component, all of it's children will freeze to the frame that you specify as a prop.
+
+If a component is a child of `<Freeze/>`, calling the `useCurrentFrame()` hook will always return the frame number you specify.
+
+`<Video/>` elements will be paused and `<Audio/>` elements will render muted.
## API
The Freeze component is a high order component and accepts, besides it's children, the following props:
-- `frame` _(required)_: At which frame it's children should freeze. And it makes `useCurrentFrame()` to always return frame number.
+- `frame` _(required)_: At which frame it's children should freeze.
-## Example
+## Example usage
```tsx twoslash
// @include: example-BlueSquare
-import {Freeze} from 'remotion'
// ---cut---
+import {Freeze} from 'remotion';
+
const MyVideo = () => {
return (
<Freeze frame={30}>
@@ -35,5 +41,11 @@ const MyVideo = () => {
}
```
+## Demo
+
<FreezeExample />
+## See also
+
+- [`<Video/>` Playback speed](video#controlling-playback-speed)
+- [`useCurrentFrame()`](use-current-frame)
diff --git a/packages/docs/docs/use-current-frame.md b/packages/docs/docs/use-current-frame.md
index ea2b2ecd59..01898476a4 100644
--- a/packages/docs/docs/use-current-frame.md
+++ b/packages/docs/docs/use-current-frame.md
@@ -7,7 +7,7 @@ With this hook, you can retrieve the current frame of the video. Frames are 0-in
If the component you are writing is wrapped in a `<Sequence>`, `useCurrentFrame` will return the frame relative to when the Sequence starts.
-Say the timeline marker is positioned at frame 25. In the example below, `useCurrentFrame` will return `20`, except within the Subtitle component, where it will return `15` because it is within a sequence that starts at frame 10.
+Say the timeline marker is positioned at frame 25. In the example below, `useCurrentFrame` will return `25`, except within the Subtitle component, where it will return `15` because it is within a sequence that starts at frame 10.
```tsx twoslash
import {useCurrentFrame, Sequence} from 'remotion';
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 70beb64bb8..c9fe1c7903 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -58,11 +58,11 @@ module.exports = {
"audio",
"composition",
"sequence",
- "freeze",
"video",
"absolute-fill",
"img",
"iframe",
+ "freeze",
"easing",
],
},