remotion-dev/remotion · error · Error
Expected segment
Error message
Expected segment
What it means
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.
Source
Thrown at packages/media-parser/src/containers/webm/parse-webm-header.ts:50
if (results === null) {
return null;
}
if (isInsideCluster) {
if (maySkipVideoData({state})) {
return makeSkip(
Math.min(
state.contentLength,
isInsideCluster.size + isInsideCluster.start,
),
);
}
const segments = structure.boxes.filter((box) => box.type === 'Segment');
const segment = segments[isInsideCluster.segment];
if (!segment) {
throw new Error('Expected segment');
}
const clusters = segment.value.find((box) => box.type === 'Cluster');
if (!clusters) {
throw new Error('Expected cluster');
}
// let's not add it to the cluster
if (results.type !== 'Block' && results.type !== 'SimpleBlock') {
clusters.value.push(results);
}
} else if (isInsideSegment) {
const segments = structure.boxes.filter((box) => box.type === 'Segment');
const segment = segments[isInsideSegment.index];
if (!segment) {
throw new Error('Expected segment');
}
View on GitHub (pinned to 78fe4bb3fd)
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.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await parseMedia({src: 'in.mkv', fields: {durationInSeconds: true}});
} catch (err) {
if (err instanceof Error && err.message === 'Expected segment') {
throw new Error('Segment/Cluster state desync; re-mux the file or parse without seeking.', {cause: err});
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Damaged files where the Segment appears after a Cluster, partial reads during a seek, or files with an unusual multi-Segment layout.
Related errors
- Expected cluster
- Expected to be inside segment
- Could not find sample rate or number of channels
- Expected block segment
- Expected CuePoint
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/5c4def0ed4ea6348.
Report an issue: GitHub.