remotion-dev/remotion · error
Expected codec
Error message
Expected codec
What it means
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.
Source
Thrown at packages/media-parser/src/get-audio-codec.ts:224
export const isLpcmAudioCodec = (trak: TrakBox): boolean => {
return getAudioCodecFromTrak(trak)?.format === 'lpcm';
};
export const isIn24AudioCodec = (trak: TrakBox): boolean => {
return getAudioCodecFromTrak(trak)?.format === 'in24';
};
export const isTwosAudioCodec = (trak: TrakBox): boolean => {
return getAudioCodecFromTrak(trak)?.format === 'twos';
};
export const getAudioCodecStringFromTrak = (
trak: TrakBox,
): {codecString: string; description: MediaParserCodecData | undefined} => {
const codec = getAudioCodecFromTrak(trak);
if (!codec) {
throw new Error('Expected codec');
}
if (codec.format === 'lpcm') {
return {
codecString: 'pcm-s16',
description: codec.description
? {type: 'unknown-data', data: codec.description}
: undefined,
};
}
if (codec.format === 'twos') {
return {
codecString: 'pcm-s16',
description: codec.description
? {type: 'unknown-data', data: codec.description}
: undefined,
};View on GitHub (pinned to 78fe4bb3fd)
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.
Example fix
// before
const {codecString} = getAudioCodecStringFromTrak(trak);
// after
if (getAudioCodecFromTrak(trak)) {
const {codecString} = getAudioCodecStringFromTrak(trak);
} else {
// not a recognized audio trak; skip
} Defensive patterns
Strategy: type-guard
Validate before calling
import {getAudioCodecFromTrak} from '@remotion/media-parser/get-audio-codec';
if (getAudioCodecFromTrak(trak)) {
const {codecString} = getAudioCodecStringFromTrak(trak);
} Type guard
const hasRecognizedAudioCodec = (trak: TrakBox): boolean => getAudioCodecFromTrak(trak) !== null;
Try / catch
try { getAudioCodecStringFromTrak(trak); } catch (e) { if (e.message === 'Expected codec') { /* skip unrecognized audio trak */ } else throw e; } Prevention
- Filter to audio traks before deriving codec strings.
- Use the boolean helpers (isLpcmAudioCodec, etc.) for known formats.
- Handle the null result of getAudioCodecFromTrak explicitly.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not find audio sample
- Could not find number of channels
- Could not find sample rate
- No decoder-config-descriptor
- No audio-specific-config
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/746d4cef02ca182d.
Report an issue: GitHub.