Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/audio.md
1---2name: audio3description: Using audio and sound in Remotion - importing, trimming, volume, speed, pitch4metadata:5tags: audio, media, trim, volume, speed, loop, pitch, mute, sound, sfx6---78# Using audio in Remotion910## Prerequisites1112First, the @remotion/media package needs to be installed.13If it is not installed, use the following command:1415```bash16npx remotion add @remotion/media17```1819## Importing Audio2021Use `<Audio>` from `@remotion/media` to add audio to your composition.2223```tsx24import { Audio } from "@remotion/media";25import { staticFile } from "remotion";2627export const MyComposition = () => {28return <Audio src={staticFile("audio.mp3")} />;29};30```3132Remote URLs are also supported:3334```tsx35<Audio src="https://remotion.media/audio.mp3" />36```3738By default, audio plays from the start, at full volume and full length.39Multiple audio tracks can be layered by adding multiple `<Audio>` components.4041## Trimming4243Use `trimBefore` and `trimAfter` to remove portions of the audio. Values are in frames.4445```tsx46const { fps } = useVideoConfig();4748return (49<Audio50src={staticFile("audio.mp3")}51trimBefore={2 * fps} // Skip the first 2 seconds52trimAfter={10 * fps} // End at the 10 second mark53/>54);55```5657The audio still starts playing at the beginning of the composition - only the specified portion is played.5859## Delaying6061Wrap the audio in a `<Sequence>` to delay when it starts:6263```tsx64import { Sequence, staticFile } from "remotion";65import { Audio } from "@remotion/media";6667const { fps } = useVideoConfig();6869return (70<Sequence from={1 * fps}>71<Audio src={staticFile("audio.mp3")} />72</Sequence>73);74```7576The audio will start playing after 1 second.7778## Volume7980Set a static volume (0 to 1):8182```tsx83<Audio src={staticFile("audio.mp3")} volume={0.5} />84```8586Or use a callback for dynamic volume based on the current frame:8788```tsx89import { interpolate } from "remotion";9091const { fps } = useVideoConfig();9293return (94<Audio95src={staticFile("audio.mp3")}96volume={(f) =>97interpolate(f, [0, 1 * fps], [0, 1], { extrapolateRight: "clamp" })98}99/>100);101```102103The value of `f` starts at 0 when the audio begins to play, not the composition frame.104105## Muting106107Use `muted` to silence the audio. It can be set dynamically:108109```tsx110const frame = useCurrentFrame();111const { fps } = useVideoConfig();112113return (114<Audio115src={staticFile("audio.mp3")}116muted={frame >= 2 * fps && frame <= 4 * fps} // Mute between 2s and 4s117/>118);119```120121## Speed122123Use `playbackRate` to change the playback speed:124125```tsx126<Audio src={staticFile("audio.mp3")} playbackRate={2} /> {/* 2x speed */}127<Audio src={staticFile("audio.mp3")} playbackRate={0.5} /> {/* Half speed */}128```129130Reverse playback is not supported.131132## Looping133134Use `loop` to loop the audio indefinitely:135136```tsx137<Audio src={staticFile("audio.mp3")} loop />138```139140Use `loopVolumeCurveBehavior` to control how the frame count behaves when looping:141142- `"repeat"`: Frame count resets to 0 each loop (default)143- `"extend"`: Frame count continues incrementing144145```tsx146<Audio147src={staticFile("audio.mp3")}148loop149loopVolumeCurveBehavior="extend"150volume={(f) => interpolate(f, [0, 300], [1, 0])} // Fade out over multiple loops151/>152```153154## Pitch155156Use `toneFrequency` to adjust the pitch without affecting speed. Values range from 0.01 to 2:157158```tsx159<Audio160src={staticFile("audio.mp3")}161toneFrequency={1.5} // Higher pitch162/>163<Audio164src={staticFile("audio.mp3")}165toneFrequency={0.8} // Lower pitch166/>167```168169Pitch shifting only works during server-side rendering, not in the Remotion Studio preview or in the `<Player />`.170