packages/docs/docs/webcodecs/get-partial-audio-data.mdx
:::warning We are phasing out Remotion WebCodecs and are moving to Mediabunny! :::
import {UnstableDisclaimer} from './UnstableDisclaimer';
:::warning
<UnstableDisclaimer /> :::Part of the @remotion/webcodecs package.
Extracts audio data from a specific time window of a media file and returns it as a Float32Array.
import {getPartialAudioData} from '@remotion/webcodecs';
const audioData = await getPartialAudioData({
src: 'https://remotion.media/audio.wav',
fromSeconds: 10,
toSeconds: 20,
channelIndex: 0, // Left channel for stereo audio
signal: new AbortController().signal,
});
console.log('Audio samples:', audioData.length);
console.log('First sample value:', audioData[0]);
srcstring
A URL pointing to a media file, or a File/Blob object.
If it is a remote URL, it must support CORS and the server must support byte-range requests for efficient seeking.
fromSecondsnumber
The start time in seconds from which to extract audio data.
toSecondsnumber
The end time in seconds until which to extract audio data.
channelIndexnumber
The audio channel index to extract. For stereo audio:
0 = Left channel1 = Right channelFor mono audio, use 0.
signalAbortSignal
An AbortSignal to cancel the operation.
import {getPartialAudioData} from '@remotion/webcodecs';
import {hasBeenAborted} from '@remotion/media-parser';
const controller = new AbortController();
// Cancel after 5 seconds
setTimeout(() => controller.abort(), 5000);
try {
const audioData = await getPartialAudioData({
src: 'https://remotion.media/audio.wav',
fromSeconds: 0,
toSeconds: 30,
channelIndex: 0,
signal: controller.signal,
});
} catch (err) {
if (hasBeenAborted(err)) {
console.log('Operation was cancelled');
}
}
Returns a Promise<Float32Array> containing the audio samples for the requested time window and channel.
The sample values are normalized floating-point numbers typically in the range of -1.0 to 1.0.
@remotion/media-parser for parsing and WebCodecs for efficient audio decoding