Skip to content

🎥 Make videos programmatically with React

feat: add example for postmount

Shankhadeep Dey90b55478d315
diff --git a/packages/example/src/Postmount/PostmountExample.tsx b/packages/example/src/Postmount/PostmountExample.tsx
new file mode 100644
index 0000000000..33a73e85d6
--- /dev/null
+++ b/packages/example/src/Postmount/PostmountExample.tsx
@@ -0,0 +1,75 @@
+import React from 'react';
+import {AbsoluteFill, Series, staticFile, Video} from 'remotion';
+
+export const PostmountExample: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <Series>
+ {/* First video with both premount and postmount */}
+ <Series.Sequence
+ durationInFrames={100}
+ premountFor={20}
+ postmountFor={30}
+ >
+ <Video pauseWhenBuffering src={staticFile('framer.webm')} />
+ </Series.Sequence>
+
+ {/* Second video with just postmount to keep it in memory */}
+ <Series.Sequence
+ durationInFrames={150}
+ postmountFor={50}
+ >
+ <Video
+ pauseWhenBuffering
+ src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
+ />
+ </Series.Sequence>
+
+ {/* Third video with both to enable smooth transitions */}
+ <Series.Sequence
+ durationInFrames={100}
+ premountFor={25}
+ postmountFor={25}
+ >
+ <Video pauseWhenBuffering src={staticFile('framer.webm')} />
+ </Series.Sequence>
+ </Series>
+ </AbsoluteFill>
+ );
+};
+
+export const PostmountWithStyles: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <Series>
+ <Series.Sequence
+ durationInFrames={100}
+ premountFor={20}
+ postmountFor={30}
+ styleWhilePremounted={{
+ opacity: 0,
+ transform: 'scale(0.8)',
+ }}
+ styleWhilePostmounted={{
+ opacity: 0,
+ transform: 'scale(1.2)',
+ }}
+ >
+ <AbsoluteFill style={{background: 'blue', color: 'white', fontSize: 50, display: 'flex', alignItems: 'center', justifyContent: 'center'}}>
+ <div>Scene 1</div>
+ </AbsoluteFill>
+ </Series.Sequence>
+
+ <Series.Sequence
+ durationInFrames={100}
+ premountFor={20}
+ postmountFor={30}
+ >
+ <AbsoluteFill style={{background: 'green', color: 'white', fontSize: 50, display: 'flex', alignItems: 'center', justifyContent: 'center'}}>
+ <div>Scene 2</div>
+ </AbsoluteFill>
+ </Series.Sequence>
+ </Series>
+ </AbsoluteFill>
+ );
+};
\ No newline at end of file
diff --git a/packages/example/src/Postmount/index.tsx b/packages/example/src/Postmount/index.tsx
new file mode 100644
index 0000000000..7b98c57d24
--- /dev/null
+++ b/packages/example/src/Postmount/index.tsx
@@ -0,0 +1,114 @@
+import React from 'react';
+import {AbsoluteFill, Sequence, Video, staticFile} from 'remotion';
+
+/**
+ * Example demonstrating postmountFor feature
+ *
+ * postmountFor keeps a sequence mounted for X frames after its duration ends,
+ * improving performance when scrubbing backwards in the timeline.
+ */
+export const PostmountDemoComposition: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ {/* Video that stays mounted 40 frames after it ends */}
+ <Sequence
+ from={50}
+ durationInFrames={100}
+ postmountFor={40}
+ >
+ <Video pauseWhenBuffering src={staticFile('framer.webm')} />
+ </Sequence>
+
+ {/* Overlapping sequences with both premount and postmount */}
+ <Sequence
+ from={120}
+ durationInFrames={80}
+ premountFor={30}
+ postmountFor={30}
+ >
+ <AbsoluteFill style={{background: 'rgba(255, 0, 0, 0.5)'}}>
+ <Video
+ pauseWhenBuffering
+ src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
+ />
+ </AbsoluteFill>
+ </Sequence>
+
+ {/* Another sequence that benefits from the previous one's postmount */}
+ <Sequence
+ from={200}
+ durationInFrames={100}
+ premountFor={20}
+ postmountFor={50}
+ >
+ <AbsoluteFill style={{background: 'rgba(0, 0, 255, 0.5)'}}>
+ <Video pauseWhenBuffering src={staticFile('framer.webm')} />
+ </AbsoluteFill>
+ </Sequence>
+ </AbsoluteFill>
+ );
+};
+
+/**
+ * Example showing how postmountFor works with custom styles
+ */
+export const PostmountWithCustomStyles: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <Sequence
+ from={30}
+ durationInFrames={60}
+ premountFor={20}
+ postmountFor={30}
+ style={{
+ border: '2px solid blue',
+ }}
+ styleWhilePremounted={{
+ opacity: 0,
+ transform: 'translateX(-100px)',
+ }}
+ styleWhilePostmounted={{
+ opacity: 0,
+ transform: 'translateX(100px)',
+ }}
+ >
+ <AbsoluteFill style={{
+ background: 'linear-gradient(45deg, #667eea 0%, #764ba2 100%)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ fontSize: 60,
+ color: 'white',
+ fontFamily: 'Arial, sans-serif',
+ }}>
+ <div>Mounted Content</div>
+ </AbsoluteFill>
+ </Sequence>
+
+ {/* Visual indicator showing mount status */}
+ <Sequence from={0} durationInFrames={140}>
+ <div style={{
+ position: 'absolute',
+ top: 20,
+ left: 20,
+ fontSize: 20,
+ color: 'black',
+ background: 'white',
+ padding: 10,
+ }}>
+ Frame timeline:
+ <br />
+ 0-10: Not mounted
+ <br />
+ 10-30: Premounting (invisible)
+ <br />
+ 30-90: Visible & active
+ <br />
+ 90-120: Postmounting (invisible)
+ <br />
+ 120+: Not mounted
+ </div>
+ </Sequence>
+ </AbsoluteFill>
+ );
+};
\ No newline at end of file
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index e579b60f7b..4b25808ae1 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -47,6 +47,10 @@ import {OffthreadVideoToCanvas} from './OffthreadVideoToCanvas';
import {OrbScene} from './Orb';
import {ShapesMorph} from './Paths/ShapesMorph';
import {SlicePath} from './Paths/SlicePath';
+import {
+ PostmountExample,
+ PostmountWithStyles,
+} from './Postmount/PostmountExample';
import {PremountedExample} from './Premount';
import {PremountedRemoteVideos} from './Premount/RemoteVideos';
import InfinityVideo from './ReallyLongVideo';
@@ -1325,6 +1329,24 @@ export const Index: React.FC = () => {
width={1080}
/>
</Folder>
+ <Folder name="Postmount">
+ <Composition
+ id="postmount-example"
+ component={PostmountExample}
+ fps={30}
+ height={1080}
+ durationInFrames={350}
+ width={1920}
+ />
+ <Composition
+ id="postmount-with-styles"
+ component={PostmountWithStyles}
+ fps={30}
+ height={1080}
+ durationInFrames={230}
+ width={1920}
+ />
+ </Folder>
<Folder name="Transitions">
<Composition
id="basic-transition"