{"record":{"id":"39f3d81556e13c3a","repo":"remotion-dev/remotion","slug":"expected-to-be-inside-segment","errorCode":null,"errorMessage":"Expected to be inside segment","messagePattern":"Expected to be inside segment","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/webm/segments.ts","lineNumber":85,"sourceCode":"\t\tif (!statesForProcessing) {\n\t\t\tthrow new Error('States for processing are required');\n\t\t}\n\n\t\tstatesForProcessing.webmState.addSegment({\n\t\t\tstart: offset,\n\t\t\tsize,\n\t\t});\n\t\tconst newSegment: MainSegment = {\n\t\t\ttype: 'Segment',\n\t\t\tminVintWidth: offsetAfterVInt - offsetBeforeVInt,\n\t\t\tvalue: [],\n\t\t};\n\t\treturn newSegment;\n\t}\n\n\tif (segmentId === matroskaElements.Cluster) {\n\t\tif (isInsideSegment === null) {\n\t\t\tthrow new Error('Expected to be inside segment');\n\t\t}\n\n\t\tif (!statesForProcessing) {\n\t\t\tthrow new Error('States for processing are required');\n\t\t}\n\n\t\tif (mediaSectionState) {\n\t\t\tmediaSectionState.addMediaSection({\n\t\t\t\tstart: offset,\n\t\t\t\tsize,\n\t\t\t});\n\t\t}\n\n\t\tstatesForProcessing.webmState.addCluster({\n\t\t\tstart: offset,\n\t\t\tsize: size + (offsetAfterVInt - offset),\n\t\t\tsegment: isInsideSegment.index,\n\t\t});","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/webm/segments.ts#L67-L103","documentation":"A Cluster element was encountered but isInsideSegment is null, meaning the Cluster appears outside any Segment. Matroska requires Clusters to live inside a Segment, so this is a structural error in the file or a state-tracking desync.","triggerScenarios":"parseMedia reads a Cluster element ID before any Segment element ID has been seen - e.g. a file whose EBML header is followed directly by a Cluster, a reordered/edited file, or state that lost the Segment entry.","commonSituations":"Hand-edited or damaged MKV/WebM, files produced by muxers that emit Clusters prematurely, or a seek that reset Segment state.","solutions":["Re-mux with ffmpeg so the EBML header is followed by a Segment before any Cluster.","Re-encode from the original source.","Try Mediabunny."],"exampleFix":"// shell: ffmpeg -i broken.webm -c copy fixed.webm\nawait parseMedia({src: 'fixed.webm'});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({src: 'in.webm'});\n} catch (err) {\n  if (err instanceof Error && err.message === 'Expected to be inside segment') {\n    throw new Error('Cluster outside Segment; re-mux to normalize structure.', {cause: err});\n  }\n  throw err;\n}","preventionTips":["Re-mux uploads with ffmpeg to guarantee EBML header -> Segment -> Cluster ordering.","Reject binary-edited MKV/WebM inputs.","Keep a fallback source/parser."],"tags":["webm","matroska","media-parser","cluster","segment","malformed-file"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}