{"record":{"id":"ae0bb8dbe746312e","repo":"remotion-dev/remotion","slug":"expected-fmt-box","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/get-duration-from-wav.ts","lineNumber":11,"sourceCode":"import type {ParserState} from '../../state/parser-state';\nimport type {WavData, WavFmt} from './types';\n\nexport const getDurationFromWav = (state: ParserState) => {\n\tconst structure = state.structure.getWavStructure();\n\n\tconst fmt = structure.boxes.find((b) => b.type === 'wav-fmt') as\n\t\t| WavFmt\n\t\t| undefined;\n\tif (!fmt) {\n\t\tthrow new Error('Expected fmt box');\n\t}\n\n\tconst dataBox = structure.boxes.find((b) => b.type === 'wav-data') as WavData;\n\tif (!dataBox) {\n\t\tthrow new Error('Expected data box');\n\t}\n\n\tconst durationInSeconds =\n\t\tdataBox.dataSize / (fmt.sampleRate * fmt.blockAlign);\n\treturn durationInSeconds;\n};\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/wav/get-duration-from-wav.ts#L1-L23","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-encode the WAV with a conformant tool: ffmpeg -i in.wav -c:a pcm_s16le out.wav.","Verify the WAV with ffprobe -show_format that the fmt chunk is present.","Ensure the entire WAV header (including fmt) is read before calling duration APIs.","If you control the writer, always emit fmt as the first subchunk after the RIFF header."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm the WAV has a fmt chunk before parsing\nimport {execSync} from 'node:child_process';\nfunction hasWavFmt(src: string): boolean {\n  try {\n    const out = execSync(`ffprobe -v error -show_entries stream=codec_name -of csv=p=0 \"${src}\"`).toString().trim();\n    return out.startsWith('pcm_') || out === 'wavpack' || out === 'adpcm';\n  } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { await parseMedia({src, fields: {durationInSeconds: true}}); }\ncatch (e) {\n  if (e instanceof Error && e.message === 'Expected fmt box') {\n    // re-encode WAV with a conformant header\n    await runFfmpeg(['-i', src, '-c:a', 'pcm_s16le', out]);\n    await parseMedia({src: out, fields: {durationInSeconds: true}});\n  } else throw e;\n}","preventionTips":["Re-encode WAV files with ffmpeg to ensure a conformant fmt chunk.","Validate WAV structure with ffprobe before parsing.","If writing WAVs yourself, always emit fmt as the first subchunk."],"tags":["media-parser","wav","riff","container-format","validation"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}