{"record":{"id":"cf93eab63bf1a193","repo":"remotion-dev/remotion","slug":"could-not-find-audio-segment","errorCode":null,"errorMessage":"Could not find audio segment","messagePattern":"Could not find audio segment","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/webm/traversal.ts","lineNumber":322,"sourceCode":"\tif (!audioSegment) {\n\t\treturn null;\n\t}\n\n\tconst samplingFrequency = audioSegment.value.find(\n\t\t(b) => b.type === 'SamplingFrequency',\n\t);\n\n\tif (!samplingFrequency || samplingFrequency.type !== 'SamplingFrequency') {\n\t\treturn null;\n\t}\n\n\treturn samplingFrequency.value.value;\n};\n\nexport const getNumberOfChannels = (track: TrackEntry): number => {\n\tconst audioSegment = getAudioSegment(track);\n\tif (!audioSegment) {\n\t\tthrow new Error('Could not find audio segment');\n\t}\n\n\tconst channels = audioSegment.value.find((b) => b.type === 'Channels');\n\n\tif (!channels || channels.type !== 'Channels') {\n\t\treturn 1;\n\t}\n\n\treturn channels.value.value;\n};\n\nexport const getBitDepth = (track: TrackEntry): number | null => {\n\tconst audioSegment = getAudioSegment(track);\n\tif (!audioSegment) {\n\t\treturn null;\n\t}\n\n\tconst bitDepth = audioSegment.value.find((b) => b.type === 'BitDepth');","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/webm/traversal.ts#L304-L340","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nfor (const track of tracks) {\n  const channels = getNumberOfChannels(track);\n}\n\n// after\nfor (const track of tracks) {\n  if (!getAudioSegment(track)) continue;\n  const channels = getNumberOfChannels(track);\n}","handlingStrategy":"type-guard","validationCode":"import {getAudioSegment} from '@remotion/media-parser/containers/webm/traversal';\n\nconst audio = getAudioSegment(track);\nif (audio) {\n  const channels = getNumberOfChannels(track);\n}","typeGuard":"const isAudioTrackEntry = (track: TrackEntry): boolean =>\n  track.value.some((b) => b.type === 'Audio');","tryCatchPattern":"try { const ch = getNumberOfChannels(track); } catch (e) { if (e.message === 'Could not find audio segment') { /* skip non-audio track */ } else throw e; }","preventionTips":["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."],"tags":["webm","matroska","audio","container-parsing","validation"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}