{"record":{"id":"0716c55b19e16b11","repo":"remotion-dev/remotion","slug":"expected-stsc-box-in-trak-box-0716c5","errorCode":null,"errorMessage":"Expected stsc box in trak box","messagePattern":"Expected stsc box in trak box","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/get-sample-positions-from-mp4.ts","lineNumber":26,"sourceCode":"\tgetStszBox,\n} from './containers/iso-base-media/traversal';\nimport type {SamplePosition} from './get-sample-positions';\n\n// 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","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/get-sample-positions-from-mp4.ts#L8-L44","documentation":"Thrown by getGroupedSamplesPositionsFromMp4 when the supplied TrakBox has no stsc (sample-to-chunk) box. stsc maps samples to chunks and is mandatory for any sample-addressable MP4 track; its absence means the trak is structurally incomplete and sample positions cannot be computed.","triggerScenarios":"Calling getGroupedSamplesPositionsFromMp4 on a TrakBox whose stbl lacks stsc. Truncated MP4s, partially written files, or traks produced by a buggy muxer that omits stsc.","commonSituations":"Processing partially downloaded or repaired MP4 files. Handling fragmented MP4 where the sample tables live in moof and the initial moov stsc is sparse. Reading hint or metadata traks that lack sample tables.","solutions":["Re-mux the file with ffmpeg (ffmpeg -i in.mp4 -c copy out.mp4) to regenerate sample tables.","Filter to traks that actually carry media samples (skip hint/tmcd traks) before computing positions.","Wrap the call in try/catch and treat the trak as unsampleable when stsc is missing."],"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 stsc, skipping', err);\n}","handlingStrategy":"type-guard","validationCode":"import {getStscBox} from '@remotion/media-parser/containers/iso-base-media/traversal';\nif (getStscBox(trakBox)) { getGroupedSamplesPositionsFromMp4({trakBox, bigEndian}); }","typeGuard":"const hasStsc = (trak: TrakBox): boolean => getStscBox(trak) !== null;","tryCatchPattern":"try { getGroupedSamplesPositionsFromMp4({trakBox, bigEndian}); } catch (e) { if (e.message === 'Expected stsc box in trak box') { /* skip trak */ } else throw e; }","preventionTips":["Check for stsc/stco/stsz before computing sample positions.","Skip non-media traks (hint, tmcd).","Re-mux corrupt MP4s with ffmpeg."],"tags":["mp4","samples","stsc","corrupt-file"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}