{"record":{"id":"8dd1b5081a391761","repo":"remotion-dev/remotion","slug":"expected-mvhd-box","errorCode":null,"errorMessage":"Expected mvhd-box","messagePattern":"Expected mvhd-box","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/get-duration.ts","lineNumber":93,"sourceCode":"\tconst moofBoxes = getMoofBoxes(structure.boxes);\n\tconst mfra = parserState.iso.mfra.getIfAlreadyLoaded();\n\tconst tfraBoxes = deduplicateTfraBoxesByOffset([\n\t\t...(mfra ? getTfraBoxesFromMfraBoxChildren(mfra) : []),\n\t\t...getTfraBoxes(structure.boxes),\n\t]);\n\n\tif (!areSamplesComplete({moofBoxes, tfraBoxes})) {\n\t\treturn null;\n\t}\n\n\tconst mvhdBox = getMvhdBox(moovBox);\n\n\tif (!mvhdBox) {\n\t\treturn null;\n\t}\n\n\tif (mvhdBox.type !== 'mvhd-box') {\n\t\tthrow new Error('Expected mvhd-box');\n\t}\n\n\tif (mvhdBox.durationInSeconds > 0) {\n\t\treturn mvhdBox.durationInSeconds;\n\t}\n\n\tconst tracks = getTracks(parserState, true);\n\n\tconst allSamples = tracks.map((t) => {\n\t\tconst {originalTimescale: ts} = t;\n\n\t\tconst trakBox = getTrakBoxByTrackId(moovBox, t.trackId);\n\n\t\tif (!trakBox) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst {samplePositions, isComplete} = getSamplePositionsFromTrack({","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/get-duration.ts#L75-L111","documentation":"Thrown by getDuration() as a defensive type check after getMvhdBox(moovBox) returns a non-null value whose type is not 'mvhd-box'. In practice the moov box is expected to contain exactly one well-formed movie header; reaching this throw means the box parser produced a node of the wrong type, indicating corrupt data or an internal invariant violation rather than normal user input.","triggerScenarios":"A malformed MP4 where the moov contains a box that getMvhdBox matched but is not actually typed mvhd-box. Extremely rare; usually points to a parser bug or bit-flipped box header.","commonSituations":"Processing damaged MP4 files. Encountering edge cases in fragmented MP4s where the moov is reconstructed from segments. After partial writes or truncated downloads that nonetheless yielded a box.","solutions":["Re-fetch or re-mux the source file; a conformant MP4 should not reach this branch.","Wrap duration parsing in try/catch and fall back to a sample-based duration calculation or null duration.","Report the file to the library maintainers with the structure dump, since this guard usually signals an internal invariant break."],"exampleFix":"// before\nconst duration = getDuration(parserState);\n\n// after\nlet duration;\ntry {\n  duration = getDuration(parserState);\n} catch (err) {\n  console.warn('Could not read mvhd duration', err);\n  duration = null;\n}","handlingStrategy":"try-catch","validationCode":"const mvhd = getMvhdBox(moovBox);\nif (mvhd && mvhd.type === 'mvhd-box' && mvhd.durationInSeconds > 0) { /* safe */ }","typeGuard":"const isMvhdBox = (b): b is MvhdBox => b?.type === 'mvhd-box';","tryCatchPattern":"try { getDuration(parserState); } catch (e) { if (e.message === 'Expected mvhd-box') { /* corrupt moov, fall back to null duration */ } else throw e; }","preventionTips":["Wrap duration reads in try/catch.","Re-mux or re-fetch corrupt MP4 files.","Report internal-invariant breaks to maintainers."],"tags":["mp4","duration","mvhd","corrupt-file","defensive"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}