remotion-dev/remotion · error · Error

Expected bit depth

Error message

Expected bit depth

What it means

Thrown by `getMatroskaAudioCodecEnum` (make-track.ts:158) for an `A_PCM/INT/LIT` audio track whose TrackEntry has no `AudioBitDepth` element. Bit depth is mandatory for PCM tracks because the parser must select `pcm-u8` / `pcm-s16` / `pcm-s24`; without it the PCM format is ambiguous.

Source

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

	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');
		}

		if (bitDepth === 8) {
			return 'pcm-u8';
		}

		if (bitDepth === 16) {
			return 'pcm-s16';
		}

		if (bitDepth === 24) {
			return 'pcm-s24';
		}

		throw new Error('Unknown audio format');
	}

	if (codec.value === 'A_AAC') {

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Re-encode the audio to a self-describing codec: `ffmpeg -i in.mkv -c:a pcm_s16le out.mkv` (ensures bit depth is set).
  2. Prefer a non-PCM container (WAV/FLAC) for raw PCM where bit depth is always explicit.
  3. Verify with `ffprobe` and reject malformed assets.
Defensive patterns

Strategy: validation

Validate before calling

// Reject PCM tracks whose bit depth is unknown — probe with ffprobe.
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
const exec = promisify(execFile);
async function pcmBitDepth(filePath) {
  const { stdout } = await exec('ffprobe', ['-v', 'error', '-select_entries', 'stream=codec_name,bits_per_sample', '-of', 'json', filePath]);
  const info = JSON.parse(stdout);
  const pcm = info.streams?.find((s) => /pcm/i.test(s.codec_name ?? ''));
  return pcm?.bits_per_sample ?? null;
}

Try / catch

try {
  await parseMedia({ src, fields: { tracks: true } });
} catch (err) {
  if (err instanceof Error && err.message === 'Expected bit depth') {
    console.warn('PCM track missing AudioBitDepth — re-encode the file.');
  }
  throw err;
}

Prevention

When it happens

Trigger: A PCM (signed little-endian integer) audio track missing the `AudioBitDepth` child element. Occurs with malformed muxers or truncated headers.

Common situations: Hand-crafted or corrupted MKV PCM tracks; encoder bugs that omit `AudioBitDepth`; rare in production since PCM is uncommon in WebM.

Related errors


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