remotion-dev/remotion · error
Could not find audio segment
Error message
Could not find audio segment
What it means
Thrown by getNumberOfChannels() in the WebM/Matroska traversal layer when the supplied TrackEntry has no child segment of type 'Audio'. Unlike getSampleRate() and getBitDepth() (which return null in this case), getNumberOfChannels treats a missing Audio segment as a hard error because a channel count is meaningless for a non-audio track. The throw signals that the caller passed the wrong track kind or inspected the track before its Audio child was parsed.
Source
Thrown at packages/media-parser/src/containers/webm/traversal.ts:322
if (!audioSegment) {
return null;
}
const samplingFrequency = audioSegment.value.find(
(b) => b.type === 'SamplingFrequency',
);
if (!samplingFrequency || samplingFrequency.type !== 'SamplingFrequency') {
return null;
}
return samplingFrequency.value.value;
};
export const getNumberOfChannels = (track: TrackEntry): number => {
const audioSegment = getAudioSegment(track);
if (!audioSegment) {
throw new Error('Could not find audio segment');
}
const channels = audioSegment.value.find((b) => b.type === 'Channels');
if (!channels || channels.type !== 'Channels') {
return 1;
}
return channels.value.value;
};
export const getBitDepth = (track: TrackEntry): number | null => {
const audioSegment = getAudioSegment(track);
if (!audioSegment) {
return null;
}
const bitDepth = audioSegment.value.find((b) => b.type === 'BitDepth');View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Filter tracks to audio tracks before calling getNumberOfChannels: use getAudioSegment(track) (which returns null instead of throwing) to gate the call.
- If parsing lazily, wait until parseMedia has emitted the tracks and the Audio child is populated before reading channel count.
- Validate the file with a tool such as ffprobe; a missing Audio element usually indicates a corrupt or non-audio track.
- Fall back to a default of 1 channel when getAudioSegment(track) returns null rather than calling getNumberOfChannels unconditionally.
Example fix
// before
for (const track of tracks) {
const channels = getNumberOfChannels(track);
}
// after
for (const track of tracks) {
if (!getAudioSegment(track)) continue;
const channels = getNumberOfChannels(track);
} Defensive patterns
Strategy: type-guard
Validate before calling
import {getAudioSegment} from '@remotion/media-parser/containers/webm/traversal';
const audio = getAudioSegment(track);
if (audio) {
const channels = getNumberOfChannels(track);
} Type guard
const isAudioTrackEntry = (track: TrackEntry): boolean => track.value.some((b) => b.type === 'Audio');
Try / catch
try { const ch = getNumberOfChannels(track); } catch (e) { if (e.message === 'Could not find audio segment') { /* skip non-audio track */ } else throw e; } Prevention
- Always gate getNumberOfChannels with getAudioSegment(track).
- Filter the track list to audio tracks before reading audio-only fields.
- Prefer getSampleRate/getBitDepth (which return null) when in doubt about track kind.
When it happens
Trigger: Calling getNumberOfChannels(track) on a TrackEntry that is a video track, a subtitle track, or an audio track whose 'Audio' child segment has not yet been encountered by the parser. Also triggered by passing a TrackEntry obtained from a malformed WebM/MKV that omits the Audio element.
Common situations: Iterating over all Matroska tracks and calling getNumberOfChannels on every entry without first filtering for audio tracks. Reading channel count during early parsing before the audio segment is available. Feeding a truncated or non-standard MKV/WebM produced by a buggy muxer.
Related errors
- Expected vorbis private data version 2
- Error parsing vorbis codec private
- Could not find sample rate or number of channels
- No 'src' was passed to <Html5Audio>.
- No src passed
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/cf93eab63bf1a193.
Report an issue: GitHub.