remotion-dev/remotion · error
Expected stco box in trak box
Error message
Expected stco box in trak box
What it means
Thrown by getGroupedSamplesPositionsFromMp4 when the TrakBox has no stco (32-bit chunk-offset) box. stco gives the absolute file offset of each chunk; without it sample positions cannot be resolved, so the parser refuses rather than emit invalid offsets. Note this path does not also check for the 64-bit co64 variant.
Source
Thrown at packages/media-parser/src/get-sample-positions-from-mp4.ts:30
// example video: mehmet.mov
export const getGroupedSamplesPositionsFromMp4 = ({
trakBox,
bigEndian,
}: {
trakBox: TrakBox;
bigEndian: boolean;
}): SamplePosition[] => {
const stscBox = getStscBox(trakBox);
const stszBox = getStszBox(trakBox);
const stcoBox = getStcoBox(trakBox);
if (!stscBox) {
throw new Error('Expected stsc box in trak box');
}
if (!stcoBox) {
throw new Error('Expected stco box in trak box');
}
if (!stszBox) {
throw new Error('Expected stsz box in trak box');
}
if (stszBox.countType !== 'fixed') {
throw new Error('Only supporting fixed count type in stsz box');
}
const samples: SamplePosition[] = [];
let timestamp = 0;
const stscKeys = Array.from(stscBox.entries.keys());
for (let i = 0; i < stcoBox.entries.length; i++) {
const entry = stcoBox.entries[i];
const chunk = i + 1;View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Ensure the file provides stco; if the source uses co64, re-mux with ffmpeg to emit stco where possible.
- Use a different code path that handles co64 if the library provides one, or skip this trak.
- Wrap in try/catch and mark the trak as unsampleable when stco is absent.
Example fix
// before
const positions = getGroupedSamplesPositionsFromMp4({trakBox, bigEndian});
// after
let positions = [];
try {
positions = getGroupedSamplesPositionsFromMp4({trakBox, bigEndian});
} catch (err) {
console.warn('trak missing stco (or uses co64), skipping', err);
} Defensive patterns
Strategy: type-guard
Validate before calling
import {getStcoBox} from '@remotion/media-parser/containers/iso-base-media/traversal';
if (getStcoBox(trakBox)) { getGroupedSamplesPositionsFromMp4({trakBox, bigEndian}); } Type guard
const hasStco = (trak: TrakBox): boolean => getStcoBox(trak) !== null;
Try / catch
try { getGroupedSamplesPositionsFromMp4({trakBox, bigEndian}); } catch (e) { if (e.message === 'Expected stco box in trak box') { /* trak uses co64 or is corrupt */ } else throw e; } Prevention
- Detect co64 vs stco before choosing the sample-position path.
- Skip traks that use co64 if only stco is supported here.
- Re-mux with ffmpeg to emit stco where possible.
When it happens
Trigger: Trak whose stbl uses co64 (64-bit offsets) instead of stco, or omits the chunk-offset box entirely. Files with non-standard sample table layouts.
Common situations: Large MP4 files (>4 GB) that use co64 rather than stco. Truncated or repaired files. Tracks muxed by tools that emit co64 exclusively.
Related errors
- Expected stsc box in trak box
- Expected stsz box in trak box
- Expected stsz box in trak box
- Expected stco box in trak box
- Expected stsc box in trak box
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/08da37cc7183f5df.
Report an issue: GitHub.