remotion-dev/remotion · error · Error

Expected codec segment

Error message

Expected codec segment

What it means

Thrown by `getMatroskaAudioCodecEnum` (make-track.ts:141) when `getCodecSegment(track)` returns null — the audio TrackEntry has no `CodecID` child element. CodecID is mandatory for every Matroska track, so its absence is a spec violation that prevents mapping to an internal codec enum.

Source

Thrown at packages/media-parser/src/containers/webm/make-track.ts:141

		if (!priv) {
			throw new Error('Expected private data in AV1 track');
		}

		return parseAv1PrivateData(priv, null);
	}

	throw new Error(`Unknown codec: ${codec.value}`);
};

export const getMatroskaAudioCodecEnum = ({
	track,
}: {
	track: TrackEntry;
}): MediaParserAudioCodec => {
	const codec = getCodecSegment(track);
	if (!codec) {
		throw new Error('Expected codec segment');
	}

	if (codec.value === 'A_OPUS') {
		return 'opus';
	}

	if (codec.value === 'A_VORBIS') {
		return 'vorbis';
	}

	if (codec.value === 'A_PCM/INT/LIT') {
		// https://github.com/ietf-wg-cellar/matroska-specification/issues/142#issuecomment-330004950
		// Audio samples MUST be considered as signed values, except if the audio bit depth is 8 which MUST be interpreted as unsigned values.

		const bitDepth = getBitDepth(track);
		if (bitDepth === null) {
			throw new Error('Expected bit depth');
		}

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Re-mux or re-encode the file: `ffmpeg -i in.webm -c copy out.webm` (ffmpeg repairs missing elements where possible).
  2. Verify integrity with `ffprobe`; if ffprobe also fails, the file is corrupt.
  3. Catch and treat as unparseable.
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify the file is well-formed with ffprobe before parseMedia.
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
const exec = promisify(execFile);
async function isWellFormed(filePath) {
  try {
    await exec('ffprobe', ['-v', 'error', filePath]);
    return true;
  } catch {
    return false;
  }
}

Try / catch

try {
  await parseMedia({ src, fields: { tracks: true } });
} catch (err) {
  if (err instanceof Error && err.message === 'Expected codec segment') {
    console.warn('Audio TrackEntry missing CodecID — file is malformed:', src);
    return null;
  }
  throw err;
}

Prevention

When it happens

Trigger: Resolving an audio track whose TrackEntry lacks a `CodecID` element. Caused by malformed/truncated EBML, a parser mis-segmentation, or files emitted by a non-conformant muxer.

Common situations: Truncated .webm/.mkv where the TrackEntry was cut off before CodecID; corrupt headers; rarely, deliberately minimal test vectors. Most real muxers always emit CodecID.

Related errors


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/b61980c6c0a84838. Report an issue: GitHub.