🎥 Make videos programmatically with React
revamp documentation page for <Audio>
Jonny Burgerda390f266e27
diff --git a/packages/docs/blog/2021-07-09-remotion-2-2.md b/packages/docs/blog/2021-07-09-remotion-2-2.mdindex 7d5496dc9e..ee82c68b0b 100644--- a/packages/docs/blog/2021-07-09-remotion-2-2.md+++ b/packages/docs/blog/2021-07-09-remotion-2-2.md@@ -25,16 +25,16 @@ This new core component will freeze all of it's children and make them think thaYou can use it for example to display a still frame from a video:```tsx twoslash title="MyVideo.tsx"-import {Freeze, Video} from 'remotion';-import myVid from './vid.mp4';+import { Freeze, Video } from "remotion";+import myVid from "./vid.mp4";export const MyVideo = () => {return (<Freeze frame={30}><Video src={myVid} /></Freeze>- )-}+ );+};```However, it works for any content. As you can see the API is dead simple! You can combine it with the [`<Sequence>`](/docs/sequence) API to make any content play, pause and then continue again.@@ -46,19 +46,17 @@ However, it works for any content. As you can see the API is dead simple! You caThis prop allows you to slow down or speed up video and audio elements! Now you can import a video in normal speed and play it in slow motion or timelapse without re-rendering the video.```tsx twoslash title="LightningSpeed.tsx"-import {Video} from 'remotion';-import myVid from './vid.mp4';+import { Video } from "remotion";+import myVid from "./vid.mp4";export const MyVideo = () => {- return (- <Video src={myVid} playbackRate={4}/>- )-}+ return <Video src={myVid} playbackRate={4} />;+};```While previewing, we are using the HTML5 `playbackRate` API, and when rendering, we will calculate the correct FFMPEG command for any tempo.-Learn more about the `playbackRate` props for [`<Audio />`](/docs/audio/#controlling-playback-speed) and [`<Video />`](/docs/video/#controlling-playback-speed).+Learn more about the `playbackRate` props for [`<Audio />`](/docs/audio/#playbackrate) and [`<Video />`](/docs/video/#controlling-playback-speed).## `@remotion/three` packagediff --git a/packages/docs/docs/audio.md b/packages/docs/docs/audio.mdindex fef8b1a376..01338020c6 100644--- a/packages/docs/docs/audio.md+++ b/packages/docs/docs/audio.md@@ -5,37 +5,74 @@ id: audioUsing this component, you can add audio to your video. All audio formats which are supported by Chromium are supported by the component.-## API / Example+## API-Use an import or require to load an audio file and pass it to the `src` props of the `<Audio />` component.+### `src`-The component also accepts a `volume` props which allows you to control the volume of the audio in it's entirety or frame by frame. Read the page on [using audio](/docs/using-audio) to learn more.+[Put an audio file into the `public/` folder](/docs/assets) and use [`staticFile()`](/docs/staticfile) to reference it.++```tsx twoslash+import { AbsoluteFill, Audio, staticFile } from "remotion";-`<Audio>` has two more helper props: `startFrom` and `endAt` for defining the start frame and end frame. Both are optional and do not get forwarded to the native `<audio>` element but tell Remotion which portion of the audio should be included.+export const MyVideo = () => {+ return (+ <AbsoluteFill>+ <Audio src={staticFile("audio.mp3")} />+ </AbsoluteFill>+ );+};+```++### `volume`++The component also accepts a `volume` props which allows you to control the volume of the audio in it's entirety or frame by frame. Read the page on [using audio](/docs/using-audio) to learn more.```tsx twoslash-import { Audio } from "remotion";-import audio from "./audio.mp3";+import { AbsoluteFill, Audio, interpolate, staticFile } from "remotion";export const MyVideo = () => {return (- <div>- <div>Hello World!</div>+ <AbsoluteFill>+ <Audio volume={0.5} src={staticFile("background.mp3")} /><Audio- src={audio}- startFrom={59} // if composition is 30fps, then it will start at 2s- endAt={120} // if composition is 30fps, then it will end at 4s+ volume={(f) =>+ interpolate(f, [0, 30], [0, 1], { extrapolateLeft: "clamp" })+ }+ src={staticFile("voice.mp3")}/>- </div>+ </AbsoluteFill>);};```-## Controlling volume+### `startFrom` / `endAt`++`<Audio>` has two more helper props you can use:-You can use the `volume` prop to control the loudness of the audio. See [Controlling audio](/docs/using-audio#controlling-volume) for more information.+- `startFrom` will remove a portion of the audio at the beginning+- `endAt` will remove a portion of the audio at the end++In the following example, we assume that the [`fps`](/docs/composition#fps) of the composition is `30`.++By passing `startFrom={60}`, the playback starts immediately, but with the first 2 seconds of the audio trimmed away.+By passing `endAt={120}`, any audio after the 4 second mark in the file will be trimmed away.++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 { Audio, staticFile } from "remotion";++export const MyVideo = () => {+ return (+ <div>+ <div>Hello World!</div>+ <Audio src={staticFile("audio.mp3")} startFrom={60} endAt={120} />+ </div>+ );+};+```-## Controlling playback speed+### `playbackRate`_Available from v2.2_