remotion-dev/remotion · error · Error

Expected fmt box

Error message

Expected fmt box

What it means

While reading PCM samples in parseMediaSection, the parser needs the already-parsed 'wav-fmt' box to compute byte-rates and timestamps. If the structure has no 'wav-fmt' box at that moment — fmt was skipped/failed earlier, or 'data' appeared before 'fmt ' — it throws. This fires only when sample extraction has started (e.g. an audio-sample field is requested).

Source

Thrown at packages/media-parser/src/containers/wav/parse-media-section.ts:25

export const parseMediaSection = async ({
	state,
}: {
	state: ParserState;
}): Promise<ParseResult> => {
	const {iterator} = state;
	const structure = state.structure.getWavStructure();

	const videoSection = state.mediaSection.getMediaSectionAssertOnlyOne();

	const maxOffset = videoSection.start + videoSection.size;
	const maxRead = maxOffset - iterator.counter.getOffset();
	const offset = iterator.counter.getOffset();

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

	const toRead = Math.min(
		maxRead,
		(fmtBox.sampleRate * fmtBox.blockAlign) / WAVE_SAMPLES_PER_SECOND,
	);

	const duration = toRead / (fmtBox.sampleRate * fmtBox.blockAlign);
	const timestamp =
		(offset - videoSection.start) / (fmtBox.sampleRate * fmtBox.blockAlign);

	const data = iterator.getSlice(toRead);

	const audioSample = convertAudioOrVideoSampleToWebCodecsTimestamps({
		sample: {
			decodingTimestamp: timestamp,
			data,
			duration,

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Check chunk order with ffprobe (fmt should precede data).
  2. Re-export so fmt comes first: ffmpeg -i in.wav out.wav.
  3. Use Mediabunny for sample extraction; try/catch the call.

Example fix

# re-mux to fix chunk order
ffmpeg -i in.wav -c:a copy out.wav

try { await parseMedia({ src: 'out.wav' }); } catch { /* fallback */ }
Defensive patterns

Strategy: try-catch

Validate before calling

// ffprobe validates chunk order (fmt before data)
// ffprobe -v warning in.wav

Try / catch

try {
  await parseMedia({ src: 'in.wav' });
} catch (err) {
  if (err instanceof Error && /Expected fmt box/.test(err.message)) {
    // fmt chunk missing/out-of-order — re-mux
  } else throw err;
}

Prevention

When it happens

Trigger: Requesting audio samples from a WAV whose fmt chunk was never parsed: an invalid WAV with 'data' before 'fmt ', a fmt chunk that failed an earlier guard, or a stream where sample reading began before fmt arrived.

Common situations: Out-of-order chunks (non-compliant WAV); earlier fmt-parse error partially handled; truncated stream; requesting sample fields on a non-PCM/corrupted WAV.

Related errors


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