Skip to content

🎥 Make videos programmatically with React

Docs: Example of getting duration of a TransitionSeries with 3 slides

Jonny Burger0d7dec69c7af
diff --git a/packages/docs/docs/transitions/transitionseries.mdx b/packages/docs/docs/transitions/transitionseries.mdx
index 0830c6bb2f..406fff6ad9 100644
--- a/packages/docs/docs/transitions/transitionseries.mdx
+++ b/packages/docs/docs/transitions/transitionseries.mdx
@@ -188,6 +188,70 @@ During this time, both slides are rendered. This means the total duration of the
<TransitionsDuration />
+<details>
+<summary>Example with 3 slides</summary>
+
+```tsx twoslash title="SlideTransition.tsx"
+import { AbsoluteFill } from "remotion";
+
+const Letter: React.FC<{
+ children: React.ReactNode;
+ color: string;
+}> = ({ children, color }) => {
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: color,
+ opacity: 0.9,
+ justifyContent: "center",
+ alignItems: "center",
+ fontSize: 200,
+ color: "white",
+ }}
+ >
+ {children}
+ </AbsoluteFill>
+ );
+};
+// ---cut---
+import { linearTiming, TransitionSeries } from "@remotion/transitions";
+import { slide } from "@remotion/transitions/slide";
+
+const BasicTransition = () => {
+ return (
+ <TransitionSeries>
+ <TransitionSeries.Sequence durationInFrames={40}>
+ <Letter color="#0b84f3">A</Letter>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={slide()}
+ timing={linearTiming({ durationInFrames: 30 })}
+ />
+ <TransitionSeries.Sequence durationInFrames={60}>
+ <Letter color="pink">B</Letter>
+ </TransitionSeries.Sequence>
+ <TransitionSeries.Transition
+ presentation={slide()}
+ timing={linearTiming({ durationInFrames: 45 })}
+ />
+ <TransitionSeries.Sequence durationInFrames={90}>
+ <Letter color="green">C</Letter>
+ </TransitionSeries.Sequence>
+ </TransitionSeries>
+ );
+};
+```
+
+- The first slide is shown for 40 frames
+- The second slide is shown for 60 frames
+- The third slide is shown for 90 frames
+- There are two transitions, one 30 frames long and one 45 frames long
+
+1. Sum up the durations: `40 + 60 + 90 = 190`
+2. Subtract the duration of the transitions: `190 - 30 - 45 = 115`
+
+</details>
+
## Getting the duration of a transition
You can get the duration of a transition by calling `getDurationInFrames()` on the timing: