🎥 Make videos programmatically with React
Reorder timing docs and clarify prop behavior
JonnyBurgere8e334271995
diff --git a/packages/docs/docs/timing.mdx b/packages/docs/docs/timing.mdxindex c81bced868..5dfcf80d23 100644--- a/packages/docs/docs/timing.mdx+++ b/packages/docs/docs/timing.mdx@@ -19,7 +19,8 @@ The way timing works is standardized across these components:## `from`: Move an item-`from` moves an item on its parent timeline. By default, its children start at frame `0` when it appears:+`from` moves an item on the timeline.+By default, its children start at frame `0` when it appears:<TimingTimeline from={30} trimBefore={0} trimAfter={null} playbackRate={1} loop={false} />@@ -35,11 +36,11 @@ export const MyComposition = () => ();```-## `durationInFrames`: Limit an item+## `trimBefore`: Trim the beginning-`durationInFrames` sets how long an item stays on its parent timeline, starting at `from`.+`trimBefore` trims the beginning of an item.-<TimingTimeline from={30} durationInFrames={45} trimBefore={0} trimAfter={null} playbackRate={1} loop={false} />+<TimingTimeline from={30} trimBefore={15} trimAfter={null} playbackRate={1} loop={false} />```tsx twoslash title="MyComposition.tsx"import {Interactive, useCurrentFrame} from 'remotion';@@ -47,17 +48,17 @@ import {Interactive, useCurrentFrame} from 'remotion';const Counter = () => <div>{useCurrentFrame()}</div>;export const MyComposition = () => (- <Interactive.Div from={30} durationInFrames={45}>+ <Interactive.Div from={30} trimBefore={15}><Counter /></Interactive.Div>);```-## `trimBefore`: Trim the beginning+## `trimAfter`: Trim the end-`trimBefore` skips the beginning of an item's content without moving it from its `from` position.+`trimAfter` trims an item to end early.-<TimingTimeline from={30} trimBefore={15} trimAfter={null} playbackRate={1} loop={false} />+<TimingTimeline from={30} trimBefore={45} trimAfter={105} playbackRate={2} loop={false} />```tsx twoslash title="MyComposition.tsx"import {Interactive, useCurrentFrame} from 'remotion';@@ -65,7 +66,12 @@ import {Interactive, useCurrentFrame} from 'remotion';const Counter = () => <div>{useCurrentFrame()}</div>;export const MyComposition = () => (- <Interactive.Div from={30} trimBefore={15}>+ <Interactive.Div+ from={30}+ trimBefore={45}+ trimAfter={105}+ playbackRate={2}+ ><Counter /></Interactive.Div>);@@ -73,7 +79,7 @@ export const MyComposition = () => (## `playbackRate`: Change speed of an item-`playbackRate` on `<Interactive.Div>` changes how quickly its children's frame advances.+`playbackRate` changes the speed of its children.<TimingTimeline from={30} trimBefore={15} trimAfter={null} playbackRate={2} loop={false} />@@ -93,13 +99,11 @@ export const MyComposition = () => ();```-## `trimAfter`: Trim the end--`trimAfter` selects where the content ends, measured in the same clock as `trimBefore`: the frame that the children receive from [`useCurrentFrame()`](/docs/use-current-frame).+## `loop`: Repeat an item-The item shows the child frames from `trimBefore` up to, but not including, `trimAfter`. It therefore ends after `(trimAfter - trimBefore) / playbackRate` parent frames, unless `durationInFrames` or the parent ends it earlier.+`loop` repeats the range selected by `trimBefore` and `trimAfter`.-<TimingTimeline from={30} trimBefore={45} trimAfter={105} playbackRate={2} loop={false} />+<TimingTimeline from={30} durationInFrames={90} trimBefore={45} trimAfter={105} playbackRate={2} loop />```tsx twoslash title="MyComposition.tsx"import {Interactive, useCurrentFrame} from 'remotion';@@ -112,23 +116,23 @@ export const MyComposition = () => (trimBefore={45}trimAfter={105}playbackRate={2}+ loop+ durationInFrames={90}><Counter /></Interactive.Div>);```-For `<Video>` and `<Audio>`, the child clock is the position in the source file in composition frames.-At 30 composition FPS, `trimBefore={45}` and `trimAfter={105}` select the source from 1.5 to 3.5 seconds.-If `trimAfter` is omitted, playback continues until the end of the file.--## `loop`: Repeat an item+[`<Video>`](/docs/media/video) and [`<Audio>`](/docs/media/audio) have an intrinsic duration, so they may omit `trimAfter` when passing `loop`.+All other items require `trimAfter` to loop.-`loop` repeats the range selected by `trimBefore` and `trimAfter`.+## `durationInFrames`: Limit an item-`durationInFrames` limits the total length of the item. Without it, the item loops until its parent ends.+`durationInFrames` sets how long an item stays on the timeline, starting at `from`.+It is not affected by `playbackRate` and `loop`.-<TimingTimeline from={30} durationInFrames={90} trimBefore={45} trimAfter={105} playbackRate={2} loop />+<TimingTimeline from={30} durationInFrames={45} trimBefore={0} trimAfter={null} playbackRate={1} loop={false} />```tsx twoslash title="MyComposition.tsx"import {Interactive, useCurrentFrame} from 'remotion';@@ -136,26 +140,12 @@ import {Interactive, useCurrentFrame} from 'remotion';const Counter = () => <div>{useCurrentFrame()}</div>;export const MyComposition = () => (- <Interactive.Div- from={30}- trimBefore={45}- trimAfter={105}- playbackRate={2}- loop- durationInFrames={90}- >+ <Interactive.Div from={30} durationInFrames={45}><Counter /></Interactive.Div>);```-This repeats the selected 60 child frames three times over 90 composition frames.--`<Video>` and `<Audio>` have an intrinsic duration, so they may omit `trimAfter` and loop the whole file after `trimBefore`.-All other items require `trimAfter` to loop, because they have no intrinsic end.--[`<Loop>`](/docs/loop) is a shorthand for the same behavior with a period measured in the parent timeline: `<Loop durationInFrames={50} times={3}>` is equivalent to `trimAfter={50}`, `durationInFrames={150}` and `loop`.-## Order of operationsThink of the timing props as applying to the content in this order:@@ -165,16 +155,18 @@ Think of the timing props as applying to the content in this order:3. `loop` repeats the stretched range4. `durationInFrames` is applied last and defines the duration of the item in the timeline.-For an item with children, [`useCurrentFrame()`](/docs/use-current-frame) at parent frame `t` is:+## Formula-```-trimBefore + (t - from) * playbackRate+Child components calling [`useCurrentFrame()`](/docs/use-current-frame) get:++```md+trimBefore + (frame - from) * playbackRate```-If the item loops, the elapsed child frames wrap around at the end of the range:+If the item loops:-```-trimBefore + ((t - from) * playbackRate) % (trimAfter - trimBefore)+```md+trimBefore + ((frame - from) * playbackRate) % (trimAfter - trimBefore)```## See also