Skip to content

🎥 Make videos programmatically with React

Docs: Explain timing and trimming for sequences and media

JonnyBurger8ed157a8ed57
diff --git a/packages/docs/docs/audio/TableOfContents.tsx b/packages/docs/docs/audio/TableOfContents.tsx
index 373bf72cd7..47bab3abb6 100644
--- a/packages/docs/docs/audio/TableOfContents.tsx
+++ b/packages/docs/docs/audio/TableOfContents.tsx
@@ -42,10 +42,6 @@ export const TableOfContents: React.FC = () => {
<strong>{'Exporting audio'}</strong>
<div>Export audio</div>
</TOCItem>
- <TOCItem link="/docs/audio/order-of-operations">
- <strong>{'Order of operations'}</strong>
- <div>Control the order of operations for audio elements</div>
- </TOCItem>
</Grid>
</div>
);
diff --git a/packages/docs/docs/audio/order-of-operations.mdx b/packages/docs/docs/audio/order-of-operations.mdx
deleted file mode 100644
index 3ca5b166dc..0000000000
--- a/packages/docs/docs/audio/order-of-operations.mdx
+++ /dev/null
@@ -1,27 +0,0 @@
----
-image: /generated/articles-docs-audio-order-of-operations.png
-title: Order of Operations
-sidebar_label: Order of Operations
-id: order-of-operations
-crumb: 'Audio'
----
-
-import Tabs from '@theme/Tabs';
-import TabItem from '@theme/TabItem';
-import {AvailableFrom} from '../../src/components/AvailableFrom';
-
-Since Remotion v4.0.141, the order of operations is guaranteed to be the following for `<Video>`, `<Audio>`, `<Html5Audio>`, `<Html5Video>` and `<OffthreadVideo>`, :
-
-1. Trim audio (using [`trimBefore`](/docs/html5-audio#trimbefore--trimafter)).
-2. Offset audio (by putting it in a [`<Sequence>`](/docs/sequence)).
-3. Stretch audio (by adding a [`playbackRate`](/docs/html5-audio#playbackrate)).
-
-Example for a 30 FPS composition which is 60 frames long:
-
-1. An [`<Audio>`](/docs/media/audio) tag has a [`trimBefore`](/docs/media/audio#trimbefore) value of 45. The first 1.5 seconds of the audio get trimmed off.
-2. The [`<Audio>`](/docs/media/audio) tag is in a [`<Sequence>`](/docs/sequence) which starts at `30`. The audio only begins playing at the 1.0 second timeline mark at the 1.5 second audio position.
-3. The [`<Audio>`](/docs/media/audio) has a [`playbackRate`](/docs/html5-audio#playbackrate) of `2`. The audio gets sped up by 2x, but the starting position and start offset is not affected.
-4. The composition is 60 frames long, so the audio must stop at the 3.5 second mark:
- > (comp_duration - offset) \* playback_rate + start_from
- > (60 - 30) \* 2 + 45 => frame 105 or the 3.5 second mark
-5. Result: The section of 1.5sec - 3.5sec gets cut out of the audio and is played in the Remotion timeline between frames 30 and 59 at 2x speed.
diff --git a/packages/docs/docs/html5-video.mdx b/packages/docs/docs/html5-video.mdx
index 9dd38782d9..e61e5871a7 100644
--- a/packages/docs/docs/html5-video.mdx
+++ b/packages/docs/docs/html5-video.mdx
@@ -66,7 +66,7 @@ By passing `trimAfter={120}`, any video after the 4 second mark in the file will
The video will play the range from `00:02:00` to `00:04:00`, meaning the video will play for 2 seconds.
-For exact behavior, see: [Order of operations](/docs/audio/order-of-operations).
+For exact behavior, see [Timing and trimming](/docs/timing).
```tsx twoslash
import {AbsoluteFill, staticFile, Html5Video} from 'remotion';
diff --git a/packages/docs/docs/media/audio.mdx b/packages/docs/docs/media/audio.mdx
index eede17c99a..8b05964b4f 100644
--- a/packages/docs/docs/media/audio.mdx
+++ b/packages/docs/docs/media/audio.mdx
@@ -88,7 +88,7 @@ By passing `trimAfter={120}`, any audio after the 4 second mark in the file will
The audio will play the range from `00:02:00` to `00:04:00`, meaning the audio will play for 2 seconds.
-For exact behavior, see: [Order of operations](/docs/audio/order-of-operations).
+For exact behavior, see [Timing and trimming](/docs/timing).
```tsx twoslash
import {AbsoluteFill, staticFile} from 'remotion';
diff --git a/packages/docs/docs/media/video.mdx b/packages/docs/docs/media/video.mdx
index 3fa56a93e5..c9d9d6a555 100644
--- a/packages/docs/docs/media/video.mdx
+++ b/packages/docs/docs/media/video.mdx
@@ -137,7 +137,7 @@ By passing `trimAfter={120}`, any video after the 4 second mark in the file will
The video will play the range from `00:02:00` to `00:04:00`, meaning the video will play for 2 seconds.
-For exact behavior, see: [Order of operations](/docs/audio/order-of-operations).
+For exact behavior, see [Timing and trimming](/docs/timing).
```tsx twoslash
import {AbsoluteFill, staticFile} from 'remotion';
diff --git a/packages/docs/docs/offthreadvideo.mdx b/packages/docs/docs/offthreadvideo.mdx
index e0d8e38bf5..e6f893e4da 100644
--- a/packages/docs/docs/offthreadvideo.mdx
+++ b/packages/docs/docs/offthreadvideo.mdx
@@ -62,7 +62,7 @@ By passing `trimAfter={120}`, any video after the 4 second mark in the file will
The video will play the range from `00:02:00` to `00:04:00`, meaning the video will play for 2 seconds.
-For exact behavior, see: [Order of operations](/docs/audio/order-of-operations).
+For exact behavior, see [Timing and trimming](/docs/timing).
```tsx twoslash
import {AbsoluteFill, OffthreadVideo, staticFile} from 'remotion';
diff --git a/packages/docs/docs/sequence.mdx b/packages/docs/docs/sequence.mdx
index 0fb36084b1..29ac04bb05 100644
--- a/packages/docs/docs/sequence.mdx
+++ b/packages/docs/docs/sequence.mdx
@@ -244,6 +244,8 @@ A media component's own `playbackRate` also multiplies with its parent sequences
The rate applies to [`useCurrentFrame()`](/docs/use-current-frame) called inside descendant components. Animations calculated in the parent and passed as the sequence's `style` or as child props keep the parent's clock.
+For a combined example of position, trimming and playback speed, see [Timing and trimming](/docs/timing).
+
### `freeze?`<AvailableFrom v="4.0.476" />
Freezes the children of the sequence at the specified frame.
diff --git a/packages/docs/docs/timing.mdx b/packages/docs/docs/timing.mdx
new file mode 100644
index 0000000000..c6ac59bb8a
--- /dev/null
+++ b/packages/docs/docs/timing.mdx
@@ -0,0 +1,61 @@
+---
+image: /generated/articles-docs-timing.png
+id: timing
+title: Timing and trimming
+crumb: 'Getting started'
+---
+
+An item's position in the composition and the frame of its content are separate. Use [`from`](/docs/sequence#from) and [`durationInFrames`](/docs/sequence#durationinframes) to control when it appears. Use [`trimBefore`](/docs/sequence#trimbefore) and [`playbackRate`](/docs/sequence#playbackrate) to control which frame its children see.
+
+These timing props are available on [`<Sequence>`](/docs/sequence) and components such as [`<AbsoluteFill>`](/docs/absolute-fill), [`<Gif>`](/docs/gif/gif) and [`Interactive` components](/docs/interactive). Media also has source trimming props, which work differently from a sequence's `trimBefore`.
+
+## Position, trim and speed
+
+For a `<Sequence>`, `from` and `durationInFrames` are measured in the parent timeline. A finite `durationInFrames` unmounts the children at the end of that interval, without changing their frame number.
+
+From <AvailableFrom v="4.0.482" inline />, `trimBefore` advances the children's frame when they first appear. From <AvailableFrom v="4.0.528" inline />, `playbackRate` changes how quickly that frame advances. At parent frame `t`, the frame returned by [`useCurrentFrame()`](/docs/use-current-frame) inside the sequence is:
+
+```text
+(t - from) * playbackRate + trimBefore
+```
+
+For example:
+
+```tsx twoslash title="MyComposition.tsx"
+import {Sequence, useCurrentFrame} from 'remotion';
+
+const Counter = () => <div>{useCurrentFrame()}</div>;
+
+export const MyComposition = () => (
+ <Sequence from={30} durationInFrames={60} trimBefore={10} playbackRate={2}>
+ <Counter />
+ </Sequence>
+);
+```
+
+The counter appears at composition frame `30` and reads `10`. At composition frame `40`, it reads `30`. It remains visible through frame `89`; changing the speed does not change its 60-frame duration in the parent timeline.
+
+Nested sequences apply their timing in order from the outer sequence to the inner one. Their playback rates multiply. To trim the end of a sequence, set `durationInFrames`; `<Sequence>` has no `trimAfter` prop.
+
+## Trimming a media source
+
+[`<Audio>`](/docs/media/audio) and [`<Video>`](/docs/media/video) from `@remotion/media` use their own `trimBefore` and `trimAfter` props to select a range of the source file. `trimAfter` is the frame at which the source range ends, not a number of frames to remove. This differs from `<Sequence trimBefore>`, which advances the timeline seen by all its children.
+
+At 30 FPS, this video plays source frames `45` through `104` (1.5 to 3.5 seconds). At double speed, it takes 30 composition frames and appears from frame `30` through `59`:
+
+```tsx twoslash title="MyComposition.tsx"
+import {staticFile} from 'remotion';
+import {Video} from '@remotion/media';
+
+export const MyComposition = () => <Video src={staticFile('video.mp4')} from={30} trimBefore={45} trimAfter={105} playbackRate={2} />;
+```
+
+When `loop` is set, the selected source range repeats. Use `durationInFrames` to limit how long the loop remains on the composition timeline. Without a loop, `trimAfter` also limits how long the media can play.
+
+The legacy [`<Html5Audio>`](/docs/html5-audio), [`<Html5Video>`](/docs/html5-video) and [`<OffthreadVideo>`](/docs/offthreadvideo) components also support source trimming. Wrap them in a `<Sequence>` to position them or limit their duration.
+
+## See also
+
+- [`<Sequence>`](/docs/sequence)
+- [Trimming audio](/docs/audio/trimming)
+- [Adding a video](/docs/videos/)
diff --git a/packages/docs/docs/videos/index.mdx b/packages/docs/docs/videos/index.mdx
index 492b4bfdab..190229f4bd 100644
--- a/packages/docs/docs/videos/index.mdx
+++ b/packages/docs/docs/videos/index.mdx
@@ -157,7 +157,7 @@ export const MyComp: React.FC = () => {
};
```
-To learn how looping interacts with `trimBefore` and `trimAfter`, see [Order of operations](/docs/audio/order-of-operations).
+To learn how looping interacts with `trimBefore` and `trimAfter`, see [Timing and trimming](/docs/timing).
## GIFs
diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.ts
index c1213441ed..59bf809c29 100644
--- a/packages/docs/sidebars.ts
+++ b/packages/docs/sidebars.ts
@@ -1150,6 +1150,7 @@ const sidebars: SidebarsConfig = {
items: [
'getting-started',
'the-fundamentals',
+ 'timing',
'animating-properties',
'reusability',
'preview',
@@ -1223,7 +1224,6 @@ const sidebars: SidebarsConfig = {
'audio/visualization',
'audio/sfx',
'audio/exporting',
- 'audio/order-of-operations',
],
},
{
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 614bf4d8af..5188a9c4a2 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -431,15 +431,6 @@ export const articles = [
noAi: false,
slug: 'audio/muting',
},
- {
- id: 'order-of-operations',
- title: 'Order of Operations',
- relativePath: 'docs/audio/order-of-operations.mdx',
- compId: 'articles-docs-audio-order-of-operations',
- crumb: 'Audio',
- noAi: false,
- slug: 'audio/order-of-operations',
- },
{
id: 'pitch',
title: 'Controlling Pitch',
@@ -8273,6 +8264,15 @@ export const articles = [
noAi: false,
slug: 'timeout',
},
+ {
+ id: 'timing',
+ title: 'Timing and trimming',
+ relativePath: 'docs/timing.mdx',
+ compId: 'articles-docs-timing',
+ crumb: 'Getting started',
+ noAi: false,
+ slug: 'timing',
+ },
{
id: 'transforms',
title: 'Transforms',
diff --git a/packages/docs/static/generated/articles-docs-audio-order-of-operations.png b/packages/docs/static/generated/articles-docs-audio-order-of-operations.png
deleted file mode 100644
index 811e1cfa17..0000000000
Binary files a/packages/docs/static/generated/articles-docs-audio-order-of-operations.png and /dev/null differ
diff --git a/packages/docs/static/generated/articles-docs-timing.png b/packages/docs/static/generated/articles-docs-timing.png
new file mode 100644
index 0000000000..b4880e51d3
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-timing.png differ
diff --git a/packages/docs/vercel.ts b/packages/docs/vercel.ts
index 3bed690c39..e49cb9cbed 100644
--- a/packages/docs/vercel.ts
+++ b/packages/docs/vercel.ts
@@ -50,6 +50,12 @@ export const config: VercelConfig = {
]),
],
redirects: [
+ routes.redirect('/docs/audio/order-of-operations', '/docs/timing', {
+ permanent: true,
+ }),
+ routes.redirect('/docs/audio/order-of-operations.md', '/docs/timing.md', {
+ permanent: true,
+ }),
routes.redirect('/experimental_new', '/new', {permanent: true}),
routes.redirect(
'/elements/guidelines',