Skip to content

🎥 Make videos programmatically with React

update `<Freeze />` docs

Shankhadeep Deya98a005d9f27
diff --git a/packages/docs/components/FreezeExample/FreezeExample.tsx b/packages/docs/components/FreezeExample/FreezeExample.tsx
new file mode 100644
index 0000000000..3480423b19
--- /dev/null
+++ b/packages/docs/components/FreezeExample/FreezeExample.tsx
@@ -0,0 +1,92 @@
+import { Player } from "@remotion/player";
+import React,{useState} from "react";
+import {
+ AbsoluteFill,
+ interpolate,
+ Sequence,
+ Freeze,
+ spring,
+ getInputProps,
+ useCurrentFrame,
+} from "remotion";
+
+const BlueSquare: React.FC = () => {
+ const frame = useCurrentFrame();
+ const animation = spring({
+ fps: 30,
+ frame,
+ config: {
+ damping: 400,
+ },
+ });
+ return (
+ <AbsoluteFill style={{ justifyContent: "center", alignItems: "center" }}>
+ <div
+ style={{
+ height: 200,
+ width: 200,
+ backgroundColor: "#3498db",
+ borderRadius: 20,
+ transform: `translateY(${interpolate(
+ animation,
+ [0, 1],
+ [600, 0]
+ )}px)`,
+ justifyContent: "center",
+ alignItems: "center",
+ display: "flex",
+ color: "rgba(255, 255, 255, 0.7)",
+ fontSize: 50,
+ }}
+ >
+ {frame}
+ </div>
+ </AbsoluteFill>
+ );
+};
+
+const BlueSquareFreeze: React.FC<{frame:number}> = ({frame}) => {
+ return (
+ <Freeze frame={frame}>
+ <BlueSquare />
+ </Freeze>
+ );
+};
+
+
+
+export const FreezeExample: React.FC = ( ) =>{
+ const [isFreeze,setIsFreeze] = useState(false);
+ const [frame,setFrameNumber] = useState(30);
+ return (
+ <div>
+ <Player
+ component={isFreeze? BlueSquareFreeze:BlueSquare}
+ compositionWidth={1280}
+ compositionHeight={720}
+ controls
+ durationInFrames={150}
+ fps={30}
+ style={{
+ width: "100%",
+ }}
+ inputProps={{
+ frame
+ }}
+ loop
+ />
+ <div>
+ <label>
+ <input type='checkbox' checked={isFreeze} onChange={ (e) => setIsFreeze(!isFreeze)} />
+ Use Freeze component
+ </label>
+ </div>
+ <div>
+ <label>
+ <input type='number' value={frame} onChange={ (e) => setFrameNumber(Number(e.target.value))} />
+ Frame of the Freeze
+ </label>
+ </div>
+ </div>
+ );
+};
\ No newline at end of file
diff --git a/packages/docs/components/SequenceExamples/SequenceForward.tsx b/packages/docs/components/SequenceExamples/SequenceForward.tsx
index 34670720be..87cf65224a 100644
--- a/packages/docs/components/SequenceExamples/SequenceForward.tsx
+++ b/packages/docs/components/SequenceExamples/SequenceForward.tsx
@@ -58,6 +58,7 @@ const TrimStartExample: React.FC = () => {
</Sequence>
);
};
+
const TrimAndDelayExample: React.FC = () => {
return (
<Sequence from={30} durationInFrames={Infinity}>
@@ -87,18 +88,23 @@ export const SequenceForwardExample: React.FC<{
if (type === "base") {
return BaseExample;
}
+
if (type === "delay") {
return DelayExample;
}
+
if (type === "trim-start") {
return TrimStartExample;
}
+
if (type === "trim-and-delay") {
return TrimAndDelayExample;
}
+
if (type === "clip") {
return ClipExample;
}
+
throw new TypeError("oops");
})();
return (
@@ -114,7 +120,7 @@ export const SequenceForwardExample: React.FC<{
width: "100%",
}}
loop
- ></Player>
+ />
</div>
);
};
diff --git a/packages/docs/docs/freeze.mdx b/packages/docs/docs/freeze.mdx
new file mode 100644
index 0000000000..c81ccf561b
--- /dev/null
+++ b/packages/docs/docs/freeze.mdx
@@ -0,0 +1,39 @@
+---
+id: freeze
+title: <Freeze />
+sidebar_label: <Freeze />
+---
+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.
+
+## 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.
+
+## Example
+
+```tsx twoslash
+// @include: example-BlueSquare
+import {Freeze} from 'remotion'
+// ---cut---
+const MyVideo = () => {
+ return (
+ <Freeze frame={30}>
+ <BlueSquare />
+ </Freeze>
+ );
+}
+```
+
+<FreezeExample />
+
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 919e2520ba..70beb64bb8 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -58,6 +58,7 @@ module.exports = {
"audio",
"composition",
"sequence",
+ "freeze",
"video",
"absolute-fill",
"img",