{"record":{"id":"5efed65affe7012a","repo":"remotion-dev/remotion","slug":"could-not-find-sample-rate-or-number-of-channels","errorCode":null,"errorMessage":"Could not find sample rate or number of channels","messagePattern":"Could not find sample rate or number of channels","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/webm/make-track.ts","lineNumber":388,"sourceCode":"\t\t\t\t: width.value.value,\n\t\t\trotation: 0,\n\t\t\tcodecData,\n\t\t\tcolorSpace: mediaParserAdvancedColorToWebCodecsColor(advancedColor),\n\t\t\tadvancedColor,\n\t\t\tcodecEnum,\n\t\t\tfps: null,\n\t\t\tstartInSeconds: 0,\n\t\t\ttimescale: WEBCODECS_TIMESCALE,\n\t\t\ttrackMediaTimeOffsetInTrackTimescale: 0,\n\t\t};\n\t}\n\n\tif (trackTypeToString(trackType.value.value) === 'audio') {\n\t\tconst sampleRate = getSampleRate(track);\n\t\tconst numberOfChannels = getNumberOfChannels(track);\n\t\tconst codecPrivate = getPrivateData(track);\n\t\tif (sampleRate === null) {\n\t\t\tthrow new Error('Could not find sample rate or number of channels');\n\t\t}\n\n\t\tconst codecString = getMatroskaAudioCodecString(track);\n\n\t\treturn {\n\t\t\ttype: 'audio',\n\t\t\ttrackId,\n\t\t\tcodec: codecString,\n\t\t\toriginalTimescale: timescale,\n\t\t\tnumberOfChannels,\n\t\t\tsampleRate,\n\t\t\tdescription: getAudioDescription(track),\n\t\t\tcodecData: codecPrivate\n\t\t\t\t? codecString === 'opus'\n\t\t\t\t\t? {type: 'ogg-identification', data: codecPrivate}\n\t\t\t\t\t: {type: 'unknown-data', data: codecPrivate}\n\t\t\t\t: null,\n\t\t\tcodecEnum: getMatroskaAudioCodecEnum({","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/webm/make-track.ts#L370-L406","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait parseMedia({src: 'broken.webm', fields: {tracks: true}}); // throws\n\n// after - re-mux first, then parse\n// shell: ffmpeg -i broken.webm -c copy fixed.webm\nawait parseMedia({src: 'fixed.webm', fields: {tracks: true}});","handlingStrategy":"try-catch","validationCode":"// Validate the audio track has SamplingFrequency before full parse.\n// Requires a low-level EBML walk; for callers, prefer ffprobe pre-check:\nimport {execFileSync} from 'node:child_process';\nfunction hasAudioSampleRate(file: string): boolean {\n  const out = execFileSync('ffprobe', ['-v', 'error', '-select_streams', 'a', '-show_entries', 'stream=sample_rate', '-of', 'csv=p=0', file], {encoding: 'utf8'});\n  return Number(out.trim()) > 0;\n}\nif (!hasAudioSampleRate('in.webm')) throw new Error('source audio track lacks sample rate');","typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({src: 'in.webm', fields: {tracks: true}});\n} catch (err) {\n  if (err instanceof Error && /sample rate or number of channels/.test(err.message)) {\n    // re-mux or fall back to a different source\n    throw new Error('Audio track missing SamplingFrequency; re-mux with ffmpeg.', {cause: err});\n  }\n  throw err;\n}","preventionTips":["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."],"tags":["webm","matroska","audio","media-parser","ebml","malformed-file"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}