Skip to content

🎥 Make videos programmatically with React

update sequence docs

Jonny Burgera8a2a4f13a5c
diff --git a/packages/docs/components/SequenceExamples/SequenceForward.tsx b/packages/docs/components/SequenceExamples/SequenceForward.tsx
new file mode 100644
index 0000000000..421086cb7e
--- /dev/null
+++ b/packages/docs/components/SequenceExamples/SequenceForward.tsx
@@ -0,0 +1,120 @@
+import { Player } from "@remotion/player";
+import React from "react";
+import {
+ AbsoluteFill,
+ interpolate,
+ Sequence,
+ spring,
+ useCurrentFrame,
+} from "remotion";
+
+const BlueBall: 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 DelayExample: React.FC = () => {
+ return (
+ <Sequence from={30} durationInFrames={Infinity}>
+ <BlueBall></BlueBall>
+ </Sequence>
+ );
+};
+
+const TrimStartExample: React.FC = () => {
+ return (
+ <Sequence from={-15} durationInFrames={Infinity}>
+ <BlueBall></BlueBall>
+ </Sequence>
+ );
+};
+const TrimAndDelayExample: React.FC = () => {
+ return (
+ <Sequence from={30} durationInFrames={Infinity}>
+ <Sequence from={-15} durationInFrames={Infinity}>
+ <BlueBall></BlueBall>
+ </Sequence>
+ </Sequence>
+ );
+};
+
+const ClipExample: React.FC = () => {
+ return (
+ <Sequence from={0} durationInFrames={45}>
+ <BlueBall></BlueBall>
+ </Sequence>
+ );
+};
+
+const BaseExample: React.FC = () => {
+ return <BlueBall></BlueBall>;
+};
+
+export const SequenceForwardExample: React.FC<{
+ type: "base" | "delay" | "clip" | "trim-start" | "trim-and-delay";
+}> = ({ type }) => {
+ const component = (() => {
+ 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 (
+ <div>
+ <Player
+ component={component}
+ compositionWidth={1280}
+ compositionHeight={720}
+ controls
+ durationInFrames={150}
+ fps={30}
+ style={{
+ width: "100%",
+ }}
+ loop
+ ></Player>
+ </div>
+ );
+};
diff --git a/packages/docs/docs/sequence.md b/packages/docs/docs/sequence.md
deleted file mode 100644
index 4148781d03..0000000000
--- a/packages/docs/docs/sequence.md
+++ /dev/null
@@ -1,56 +0,0 @@
----
-id: sequence
-title: <Sequence />
-sidebar_label: <Sequence />
----
-
-Using a Sequence, you can time-shift certain parts of your animation and therefore make them more reusable. Sequences are also shown in the timeline and help you visually understand the structure of your video.
-
-## API
-
-The Sequence component is a high order component and accepts, besides it's children, the following props:
-
-- `from` _(required)_: At which frame it's children should assume the video starts. When the sequence is at `frame`, it's children are at 0`.
-
-- `durationInFrames` _(required)_: For how many frames the sequence should be displayed. Children are unmounted if they are not within the time range of display. If you don't want to limit the duration of the sequence, you can pass `Infinity`.
-
-- `name` _(optional)_: You can give your sequence a name and it will be shown as the label of the sequence in the timeline of the Remotion preview. This property is purely for helping you keep track of sequences in the timeline.
-
-- `layout`: _(optional)_: Either `"absolute-fill"` _(default)_ or `"none"` By default, your sequence will be absolutely positioned, so they will overlay each other. If you would like to opt out of it and handle layouting yourself, pass `layout="none"`. Available since v1.4.
-
-:::info
-Good to know: You can nest sequences within each other and they will cascade. For example, a sequence that starts at frame 60 which is inside a sequence that starts at frame 30 will have it's children start at frame 90. However, nested sequences are not currently displayed in the timeline.
-:::
-
-## Example
-
-In the below example, you can see that the component which is wrapped inside a `<Sequence>` has gets time-shifted by 10 frames. This way you can first create the animation within `<SubComponent />` and worry about the timing of it's entrance later.
-
-```tsx
-import {Sequence, useCurrentFrame} from 'remotion';
-
-const SubComponent = () => {
- const frame = useCurrentFrame(); // 15
-
- return (
- <div>sequence frame: {frame}</div>
- );
-}
-
-const MyVideo = () => {
- const frame = useCurrentFrame(); // 25
-
- return (
- <div>
- <Sequence from={10} durationInFrames={100} name="MySequence">
- <div>global frame: {frame}</div>
- <SubComponent />
- </Sequence>
- </div>
- );
-}
-```
-
-## See also
-
-- [Reuse components using Sequences](/docs/reusability)
diff --git a/packages/docs/docs/sequence.mdx b/packages/docs/docs/sequence.mdx
new file mode 100644
index 0000000000..aa08236d54
--- /dev/null
+++ b/packages/docs/docs/sequence.mdx
@@ -0,0 +1,97 @@
+---
+id: sequence
+title: <Sequence />
+sidebar_label: <Sequence />
+---
+
+import { SequenceForwardExample } from "../components/SequenceExamples/SequenceForward";
+
+Using a Sequence, you can time-shift certain parts of your animation and therefore make them more reusable. Sequences are also shown in the timeline and help you visually understand the structure of your video.
+
+## API
+
+The Sequence component is a high order component and accepts, besides it's children, the following props:
+
+- `from` _(required)_: At which frame it's children should assume the video starts. When the sequence is at `frame`, it's children are at frame `0`.
+
+- `durationInFrames` _(required)_: For how many frames the sequence should be displayed. Children are unmounted if they are not within the time range of display. If you don't want to limit the duration of the sequence, you can pass `Infinity`.
+
+- `name` _(optional)_: You can give your sequence a name and it will be shown as the label of the sequence in the timeline of the Remotion preview. This property is purely for helping you keep track of sequences in the timeline.
+
+- `layout`: _(optional)_: Either `"absolute-fill"` _(default)_ or `"none"` By default, your sequence will be absolutely positioned, so they will overlay each other. If you would like to opt out of it and handle layouting yourself, pass `layout="none"`. Available since v1.4.
+
+:::info
+Good to know: You can nest sequences within each other and they will cascade. For example, a sequence that starts at frame 60 which is inside a sequence that starts at frame 30 will have it's children start at frame 90. However, nested sequences are not currently displayed in the timeline.
+:::
+
+## Examples
+
+All the examples below are based on the following animation of a blue square:
+
+<SequenceForwardExample type="base" />
+
+<br />
+
+```tsx
+const MyVideo = () => {
+ return (
+ <BlueSquare />
+ );
+}
+```
+
+### Delay
+
+If you would like to delay the content by say 30 frames, you can wrap it in <br/> `<Sequence from={30} durationInFrames={Infinity}>`.
+
+<SequenceForwardExample type="delay" />
+<br />
+
+```tsx
+const MyVideo = () => {
+ return (
+ <Sequence from={30} durationInFrames={Infinity}>
+ <BlueSquare />
+ </Sequence>
+ );
+}
+```
+
+### Trim end
+
+We can clip some content so it only stays visible for a certain time by specifying a non-finite `durationInFrames` number.
+In this example, we wrap the square in `<Sequence from={0} durationInFrames={45}>` and as you can see, it disappears after 45 frames.
+
+<SequenceForwardExample type="clip" />
+<br />
+
+### Trim start
+
+To trim the start of some content, we can pass a negative value to `from`.
+In this example, we wrap the square in `<Sequence from={-15} durationInFrames={Infinity}>` and as a result, the animation has already progressed by 15 frames at the start of the video.
+
+<SequenceForwardExample type="trim-start" />
+
+### Trim and delay
+
+What if you want to trim the start of the content and delay it at the same time?
+You need to wrap the videos in two sequences. To the inner one we pass a negative start value `from={-15}` to trim away the first 15 frames of the content, to the outer one we pass a positive value `from={30}` to then shift it forwards by 30 frames.
+
+<SequenceForwardExample type="trim-and-delay" />
+<br />
+
+```tsx
+const TrimAndDelayExample: React.FC = () => {
+ return (
+ <Sequence from={30} durationInFrames={Infinity}>
+ <Sequence from={-15} durationInFrames={Infinity}>
+ <BlueBall></BlueBall>
+ </Sequence>
+ </Sequence>
+ );
+};
+```
+
+## See also
+
+- [Reuse components using Sequences](/docs/reusability)