{"record":{"id":"5c4def0ed4ea6348","repo":"remotion-dev/remotion","slug":"expected-segment","errorCode":null,"errorMessage":"Expected segment","messagePattern":"Expected segment","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/webm/parse-webm-header.ts","lineNumber":50,"sourceCode":"\n\tif (results === null) {\n\t\treturn null;\n\t}\n\n\tif (isInsideCluster) {\n\t\tif (maySkipVideoData({state})) {\n\t\t\treturn makeSkip(\n\t\t\t\tMath.min(\n\t\t\t\t\tstate.contentLength,\n\t\t\t\t\tisInsideCluster.size + isInsideCluster.start,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tconst segments = structure.boxes.filter((box) => box.type === 'Segment');\n\t\tconst segment = segments[isInsideCluster.segment];\n\t\tif (!segment) {\n\t\t\tthrow new Error('Expected segment');\n\t\t}\n\n\t\tconst clusters = segment.value.find((box) => box.type === 'Cluster');\n\t\tif (!clusters) {\n\t\t\tthrow new Error('Expected cluster');\n\t\t}\n\n\t\t// let's not add it to the cluster\n\t\tif (results.type !== 'Block' && results.type !== 'SimpleBlock') {\n\t\t\tclusters.value.push(results);\n\t\t}\n\t} else if (isInsideSegment) {\n\t\tconst segments = structure.boxes.filter((box) => box.type === 'Segment');\n\t\tconst segment = segments[isInsideSegment.index];\n\t\tif (!segment) {\n\t\t\tthrow new Error('Expected segment');\n\t\t}\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/webm/parse-webm-header.ts#L32-L68","documentation":"While inside a Cluster (state.webm.isInsideCluster returned a value), the parser indexes into the parsed Segment boxes by isInsideCluster.segment and that Segment does not exist. This is an internal state-tracking inconsistency between the cluster bookkeeping and the structure list rather than a property of the bytes.","triggerScenarios":"A Cluster was registered with a segment index that is out of range for the structure.boxes Segment list - typically a side effect of a malformed Segment header, a seek that desynced state, or an earlier parse error that left structure.boxes incomplete.","commonSituations":"Damaged files where the Segment appears after a Cluster, partial reads during a seek, or files with an unusual multi-Segment layout.","solutions":["Re-mux the file to produce a single, well-formed Segment.","Avoid seeking on this file (the error is reachable via the seek path); parse linearly instead.","Re-encode from the original source.","Try Mediabunny."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({src: 'in.mkv', fields: {durationInSeconds: true}});\n} catch (err) {\n  if (err instanceof Error && err.message === 'Expected segment') {\n    throw new Error('Segment/Cluster state desync; re-mux the file or parse without seeking.', {cause: err});\n  }\n  throw err;\n}","preventionTips":["Re-mux to a single, well-formed Segment before parsing.","Avoid parseMedia seek-driven fields (durationInSeconds, keyframes) on suspect files.","Keep Mediabunny as a fallback parser."],"tags":["webm","matroska","media-parser","segment","state","malformed-file"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}