ahmedmaknessi/sum-of-parts / .claude/skills/remotion-markup
remotion-markup
VerifiedContent, animation and effects best practices
audio.md
View on GitHub---
name: audio
description: Using audio and sound in Remotion - importing, trimming, volume, speed, pitch
metadata:
tags: audio, media, trim, volume, speed, loop, pitch, mute, sound, sfx
---
# Using audio in Remotion
## Prerequisites
First, the @remotion/media package needs to be installed.
If it is not installed, use the following command:
```bash
npx remotion add @remotion/media
```
## Importing Audio
Use `<Audio>` from `@remotion/media` to add audio to your composition.
```tsx
import { Audio } from "@remotion/media";
import { staticFile } from "remotion";
export const MyComposition = () => {
return <Audio src={staticFile("audio.mp3")} />;
};
```
Remote URLs are also supported:
```tsx
import { Audio } from "@remotion/media";
<Audio src="https://remotion.media/audio.mp3" />
```
By default, audio plays from the start, at full volume and full length.
Multiple audio tracks can be layered by adding multiple `<Audio>` components.
## Trimming
Use `trimBefore` to skip the beginning of the audio and `durationInFrames` to end it early. Values are in frames.
```tsx
import { Audio } from "@remotion/media";
const { fps } = useVideoConfig();
return (
<Audio
src={staticFile("audio.mp3")}
trimBefore={2 * fps} // Skip the first 2 seconds
durationInFrames={8 * fps} // Play 8 seconds, until the 10 second mark
/>
);
```
The audio still starts playing at the beginning of the composition - only the specified portion is played.
## Delaying
Set `from` directly on `<Audio>` to delay when it starts:
```tsx
import { staticFile, useVideoConfig } from "remotion";
import { Audio } from "@remotion/media";
const { fps } = useVideoConfig();
return (
<Audio from={fps} src={staticFile("audio.mp3")} />
);
```
The audio will start playing after 1 second.
## Volume
Set a static volume (0 to 1):
```tsx
import { Audio } from "@remotion/media";
<Audio src={staticFile("audio.mp3")} volume={0.5} />
```
Use `useCurrentFrame()` and `interpolate()` for keyframed volume:
```tsx
import { Audio } from "@remotion/media";
import { interpolate, useCurrentFrame } from "remotion";
const frame = useCurrentFrame();
const { fps } = useVideoConfig();
return (
<Audio
src={staticFile("audio.mp3")}
volume={interpolate(frame, [0, 1 * fps], [0, 1], {
extrapolateLeft: "clamp",
extrapolateRight: "clamp",
})}
/>
);
```
With Studio interactivity enabled, these keyframes can be edited and are shown as a volume curve in the timeline.
The `volume` prop also accepts a callback for procedural or media-relative volume. The callback frame starts at 0 when the audio begins to play, not at the composition frame:
```tsx
import { Audio } from "@remotion/media";
<Audio
src={staticFile("audio.mp3")}
volume={(mediaFrame) => interpolate(mediaFrame, [0, 30], [0, 1])}
/>
```
## Muting
Use `muted` to silence the audio. It can be set dynamically:
```tsx
import { Audio } from "@remotion/media";
const frame = useCurrentFrame();
const { fps } = useVideoConfig();
return (
<Audio
src={staticFile("audio.mp3")}
muted={frame >= 2 * fps && frame <= 4 * fps} // Mute between 2s and 4s
/>
);
```
## Speed
Use `playbackRate` to change the playback speed:
```tsx
import { Audio } from "@remotion/media";
// 2x speed
<Audio src={staticFile("audio.mp3")} playbackRate={2} />
// Half speed
<Audio src={staticFile("audio.mp3")} playbackRate={0.5} />
```
Reverse playback is not supported.
## Looping
Use `loop` to loop the audio indefinitely:
```tsx
import { Audio } from "@remotion/media";
<Audio src={staticFile("audio.mp3")} loop premountFor={fps} />
```
Put `name`, `from`, `loop`, `volume`, and `premountFor` directly on `<Audio>`.
Use `loopVolumeCurveBehavior` to control how the frame count behaves when looping:
- `"repeat"`: Frame count resets to 0 each loop (default)
- `"extend"`: Frame count continues incrementing
```tsx
import { Audio } from "@remotion/media";
<Audio
src={staticFile("audio.mp3")}
loop
loopVolumeCurveBehavior="extend"
volume={(f) => interpolate(f, [0, 300], [1, 0])} // Fade out over multiple loops
/>
```
## Pitch
Use `toneFrequency` to adjust the pitch without affecting speed. Values range from 0.01 to 2:
```tsx
import { Audio } from "@remotion/media";
<Audio
src={staticFile("audio.mp3")}
toneFrequency={1.5} // Higher pitch
/>
<Audio
src={staticFile("audio.mp3")}
toneFrequency={0.8} // Lower pitch
/>
```
Pitch shifting only works during server-side rendering, not in the Remotion Studio preview or in the `<Player />`.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |