🎥 Make videos programmatically with React
`docs`: Prefer `durationInFrames` in media examples
JonnyBurger7df0464ae94f
diff --git a/packages/docs/docs/audio/trimming.mdx b/packages/docs/docs/audio/trimming.mdxindex 1d95add5a3..8a40fd4693 100644--- a/packages/docs/docs/audio/trimming.mdx+++ b/packages/docs/docs/audio/trimming.mdx@@ -9,8 +9,8 @@ crumb: 'Audio'import Tabs from '@theme/Tabs';import TabItem from '@theme/TabItem';-The [`<Audio />`](/docs/media/audio) and [`<Video />`](/docs/media/video) tags support the [`trimBefore`](/docs/media/audio#trimbefore) and [`trimAfter`](/docs/media/audio#trimafter) props.-[`<Html5Audio />`](/docs/html5-audio) also supports these props.+The [`<Audio />`](/docs/media/audio) and [`<Video />`](/docs/media/video) tags support the [`trimBefore`](/docs/media/audio#trimbefore) and [`durationInFrames`](/docs/media/audio#durationinframes) props.+Use them together to select a section of the source.```tsx twoslash {8} title="MyComp.tsx"import {AbsoluteFill, staticFile, useVideoConfig} from 'remotion';@@ -21,7 +21,7 @@ export const MyComposition = () => {return (<AbsoluteFill>- <Video src={staticFile('video.mp4')} trimBefore={2 * fps} trimAfter={4 * fps} />+ <Video src={staticFile('video.mp4')} trimBefore={2 * fps} durationInFrames={2 * fps} /></AbsoluteFill>);};diff --git a/packages/docs/docs/audiobuffertodataurl.mdx b/packages/docs/docs/audiobuffertodataurl.mdxindex c874833588..dd79decb1c 100644--- a/packages/docs/docs/audiobuffertodataurl.mdx+++ b/packages/docs/docs/audiobuffertodataurl.mdx@@ -72,7 +72,7 @@ export const OfflineAudioBufferExample: React.FC = () => {return audioBuffer ? (<Audiosrc={audioBuffer}- trimAfter={100}+ durationInFrames={100}volume={(f) =>interpolate(f, [0, 50, 100], [0, 1, 0], {extrapolateLeft: 'clamp',diff --git a/packages/docs/docs/html5-audio.mdx b/packages/docs/docs/html5-audio.mdxindex c5c4878ccd..88704a45ab 100644--- a/packages/docs/docs/html5-audio.mdx+++ b/packages/docs/docs/html5-audio.mdx@@ -79,17 +79,19 @@ Can be either `"repeat"` (default, start from 0 on each iteration) or `"extend"`In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.By passing `trimBefore={60}`, the playback starts immediately, but with the first 2 seconds of the audio trimmed away.-By passing `trimAfter={120}`, any audio after the 4 second mark in the file will be trimmed away.+By wrapping the audio in a [`<Sequence>`](/docs/sequence) with `durationInFrames={60}`, it plays for 60 frames.The audio will play the range from `00:02:00` to `00:04:00`, meaning the audio will play for 2 seconds.```tsx twoslash-import {AbsoluteFill, Html5Audio, staticFile} from 'remotion';+import {AbsoluteFill, Html5Audio, Sequence, staticFile} from 'remotion';export const MyVideo = () => {return (<AbsoluteFill>- <Html5Audio src={staticFile('audio.mp3')} trimBefore={60} trimAfter={120} />+ <Sequence durationInFrames={60}>+ <Html5Audio src={staticFile('audio.mp3')} trimBefore={60} />+ </Sequence></AbsoluteFill>);};diff --git a/packages/docs/docs/html5-video.mdx b/packages/docs/docs/html5-video.mdxindex e61e5871a7..84af17d370 100644--- a/packages/docs/docs/html5-video.mdx+++ b/packages/docs/docs/html5-video.mdx@@ -62,20 +62,22 @@ Will remove a portion of the video at the beginning (left side).In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.By passing `trimBefore={60}`, the playback starts immediately, but with the first 2 seconds of the video trimmed away.-By passing `trimAfter={120}`, any video after the 4 second mark in the file will be trimmed away.+By wrapping the video in a [`<Sequence>`](/docs/sequence) with `durationInFrames={60}`, it plays for 60 frames.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 [Timing and trimming](/docs/timing).```tsx twoslash-import {AbsoluteFill, staticFile, Html5Video} from 'remotion';+import {AbsoluteFill, Html5Video, Sequence, staticFile} from 'remotion';// ---cut---export const MyComposition = () => {return (<AbsoluteFill>- <Html5Video src={staticFile('video.webm')} trimBefore={60} trimAfter={120} />+ <Sequence durationInFrames={60}>+ <Html5Video src={staticFile('video.webm')} trimBefore={60} />+ </Sequence></AbsoluteFill>);};diff --git a/packages/docs/docs/media/audio.mdx b/packages/docs/docs/media/audio.mdxindex bfcc5ea8fd..8862213669 100644--- a/packages/docs/docs/media/audio.mdx+++ b/packages/docs/docs/media/audio.mdx@@ -84,7 +84,7 @@ Will remove a portion of the audio at the beginning (left side).In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.By passing `trimBefore={60}`, the playback starts immediately, but with the first 2 seconds of the audio trimmed away.-By passing `trimAfter={120}`, any audio after the 4 second mark in the file will be trimmed away.+By passing `durationInFrames={60}`, the audio plays for 60 source frames.The audio will play the range from `00:02:00` to `00:04:00`, meaning the audio will play for 2 seconds.@@ -98,7 +98,7 @@ import {Audio} from '@remotion/media';export const MyComposition = () => {return (<AbsoluteFill>- <Audio src={staticFile('audio.mp3')} trimBefore={60} trimAfter={120} />+ <Audio src={staticFile('audio.mp3')} trimBefore={60} durationInFrames={60} /></AbsoluteFill>);};diff --git a/packages/docs/docs/media/video.mdx b/packages/docs/docs/media/video.mdxindex 295876b547..72b5ba450b 100644--- a/packages/docs/docs/media/video.mdx+++ b/packages/docs/docs/media/video.mdx@@ -133,7 +133,7 @@ Will remove a portion of the video at the beginning (left side).In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.By passing `trimBefore={60}`, the playback starts immediately, but with the first 2 seconds of the video trimmed away.-By passing `trimAfter={120}`, any video after the 4 second mark in the file will be trimmed away.+By passing `durationInFrames={60}`, the video plays for 60 source frames.The video will play the range from `00:02:00` to `00:04:00`, meaning the video will play for 2 seconds.@@ -147,7 +147,7 @@ import {Video} from '@remotion/media';export const MyComposition = () => {return (<AbsoluteFill>- <Video src={staticFile('video.webm')} trimBefore={60} trimAfter={120} />+ <Video src={staticFile('video.webm')} trimBefore={60} durationInFrames={60} /></AbsoluteFill>);};diff --git a/packages/docs/docs/offthreadvideo.mdx b/packages/docs/docs/offthreadvideo.mdxindex e6f893e4da..132ade758f 100644--- a/packages/docs/docs/offthreadvideo.mdx+++ b/packages/docs/docs/offthreadvideo.mdx@@ -58,20 +58,22 @@ Will remove a portion of the video at the beginning (left side).In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.By passing `trimBefore={60}`, the playback starts immediately, but with the first 2 seconds of the video trimmed away.-By passing `trimAfter={120}`, any video after the 4 second mark in the file will be trimmed away.+By wrapping the video in a [`<Sequence>`](/docs/sequence) with `durationInFrames={60}`, it plays for 60 frames.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 [Timing and trimming](/docs/timing).```tsx twoslash-import {AbsoluteFill, OffthreadVideo, staticFile} from 'remotion';+import {AbsoluteFill, OffthreadVideo, Sequence, staticFile} from 'remotion';// ---cut---export const MyComposition = () => {return (<AbsoluteFill>- <OffthreadVideo src={staticFile('video.webm')} trimBefore={60} trimAfter={120} />+ <Sequence durationInFrames={60}>+ <OffthreadVideo src={staticFile('video.webm')} trimBefore={60} />+ </Sequence></AbsoluteFill>);};diff --git a/packages/docs/docs/videos/index.mdx b/packages/docs/docs/videos/index.mdxindex 190229f4bd..f9cd8cd55e 100644--- a/packages/docs/docs/videos/index.mdx+++ b/packages/docs/docs/videos/index.mdx@@ -46,7 +46,7 @@ export const MyComp: React.FC = () => {};```-Similarly, you can use [`trimAfter`](/docs/media/video#trimafter) to trim the end of the video.+Use [`durationInFrames`](/docs/media/video#durationinframes) to select how many source frames should play.```tsx twoslashimport React from 'react';@@ -54,7 +54,7 @@ import {Video} from '@remotion/media';import {staticFile} from 'remotion';export const MyComp: React.FC = () => {- return <Video src={staticFile('video.mp4')} trimBefore={60} trimAfter={120} />;+ return <Video src={staticFile('video.mp4')} trimBefore={60} durationInFrames={60} />;};```@@ -157,7 +157,7 @@ export const MyComp: React.FC = () => {};```-To learn how looping interacts with `trimBefore` and `trimAfter`, see [Timing and trimming](/docs/timing).+To learn how looping interacts with `trimBefore` and `durationInFrames`, see [Timing and trimming](/docs/timing).## GIFsdiff --git a/packages/docs/docs/videos/jumpcuts.mdx b/packages/docs/docs/videos/jumpcuts.mdxindex 2c488d6cbb..e9421b1e0d 100644--- a/packages/docs/docs/videos/jumpcuts.mdx+++ b/packages/docs/docs/videos/jumpcuts.mdx@@ -20,13 +20,13 @@ const fps = 30;type Section = {trimBefore: number;- trimAfter: number;+ durationInFrames: number;};export const SAMPLE_SECTIONS: Section[] = [- {trimBefore: 0, trimAfter: 5 * fps},- {trimBefore: 7 * fps, trimAfter: 10 * fps},- {trimBefore: 13 * fps, trimAfter: 18 * fps},+ {trimBefore: 0, durationInFrames: 5 * fps},+ {trimBefore: 7 * fps, durationInFrames: 3 * fps},+ {trimBefore: 13 * fps, durationInFrames: 5 * fps},];type Props = {@@ -35,7 +35,7 @@ type Props = {export const calculateMetadata: CalculateMetadataFunction<Props> = ({props}) => {const durationInFrames = props.sections.reduce((acc, section) => {- return acc + section.trimAfter - section.trimBefore;+ return acc + section.durationInFrames;}, 0);return {@@ -54,9 +54,13 @@ export const JumpCuts: React.FC<Props> = ({sections}) => {// Premount the next segment for 1.5 seconds so it can preload before it starts playingpremountFor={Math.round(1.5 * videoFps)}key={i}- durationInFrames={section.trimAfter - section.trimBefore}+ durationInFrames={section.durationInFrames}>- <Video trimBefore={section.trimBefore} trimAfter={section.trimAfter} src={staticFile('time.mp4')} />+ <Video+ trimBefore={section.trimBefore}+ durationInFrames={section.durationInFrames}+ src={staticFile('time.mp4')}+ /></Series.Sequence>))}</Series>diff --git a/packages/docs/elements/guidelines.mdx b/packages/docs/elements/guidelines.mdxindex fcc5271c0c..8bf1a6632f 100644--- a/packages/docs/elements/guidelines.mdx+++ b/packages/docs/elements/guidelines.mdx@@ -53,9 +53,9 @@ Wrap the exported component with [`Interactive.withSchema()`](/docs/interactive-Export the schema-enabled component directly and wire up the common props:- Add [`Interactive.baseSchema`](/docs/interactive#interactivebaseschema) to every `Interactive.withSchema()` schema and pass `controls` unchanged to the component's `<Sequence>`.-- Pass `from`, `durationInFrames`, `trimBefore`, `trimAfter`, `playbackRate`, `loop`, `freeze`, `hidden`, `name`, and `showInTimeline` to that Sequence.+- Pass `from`, `durationInFrames`, `trimBefore`, `playbackRate`, `loop`, `freeze`, `hidden`, `name`, and `showInTimeline` to that Sequence.- Pass `style` and the ref to the rendered element. With `layout="none"`, Studio discovers the outline automatically. Set the dimensions in the component because Element metadata does not pass them as props.-- Render frame-dependent animation in a child below the Sequence. This makes [`useCurrentFrame()`](/docs/use-current-frame) respect `from`, `trimBefore`, `trimAfter`, `playbackRate`, `loop`, and `freeze`. If the component that returns the Sequence calls it, it reads the parent clock.+- Render frame-dependent animation in a child below the Sequence. This makes [`useCurrentFrame()`](/docs/use-current-frame) respect `from`, `trimBefore`, `durationInFrames`, `playbackRate`, `loop`, and `freeze`. If the component that returns the Sequence calls it, it reads the parent clock.Export the schema-enabled component directly, without a forwarding wrapper. See the [oscilloscope](/elements/audio/oscilloscope), [waveform progress](/elements/audio/waveform-progress), and [mirrored spectrum](/elements/audio/mirrored-spectrum) Elements.