{"record":{"id":"746d4cef02ca182d","repo":"remotion-dev/remotion","slug":"expected-codec","errorCode":null,"errorMessage":"Expected codec","messagePattern":"Expected codec","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/get-audio-codec.ts","lineNumber":224,"sourceCode":"\nexport const isLpcmAudioCodec = (trak: TrakBox): boolean => {\n\treturn getAudioCodecFromTrak(trak)?.format === 'lpcm';\n};\n\nexport const isIn24AudioCodec = (trak: TrakBox): boolean => {\n\treturn getAudioCodecFromTrak(trak)?.format === 'in24';\n};\n\nexport const isTwosAudioCodec = (trak: TrakBox): boolean => {\n\treturn getAudioCodecFromTrak(trak)?.format === 'twos';\n};\n\nexport const getAudioCodecStringFromTrak = (\n\ttrak: TrakBox,\n): {codecString: string; description: MediaParserCodecData | undefined} => {\n\tconst codec = getAudioCodecFromTrak(trak);\n\tif (!codec) {\n\t\tthrow new Error('Expected codec');\n\t}\n\n\tif (codec.format === 'lpcm') {\n\t\treturn {\n\t\t\tcodecString: 'pcm-s16',\n\t\t\tdescription: codec.description\n\t\t\t\t? {type: 'unknown-data', data: codec.description}\n\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\tif (codec.format === 'twos') {\n\t\treturn {\n\t\t\tcodecString: 'pcm-s16',\n\t\t\tdescription: codec.description\n\t\t\t\t? {type: 'unknown-data', data: codec.description}\n\t\t\t\t: undefined,\n\t\t};","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/get-audio-codec.ts#L206-L242","documentation":"Thrown by getAudioCodecStringFromTrak(trak) when getAudioCodecFromTrak(trak) returns null, meaning no recognizable audio codec could be derived from the trak's stsd sample entries. The function must produce a codec string, so a null upstream result is treated as a hard failure rather than emitting an undefined string.","triggerScenarios":"Calling getAudioCodecStringFromTrak on a trak whose stsd contains no audio sample entry, or whose sample entry format is unrecognized. Calling it on a video-only trak by mistake.","commonSituations":"Iterating all traks and deriving codec strings without checking whether each is an audio trak. Processing files with exotic or unsupported audio codecs. Mistakenly passing a hint track or tmcd track.","solutions":["Guard the call: only invoke getAudioCodecStringFromTrak on traks known to carry audio (e.g. after filtering by track type).","Use the boolean helpers (isLpcmAudioCodec/isIn24AudioCodec/isTwosAudioCodec) or getAudioCodecFromTrak directly and handle null.","Verify with ffprobe which trak is audio before deriving a codec string."],"exampleFix":"// before\nconst {codecString} = getAudioCodecStringFromTrak(trak);\n\n// after\nif (getAudioCodecFromTrak(trak)) {\n  const {codecString} = getAudioCodecStringFromTrak(trak);\n} else {\n  // not a recognized audio trak; skip\n}","handlingStrategy":"type-guard","validationCode":"import {getAudioCodecFromTrak} from '@remotion/media-parser/get-audio-codec';\nif (getAudioCodecFromTrak(trak)) {\n  const {codecString} = getAudioCodecStringFromTrak(trak);\n}","typeGuard":"const hasRecognizedAudioCodec = (trak: TrakBox): boolean => getAudioCodecFromTrak(trak) !== null;","tryCatchPattern":"try { getAudioCodecStringFromTrak(trak); } catch (e) { if (e.message === 'Expected codec') { /* skip unrecognized audio trak */ } else throw e; }","preventionTips":["Filter to audio traks before deriving codec strings.","Use the boolean helpers (isLpcmAudioCodec, etc.) for known formats.","Handle the null result of getAudioCodecFromTrak explicitly."],"tags":["mp4","audio","codec","validation"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}