{"record":{"id":"9a52b909e9f97f7d","repo":"remotion-dev/remotion","slug":"expected-fmt-box-9a52b9","errorCode":null,"errorMessage":"Expected fmt box","messagePattern":"Expected fmt box","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/wav/parse-media-section.ts","lineNumber":25,"sourceCode":"export const parseMediaSection = async ({\n\tstate,\n}: {\n\tstate: ParserState;\n}): Promise<ParseResult> => {\n\tconst {iterator} = state;\n\tconst structure = state.structure.getWavStructure();\n\n\tconst videoSection = state.mediaSection.getMediaSectionAssertOnlyOne();\n\n\tconst maxOffset = videoSection.start + videoSection.size;\n\tconst maxRead = maxOffset - iterator.counter.getOffset();\n\tconst offset = iterator.counter.getOffset();\n\n\tconst fmtBox = structure.boxes.find((box) => box.type === 'wav-fmt') as\n\t\t| WavFmt\n\t\t| undefined;\n\tif (!fmtBox) {\n\t\tthrow new Error('Expected fmt box');\n\t}\n\n\tconst toRead = Math.min(\n\t\tmaxRead,\n\t\t(fmtBox.sampleRate * fmtBox.blockAlign) / WAVE_SAMPLES_PER_SECOND,\n\t);\n\n\tconst duration = toRead / (fmtBox.sampleRate * fmtBox.blockAlign);\n\tconst timestamp =\n\t\t(offset - videoSection.start) / (fmtBox.sampleRate * fmtBox.blockAlign);\n\n\tconst data = iterator.getSlice(toRead);\n\n\tconst audioSample = convertAudioOrVideoSampleToWebCodecsTimestamps({\n\t\tsample: {\n\t\t\tdecodingTimestamp: timestamp,\n\t\t\tdata,\n\t\t\tduration,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/wav/parse-media-section.ts#L7-L43","documentation":"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).","triggerScenarios":"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.","commonSituations":"Out-of-order chunks (non-compliant WAV); earlier fmt-parse error partially handled; truncated stream; requesting sample fields on a non-PCM/corrupted WAV.","solutions":["Check chunk order with ffprobe (fmt should precede data).","Re-export so fmt comes first: ffmpeg -i in.wav out.wav.","Use Mediabunny for sample extraction; try/catch the call."],"exampleFix":"# re-mux to fix chunk order\nffmpeg -i in.wav -c:a copy out.wav\n\ntry { await parseMedia({ src: 'out.wav' }); } catch { /* fallback */ }","handlingStrategy":"try-catch","validationCode":"// ffprobe validates chunk order (fmt before data)\n// ffprobe -v warning in.wav","typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({ src: 'in.wav' });\n} catch (err) {\n  if (err instanceof Error && /Expected fmt box/.test(err.message)) {\n    // fmt chunk missing/out-of-order — re-mux\n  } else throw err;\n}","preventionTips":["Re-mux WAVs so the fmt chunk precedes data (ffmpeg -i in.wav out.wav).","Use Mediabunny for sample extraction.","Probe the file before requesting sample-level fields."],"tags":["wav","media-parser","corrupt-file","audio","samples"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}