{"record":{"id":"08da37cc7183f5df","repo":"remotion-dev/remotion","slug":"expected-stco-box-in-trak-box-08da37","errorCode":null,"errorMessage":"Expected stco box in trak box","messagePattern":"Expected stco box in trak box","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/get-sample-positions-from-mp4.ts","lineNumber":30,"sourceCode":"// example video: mehmet.mov\n\nexport const getGroupedSamplesPositionsFromMp4 = ({\n\ttrakBox,\n\tbigEndian,\n}: {\n\ttrakBox: TrakBox;\n\tbigEndian: boolean;\n}): SamplePosition[] => {\n\tconst stscBox = getStscBox(trakBox);\n\tconst stszBox = getStszBox(trakBox);\n\tconst stcoBox = getStcoBox(trakBox);\n\n\tif (!stscBox) {\n\t\tthrow new Error('Expected stsc box in trak box');\n\t}\n\n\tif (!stcoBox) {\n\t\tthrow new Error('Expected stco box in trak box');\n\t}\n\n\tif (!stszBox) {\n\t\tthrow new Error('Expected stsz box in trak box');\n\t}\n\n\tif (stszBox.countType !== 'fixed') {\n\t\tthrow new Error('Only supporting fixed count type in stsz box');\n\t}\n\n\tconst samples: SamplePosition[] = [];\n\n\tlet timestamp = 0;\n\n\tconst stscKeys = Array.from(stscBox.entries.keys());\n\tfor (let i = 0; i < stcoBox.entries.length; i++) {\n\t\tconst entry = stcoBox.entries[i];\n\t\tconst chunk = i + 1;","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/get-sample-positions-from-mp4.ts#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"Large MP4 files (>4 GB) that use co64 rather than stco. Truncated or repaired files. Tracks muxed by tools that emit co64 exclusively.","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."],"exampleFix":"// before\nconst positions = getGroupedSamplesPositionsFromMp4({trakBox, bigEndian});\n\n// after\nlet positions = [];\ntry {\n  positions = getGroupedSamplesPositionsFromMp4({trakBox, bigEndian});\n} catch (err) {\n  console.warn('trak missing stco (or uses co64), skipping', err);\n}","handlingStrategy":"type-guard","validationCode":"import {getStcoBox} from '@remotion/media-parser/containers/iso-base-media/traversal';\nif (getStcoBox(trakBox)) { getGroupedSamplesPositionsFromMp4({trakBox, bigEndian}); }","typeGuard":"const hasStco = (trak: TrakBox): boolean => getStcoBox(trak) !== null;","tryCatchPattern":"try { getGroupedSamplesPositionsFromMp4({trakBox, bigEndian}); } catch (e) { if (e.message === 'Expected stco box in trak box') { /* trak uses co64 or is corrupt */ } else throw e; }","preventionTips":["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."],"tags":["mp4","samples","stco","corrupt-file"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}