remotion-dev/remotion · error · Error

Expected fmt box

Error message

Expected fmt box

What it means

Thrown by getDurationFromWav at get-duration-from-wav.ts:11 when the WAV structure has no box of type 'wav-fmt'. The fmt chunk (RIFF 'fmt ') carries the sample rate, channel count, and block align needed to compute duration; without it, duration is undefined.

Source

Thrown at packages/media-parser/src/containers/wav/get-duration-from-wav.ts:11

import type {ParserState} from '../../state/parser-state';
import type {WavData, WavFmt} from './types';

export const getDurationFromWav = (state: ParserState) => {
	const structure = state.structure.getWavStructure();

	const fmt = structure.boxes.find((b) => b.type === 'wav-fmt') as
		| WavFmt
		| undefined;
	if (!fmt) {
		throw new Error('Expected fmt box');
	}

	const dataBox = structure.boxes.find((b) => b.type === 'wav-data') as WavData;
	if (!dataBox) {
		throw new Error('Expected data box');
	}

	const durationInSeconds =
		dataBox.dataSize / (fmt.sampleRate * fmt.blockAlign);
	return durationInSeconds;
};

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Re-encode the WAV with a conformant tool: ffmpeg -i in.wav -c:a pcm_s16le out.wav.
  2. Verify the WAV with ffprobe -show_format that the fmt chunk is present.
  3. Ensure the entire WAV header (including fmt) is read before calling duration APIs.
  4. If you control the writer, always emit fmt as the first subchunk after the RIFF header.
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the WAV has a fmt chunk before parsing
import {execSync} from 'node:child_process';
function hasWavFmt(src: string): boolean {
  try {
    const out = execSync(`ffprobe -v error -show_entries stream=codec_name -of csv=p=0 "${src}"`).toString().trim();
    return out.startsWith('pcm_') || out === 'wavpack' || out === 'adpcm';
  } catch { return false; }
}

Try / catch

try { await parseMedia({src, fields: {durationInSeconds: true}}); }
catch (e) {
  if (e instanceof Error && e.message === 'Expected fmt box') {
    // re-encode WAV with a conformant header
    await runFfmpeg(['-i', src, '-c:a', 'pcm_s16le', out]);
    await parseMedia({src: out, fields: {durationInSeconds: true}});
  } else throw e;
}

Prevention

When it happens

Trigger: getDurationFromWav scans structure.boxes for type 'wav-fmt' and throws if missing. Triggered when getDurationFromWav is called before the fmt chunk has been parsed, when the WAV file omits the fmt chunk (non-conformant), or when the parser has only seen part of the file.

Common situations: Truncated WAV files where the fmt chunk is missing or incomplete; malformed WAVs produced by custom generators; getDurationFromWav invoked at the wrong stage of parsing; WAV files with non-standard chunk ordering where parsing stopped early.

Related errors


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