remotion-dev/remotion · error · Error
Could not find sample rate or number of channels
Error message
Could not find sample rate or number of channels
What it means
Thrown while building an audio track descriptor from a Matroska TrackEntry: getSampleRate(track) returned null because the Audio sub-element has no SamplingFrequency child. The parser treats a missing SamplingFrequency as unrecoverable because WebCodecs requires a concrete sample rate to construct an audio decoder config. The message text also says 'number of channels', but only the sample-rate null check is actually performed; channel lookup is handled separately in getNumberOfChannels.
Source
Thrown at packages/media-parser/src/containers/webm/make-track.ts:388
: width.value.value,
rotation: 0,
codecData,
colorSpace: mediaParserAdvancedColorToWebCodecsColor(advancedColor),
advancedColor,
codecEnum,
fps: null,
startInSeconds: 0,
timescale: WEBCODECS_TIMESCALE,
trackMediaTimeOffsetInTrackTimescale: 0,
};
}
if (trackTypeToString(trackType.value.value) === 'audio') {
const sampleRate = getSampleRate(track);
const numberOfChannels = getNumberOfChannels(track);
const codecPrivate = getPrivateData(track);
if (sampleRate === null) {
throw new Error('Could not find sample rate or number of channels');
}
const codecString = getMatroskaAudioCodecString(track);
return {
type: 'audio',
trackId,
codec: codecString,
originalTimescale: timescale,
numberOfChannels,
sampleRate,
description: getAudioDescription(track),
codecData: codecPrivate
? codecString === 'opus'
? {type: 'ogg-identification', data: codecPrivate}
: {type: 'unknown-data', data: codecPrivate}
: null,
codecEnum: getMatroskaAudioCodecEnum({View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Re-mux the source with ffmpeg ('ffmpeg -i in.webm -c copy out.webm') so a complete TrackEntry with SamplingFrequency is written.
- Switch to the non-deprecated Mediabunny parser (parseMedia is deprecated), which may tolerate or repair the missing element.
- Inspect the file's TrackEntry with 'ffprobe -show_streams' to confirm whether sample_rate is reported; if ffprobe also fails, the file is malformed.
- Provide a different, valid source file.
Example fix
// before
await parseMedia({src: 'broken.webm', fields: {tracks: true}}); // throws
// after - re-mux first, then parse
// shell: ffmpeg -i broken.webm -c copy fixed.webm
await parseMedia({src: 'fixed.webm', fields: {tracks: true}}); Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the audio track has SamplingFrequency before full parse.
// Requires a low-level EBML walk; for callers, prefer ffprobe pre-check:
import {execFileSync} from 'node:child_process';
function hasAudioSampleRate(file: string): boolean {
const out = execFileSync('ffprobe', ['-v', 'error', '-select_streams', 'a', '-show_entries', 'stream=sample_rate', '-of', 'csv=p=0', file], {encoding: 'utf8'});
return Number(out.trim()) > 0;
}
if (!hasAudioSampleRate('in.webm')) throw new Error('source audio track lacks sample rate'); Try / catch
try {
await parseMedia({src: 'in.webm', fields: {tracks: true}});
} catch (err) {
if (err instanceof Error && /sample rate or number of channels/.test(err.message)) {
// re-mux or fall back to a different source
throw new Error('Audio track missing SamplingFrequency; re-mux with ffmpeg.', {cause: err});
}
throw err;
} Prevention
- Run 'ffprobe -show_streams' on client-supplied media before parsing.
- Re-mux uploads through ffmpeg before storing.
- Prefer the non-deprecated Mediabunny parser for new code.
When it happens
Trigger: parseMedia() is called on a .webm/.mkv whose TrackEntry has TrackType=2 (audio) but whose Audio element omits SamplingFrequency (or omits the Audio element entirely while TrackType still says audio). Encoders that rely on the SamplingFrequency default instead of writing the element, or hand-crafted/edited MKVs, trigger it.
Common situations: Re-muxing audio through tools that drop 'redundant default' elements; minimal MediaRecorder outputs on older browsers; files produced by experimental or partial encoders; truncated TrackEntry that was cut mid-stream.
Related errors
- Expected block segment
- Expected vorbis private data version 2
- Error parsing vorbis codec private
- Expected track entry segment
- Not enough bytes left to parse EBML - this should not happen
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/5efed65affe7012a.
Report an issue: GitHub.