Skip to content

🎥 Make videos programmatically with React

wow

JonnyBurger4ac1c6dd3046
diff --git a/packages/skills/skills/remotion-markup/SKILL.md b/packages/skills/skills/remotion-markup/SKILL.md
index 6a53283b07..49ceb863a6 100644
--- a/packages/skills/skills/remotion-markup/SKILL.md
+++ b/packages/skills/skills/remotion-markup/SKILL.md
@@ -24,15 +24,10 @@ Use `Easing.bezier()` and `Easing.spring()` to customize timing.
Structure your markup according to [Remotion Interactivity Best Practices](../remotion-interactivity/SKILL.md).
Prefer `Interactive.withSchema({wrapInSequence: true})` for custom visual components
with editable props, and register reusable scenes as connected compositions.
-Put timing directly on components that support it; avoid redundant `<Sequence>`
-wrappers. Keep sequences where they provide grouping, dimension overrides, or
-series/transition behavior.
-
-The Studio edits the JSX source node that created an item. Author every
-composition registration, clip, scene, layer and sequence that should be
-editable independently as its own JSX node, with its editable props inline.
-Programmatic loops are suitable when the generated instances are intentionally
-controlled as one source template, not when users need to edit the instances
+Put timing directly on components that support it; avoid redundant `<Sequence>` wrappers.
+
+The Studio edits the JSX source node that created an item. Author every composition registration, clip, scene, layer and sequence that should be editable independently as its own JSX node, with its editable props inline.
+Programmatic loops are suitable when the generated instances are intentionally controlled as one source template, not when users need to edit the instances
separately.
```tsx
@@ -127,123 +122,234 @@ If the composition is primarily a timeline of video or audio clips, read
## Example scene
+A background video with a lower third.
+The lower third is an interactive component with its own timeline, registered as a [connected composition](connected-compositions.md).
+Its text is passed as `children` and `accentColor` is an editable prop.
+The fade-in is keyframed inline at the call site.
+
```tsx
-import {
- AbsoluteFill,
- Easing,
- Interactive,
- interpolate,
- useCurrentFrame,
- useVideoConfig
-} from "remotion";
-
-export const Empty = () => {
- const {fps} = useVideoConfig();
+// MyScene.tsx
+import { Video } from "@remotion/media";
+import { Easing, interpolate, useCurrentFrame, useVideoConfig } from "remotion";
+import { LowerThird } from "./LowerThird";
+
+export const MyScene = () => {
+ const { fps } = useVideoConfig();
const frame = useCurrentFrame();
return (
- <AbsoluteFill
- name="Scene"
- style={{
- display: 'flex',
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: 'white'
- }}
- >
- <Interactive.Div
- name="Title"
+ <>
+ <Video
+ name="Background"
+ src="https://remotion.media/video.mp4"
+ objectFit="cover"
+ style={{
+ position: "absolute",
+ width: "100%",
+ height: "100%",
+ }}
+ />
+ <LowerThird
+ name="Lower third"
+ from={1 * fps}
+ accentColor="#0b84f3"
style={{
opacity: interpolate(frame, [1 * fps, 2 * fps], [0, 1], {
extrapolateRight: "clamp",
extrapolateLeft: "clamp",
easing: Easing.bezier(0.16, 1, 0.3, 1),
}),
- fontSize: 88
}}
>
- Title
- </Interactive.Div>
- <Interactive.Div
- name="Subtitle"
+ Jane Doe, Product Designer
+ </LowerThird>
+ </>
+ );
+};
+```
+
+```tsx
+// LowerThird.tsx
+import type React from "react";
+import { Interactive, type InteractivitySchema } from "remotion";
+
+type LowerThirdProps = {
+ readonly children: string;
+ readonly accentColor: string;
+ readonly style?: React.CSSProperties;
+};
+
+const LowerThirdInner: React.FC<LowerThirdProps> = ({
+ children,
+ accentColor,
+ style,
+}) => {
+ return (
+ <Interactive.Div
+ style={{
+ position: "absolute",
+ left: 80,
+ bottom: 80,
+ display: "flex",
+ alignItems: "center",
+ gap: 20,
+ backgroundColor: "white",
+ borderRadius: 16,
+ padding: "20px 32px",
+ color: "black",
+ fontFamily: "Helvetica, Arial, sans-serif",
+ fontSize: 48,
+ fontWeight: 600,
+ ...style,
+ }}
+ >
+ <div
style={{
- opacity: interpolate(frame, [2 * fps, 3 * fps, 8 * fps, 10 * fps], [0, 1, 1, 0], {
- extrapolateRight: "clamp",
- extrapolateLeft: "clamp",
- easing: [Easing.bezier(0.16, 1, 0.3, 1), Easing.linear, Easing.bezier(0.16, 1, 0.3, 1)],
- }),
- fontSize: 32
+ width: 8,
+ alignSelf: "stretch",
+ borderRadius: 4,
+ backgroundColor: accentColor,
}}
- >
- Subtitle
- </Interactive.Div>
- </AbsoluteFill>
+ />
+ {children}
+ </Interactive.Div>
);
-}
+};
+
+const lowerThirdSchema = {
+ children: { type: "text-content", default: "", description: "Text" },
+ accentColor: {
+ type: "color",
+ default: "#0b84f3",
+ description: "Accent color",
+ },
+} as const satisfies InteractivitySchema;
+
+export const LowerThird = Interactive.withSchema({
+ Component: LowerThirdInner,
+ componentName: "<LowerThird>",
+ schema: lowerThirdSchema,
+ wrapInSequence: true,
+});
+```
+
+```tsx
+// Root.tsx
+import { Composition } from "remotion";
+import { LowerThird } from "./LowerThird";
+import { MyScene } from "./MyScene";
+
+export const RemotionRoot: React.FC = () => {
+ return (
+ <>
+ <Composition
+ id="MyScene"
+ component={MyScene}
+ durationInFrames={60}
+ fps={30}
+ width={1280}
+ height={720}
+ />
+ <Composition
+ id="LowerThird"
+ component={LowerThird}
+ durationInFrames={30}
+ fps={30}
+ width={1280}
+ height={720}
+ defaultProps={{
+ children: "Jane Doe, Product Designer",
+ accentColor: "#0b84f3",
+ }}
+ />
+ </>
+ );
+};
```
## Delaying, trimming
-Most components (`<AbsoluteFill>`, `<Interactive.*>` `<Img>`, `<AnimatedImage>`, `<CanvasImage>`, `<HtmlInCanvas>`, `<Solid>`, `<Sequence>` from `remotion`, `<Video>` and `<Audio>` from `@remotion/media`, `<Gif>`, and more) support the following props:
+The following timing props are supported by built-in components (`<AbsoluteFill>`, `<Interactive.*>`, `<Img>`, `<AnimatedImage>`, `<CanvasImage>`, `<HtmlInCanvas>`, `<Solid>`, `<Sequence>` from `remotion`, `<Video>` and `<Audio>` from `@remotion/media`, `<Gif>`, and more).
+Custom components made with `Interactive.withSchema({wrapInSequence: true})` accept them too, see [Prefer interactive components with their own timelines](../remotion-interactivity/SKILL.md#prefer-interactive-components-with-their-own-timelines).
-### from
+### `from`
+
+When the item starts appearing in the timeline.
+Its children start at frame `0` when it appears.
```tsx
<Img from={1 * fps} {/* ... */}/>
<Video from={1 * fps} {/* ... */}/>
<Interactive.Div from={1 * fps} {/* ... */}/>
+<LowerThird from={1 * fps} {/* ... */}/>
```
-When the element starts appearing in the timelien.
-
-### durationInFrames
-
-```tsx
-<Img durationInFrames={20 * fps} {/* ... */}/>
-<Interactive.Div durationInFrames={20 * fps} {/* ... */}/>
-```
-
-For how long the layer plays in the timeline.
-For media, pass the natural duration of the media: `<Video durationInFrames={29.322 * fps}/>`
-
### `trimBefore`
-Useful for components whose internal clock should start later:
+Sets the first frame of the item's own timeline:
```tsx
// Trim away first 2 seconds of footage
<Video trimBefore={2 * fps} {/* ... */} />
-// `useCurrenFrame()` for children starts at `10 * fps`
-<Sequence trimBefore={10 * fps} {/* ... */} />
+// `useCurrentFrame()` of the children starts at `10 * fps`
+<Interactive.Div trimBefore={10 * fps} {/* ... */} />
```
-### `trimAfter`
+### `durationInFrames`
-Ends the internal clock at a frame. Measured in the same clock as `trimBefore`, so the layer lasts `(trimAfter - trimBefore) / playbackRate` frames in the timeline unless `durationInFrames` is shorter:
+How many frames of the item's own timeline are shown, starting at `trimBefore`.
+Use it to end media early instead of cutting the file:
```tsx
// Play the footage from second 2 to second 5
-<Video trimBefore={2 * fps} trimAfter={5 * fps} {/* ... */} />
+<Video trimBefore={2 * fps} durationInFrames={3 * fps} {/* ... */} />
+<Img durationInFrames={20 * fps} {/* ... */}/>
+<LowerThird durationInFrames={5 * fps} {/* ... */}/>
+```
+
+### `playbackRate`
-// Children see frames `10 * fps` through `15 * fps - 1`
-<Sequence trimBefore={10 * fps} trimAfter={15 * fps} {/* ... */} />
+Changes the speed of the item.
+Children calling `useCurrentFrame()` advance `playbackRate` frames per frame of the parent.
+The item occupies `durationInFrames / playbackRate` frames in its parent timeline.
+
+```tsx
+// 2x speed
+<Video playbackRate={2} {/* ... */} />
+<LowerThird playbackRate={0.5} durationInFrames={2 * fps} {/* ... */} />
```
### `loop`
-Repeats the range between `trimBefore` and `trimAfter`. `durationInFrames` sets the total length. `<Video>` and `<Audio>` may omit `trimAfter` and loop the whole file; other layers need `trimAfter` because they have no intrinsic end:
+Repeats the range selected by `trimBefore` and `durationInFrames` until the parent ends.
+`<Video>`, `<Audio>`, `<Gif>` and `<AnimatedImage>` may omit `durationInFrames`; the media's own duration after `trimBefore` then defines the loop range.
+Other items need `durationInFrames` to define the loop range:
```tsx
-<Video loop durationInFrames={20 * fps} {/* ... */} />
-<Sequence trimAfter={2 * fps} durationInFrames={20 * fps} loop {/* ... */} />
+<Video loop {/* ... */} />
+<Interactive.Div durationInFrames={2 * fps} loop {/* ... */} />
```
+To limit the total length of a loop, wrap it in an outer item with `durationInFrames`.
+
`<Img>`, `<CanvasImage>`, `<Solid>` and shapes do not support `loop` because their output does not change over time.
+### Order of operations
+
+1. `from` positions the item in its parent timeline.
+2. `trimBefore` sets the first frame of the item's own timeline.
+3. `durationInFrames` selects the range of the item's own timeline.
+4. `playbackRate` stretches or compresses the selected range.
+5. `loop` repeats the selected range until the parent ends.
+
+Children calling `useCurrentFrame()` get `trimBefore + (frame - from) * playbackRate`.
+
+See [Timing and trimming](https://www.remotion.dev/docs/timing) for more details.
+
### Fallback
-If a component does not support these props, wrap it in`<Sequence>` from `remotion`, which has them.
+If a component does not support these props, wrap it in `<Sequence>` from `remotion`, which has them.
- `layout="absolute-fill"` makes the Sequence behave like AbsoluteFill
- `layout="none"` is "headless" mode, no wrapper element is used.
diff --git a/packages/skills/skills/remotion-markup/audio.md b/packages/skills/skills/remotion-markup/audio.md
index 9d514a1989..42e9450fed 100644
--- a/packages/skills/skills/remotion-markup/audio.md
+++ b/packages/skills/skills/remotion-markup/audio.md
@@ -40,7 +40,7 @@ Multiple audio tracks can be layered by adding multiple `<Audio>` components.
## Trimming
-Use `trimBefore` and `trimAfter` to remove portions of the audio. Values are in frames.
+Use `trimBefore` to skip the beginning of the audio and `durationInFrames` to end it early. Values are in frames.
```tsx
const { fps } = useVideoConfig();
@@ -49,7 +49,7 @@ return (
<Audio
src={staticFile("audio.mp3")}
trimBefore={2 * fps} // Skip the first 2 seconds
- trimAfter={10 * fps} // End at the 10 second mark
+ durationInFrames={8 * fps} // Play 8 seconds, until the 10 second mark
/>
);
```
diff --git a/packages/skills/skills/remotion-markup/embedding-videos.md b/packages/skills/skills/remotion-markup/embedding-videos.md
index c7e65dc20c..63c09f262d 100644
--- a/packages/skills/skills/remotion-markup/embedding-videos.md
+++ b/packages/skills/skills/remotion-markup/embedding-videos.md
@@ -38,7 +38,7 @@ Remote URLs are also supported:
## Trimming
-Use `trimBefore` and `trimAfter` to remove portions of the video. Values are in seconds.
+Use `trimBefore` to skip the beginning of the video and `durationInFrames` to end it early. Values are in frames.
```tsx
const { fps } = useVideoConfig();
@@ -47,7 +47,7 @@ return (
<Video
src={staticFile("video.mp4")}
trimBefore={2 * fps} // Skip the first 2 seconds
- trimAfter={10 * fps} // End at the 10 second mark
+ durationInFrames={8 * fps} // Play 8 seconds, until the 10 second mark
/>
);
```
diff --git a/packages/skills/skills/remotion-markup/ffmpeg.md b/packages/skills/skills/remotion-markup/ffmpeg.md
index 4be15bc2cb..492c6cb3e4 100644
--- a/packages/skills/skills/remotion-markup/ffmpeg.md
+++ b/packages/skills/skills/remotion-markup/ffmpeg.md
@@ -18,7 +18,7 @@ npx remotion ffprobe input.mp4
You have 2 options for trimming videos:
-1. **Preferred**: Use the `trimBefore` and `trimAfter` props of the `<Video>` component. This is non-destructive, requires no re-encoding, and you can change the trim at any time.
+1. **Preferred**: Use the `trimBefore` and `durationInFrames` props of the `<Video>` component. This is non-destructive, requires no re-encoding, and you can change the trim at any time.
```tsx
import {Video} from '@remotion/media';
@@ -26,7 +26,7 @@ import {Video} from '@remotion/media';
<Video
src={staticFile('video.mp4')}
trimBefore={5 * fps}
- trimAfter={10 * fps}
+ durationInFrames={5 * fps}
/>;
```
diff --git a/packages/skills/skills/remotion-markup/silence-detection.md b/packages/skills/skills/remotion-markup/silence-detection.md
index 33d2098820..d67110c627 100644
--- a/packages/skills/skills/remotion-markup/silence-detection.md
+++ b/packages/skills/skills/remotion-markup/silence-detection.md
@@ -55,7 +55,7 @@ When multiple silences are nearly contiguous at the start or end (gap < 0.2s), t
## Using with Remotion's `<Video>` component
-Apply the detected trim points using `trimBefore` and `trimAfter` (values are in frames):
+Apply the detected trim points using `trimBefore` and `durationInFrames` (values are in frames):
```tsx
import { Video } from "@remotion/media";
@@ -66,6 +66,6 @@ const { fps } = useVideoConfig();
<Video
src={staticFile("video.mov")}
trimBefore={Math.floor(leadingEnd * fps)}
- trimAfter={Math.ceil(trailingStart * fps)}
+ durationInFrames={Math.ceil(trailingStart * fps) - Math.floor(leadingEnd * fps)}
/>
```
diff --git a/packages/skills/skills/remotion-markup/video-editing.md b/packages/skills/skills/remotion-markup/video-editing.md
index 766a23eb11..2e029a778d 100644
--- a/packages/skills/skills/remotion-markup/video-editing.md
+++ b/packages/skills/skills/remotion-markup/video-editing.md
@@ -49,7 +49,7 @@ props. `from={0}` may be omitted:
```
- `from` is the clip's absolute start frame in its parent timeline.
-- `durationInFrames` is how many frames the clip remains visible.
+- `durationInFrames` is how many source frames are shown, starting at `trimBefore`. At the default `playbackRate`, this is how long the clip remains visible.
- `trimBefore` is how many source frames are skipped before playback begins.
- Keep `name`, `from`, `durationInFrames` and `trimBefore` inline on each clip.
- Import `<Video>` from `@remotion/media`.
diff --git a/packages/studio/src/components/Timeline/TimelineTrimTooltip.tsx b/packages/studio/src/components/Timeline/TimelineTrimTooltip.tsx
index 4220fea847..fe90f387f6 100644
--- a/packages/studio/src/components/Timeline/TimelineTrimTooltip.tsx
+++ b/packages/studio/src/components/Timeline/TimelineTrimTooltip.tsx
@@ -29,6 +29,12 @@ const tooltip: React.CSSProperties = {
zIndex: 2147483647,
};
+// `.css-reset *` sets font-size and line-height on descendants
+const line: React.CSSProperties = {
+ fontSize: 11,
+ lineHeight: '14px',
+};
+
export const TimelineTrimTooltip: React.FC<{
readonly state: TimelineTrimTooltipState;
readonly fps: number;
@@ -57,11 +63,12 @@ export const TimelineTrimTooltip: React.FC<{
return createPortal(
<div
aria-hidden="true"
+ className="css-reset"
style={{...tooltip, left, top, width: tooltipWidth}}
data-remotion-timeline-trim-tooltip="true"
>
- <div>{deltaLabel}</div>
- <div style={{color: LIGHT_TEXT}}>{edgeLabel}</div>
+ <div style={line}>{deltaLabel}</div>
+ <div style={{...line, color: LIGHT_TEXT}}>{edgeLabel}</div>
</div>,
getPortal(currentZIndex),
);