Skip to main content

Using audio

Import audio

Put an audio file into the public/ folder and use staticFile() to reference it.
Add an <Audio/> tag to your composition to add sound to it.

tsx
import { AbsoluteFill, Audio, staticFile } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Audio src={staticFile("audio.mp3")} />
</AbsoluteFill>
);
};
tsx
import { AbsoluteFill, Audio, staticFile } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Audio src={staticFile("audio.mp3")} />
</AbsoluteFill>
);
};

The audio will play from the start, at full volume and full length, unless the composition is shorter.

You can also import remote audio by passing a URL: (src="https://example.com/audio.mp3").

tsx
import { AbsoluteFill, Audio } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Audio src="https://example.com/audio.mp3" />
</AbsoluteFill>
);
};
tsx
import { AbsoluteFill, Audio } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Audio src="https://example.com/audio.mp3" />
</AbsoluteFill>
);
};

You can mix multiple tracks together by adding more audio tags.

Cutting or trimming the audio

You can use <Sequence /> to cut and trim audio.

As a convenience, the <Audio /> tag supports the startFrom and endAt props. In the following example, we assume that the 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
import { AbsoluteFill, Audio, staticFile } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Audio src={staticFile("audio.mp3")} startFrom={60} endAt={120} />
</AbsoluteFill>
);
};
tsx
import { AbsoluteFill, Audio, staticFile } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Audio src={staticFile("audio.mp3")} startFrom={60} endAt={120} />
</AbsoluteFill>
);
};

Delaying audio

Use a <Sequence> with a positive from attribute to delay the audio from playing. In the following example, the audio will start playing (from the beginning) after 100 frames.

tsx
import { AbsoluteFill, Audio, Sequence, staticFile } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Sequence from={100}>
<Audio src={staticFile("audio.mp3")} />
</Sequence>
</AbsoluteFill>
);
};
tsx
import { AbsoluteFill, Audio, Sequence, staticFile } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Sequence from={100}>
<Audio src={staticFile("audio.mp3")} />
</Sequence>
</AbsoluteFill>
);
};

Controlling volume

You can use the volume prop to control the volume.

The simplest way is to pass a number between 0 and 1. 1 is the maximum volume and 0 mutes the audio.

tsx
import { Audio } from "remotion";
import audio from "./audio.mp3";
 
export const MyComposition = () => {
return (
<div>
<div>Hello World!</div>
<Audio src={audio} volume={0.5} />
</div>
);
};
tsx
import { Audio } from "remotion";
import audio from "./audio.mp3";
 
export const MyComposition = () => {
return (
<div>
<div>Hello World!</div>
<Audio src={audio} volume={0.5} />
</div>
);
};

You can also change volume over time by passing in a function that takes a frame number and returns the volume.

In this example we are using the interpolate() function to fade the audio in over 30 frames. Note that because values below 0 are not allowed, we need to set the extrapolateLeft: 'clamp' option to ensure no negative values.

Inside the callback function, the first frame on which audio is being played is frame 0, regardless of the value of useCurrentFrame().

tsx
import { AbsoluteFill, Audio, interpolate, staticFile } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Audio
src={staticFile("audio.mp3")}
volume={(f) =>
interpolate(f, [0, 30], [0, 1], { extrapolateLeft: "clamp" })
}
/>
</AbsoluteFill>
);
};
tsx
import { AbsoluteFill, Audio, interpolate, staticFile } from "remotion";
 
export const MyComposition = () => {
return (
<AbsoluteFill>
<Audio
src={staticFile("audio.mp3")}
volume={(f) =>
interpolate(f, [0, 30], [0, 1], { extrapolateLeft: "clamp" })
}
/>
</AbsoluteFill>
);
};
note

When using the <Player>, note that Mobile Safari does not support the volume property. The audio mix may not play as intended.

muted property

You may pass in the muted and it may change over time. When muted is true, audio will be omitted at that time. In the following example, we are muting the track between frame 40 and 60.

tsx
import { AbsoluteFill, Audio, staticFile, useCurrentFrame } from "remotion";
 
export const MyComposition = () => {
const frame = useCurrentFrame();
 
return (
<AbsoluteFill>
<Audio src={staticFile("audio.mp3")} muted={frame >= 40 && frame <= 60} />
</AbsoluteFill>
);
};
tsx
import { AbsoluteFill, Audio, staticFile, useCurrentFrame } from "remotion";
 
export const MyComposition = () => {
const frame = useCurrentFrame();
 
return (
<AbsoluteFill>
<Audio src={staticFile("audio.mp3")} muted={frame >= 40 && frame <= 60} />
</AbsoluteFill>
);
};

Use audio from <Video /> tags

Audio from <Video /> tags are also included in the output. You may also use the volume and muted props in the same way.

Controlling playback speed

Available from v2.2

You can use the playbackRate prop to control the speed of the audio. 1 is the default and means regular speed, 0.5 slows down the audio so it's twice as long and 2 speeds up the audio so it's twice as fast.

While Remotion doesn't limit the range of possible playback speeds, in development mode the HTMLMediaElement.playbackRate API is used which throws errors on extreme values. At the time of writing, Google Chrome throws an exception if the playback rate is below 0.0625 or above 16.

Audio visualization

You can obtain audio data and create visualizations based on it. See the page Audio visualization for more info.

Rendering audio only

Exporting as mp3, aac and wav is supported:

To render only the audio via CLI, specify an extension when exporting via CLI:

npx remotion render src/index.tsx my-comp out/audio.mp3
npx remotion render src/index.tsx my-comp out/audio.mp3

or use the --codec flag to automatically choose a good output file name:

npx remotion render src/index.tsx my-comp --codec=mp3
npx remotion render src/index.tsx my-comp --codec=mp3

See also