{"record":{"id":"fb43e21c0a705f27","repo":"remotion-dev/remotion","slug":"only-supporting-fixed-count-type-in-stsz-box","errorCode":null,"errorMessage":"Only supporting fixed count type in stsz box","messagePattern":"Only supporting fixed count type in stsz box","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/get-sample-positions-from-mp4.ts","lineNumber":38,"sourceCode":"}): 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;\n\t\tconst stscEntry = stscKeys.findLast((e) => e <= chunk);\n\t\tif (stscEntry === undefined) {\n\t\t\tthrow new Error('should not be');\n\t\t}\n\n\t\tconst samplesPerChunk = stscBox.entries.get(stscEntry);\n\t\tif (samplesPerChunk === undefined) {\n\t\t\tthrow new Error('should not be');","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/get-sample-positions-from-mp4.ts#L20-L56","documentation":"Thrown by getGroupedSamplesPositionsFromMp4 when the stsz box's countType is not 'fixed'. A 'fixed' stsz declares one sample size applied to every sample, which lets the parser multiply by samples-per-chunk. A 'variable' stsz (per-sample sizes) is not handled by this grouped-samples fast path, so it refuses rather than compute incorrect offsets.","triggerScenarios":"Calling getGroupedSamplesPositionsFromMp4 on a trak whose stsz lists per-sample sizes (countType === 'variable'), which is normal for most compressed video/audio tracks. This path is intended only for fixed-size sample tracks (e.g. some LPCM layouts).","commonSituations":"Routing a generic/compressed audio or video trak into the grouped-samples path by mistake. Using this function for LPCM-like handling on a track that is actually variable-sized.","solutions":["Use the general sample-positions path (not the grouped variant) for tracks with variable sample sizes.","Only call getGroupedSamplesPositionsFromMp4 for tracks known to have fixed sample sizes (check stszBox.countType === 'fixed' first).","Confirm the track type; for compressed codecs prefer getSamplePositionsFromTrack."],"exampleFix":"// before\nconst positions = getGroupedSamplesPositionsFromMp4({trakBox, bigEndian});\n\n// after\nconst stszBox = getStszBox(trakBox);\nif (stszBox?.countType === 'fixed') {\n  const positions = getGroupedSamplesPositionsFromMp4({trakBox, bigEndian});\n} else {\n  // use the general variable-size sample path\n  const positions = getSamplePositionsFromTrack({trakBox, ...});\n}","handlingStrategy":"type-guard","validationCode":"import {getStszBox} from '@remotion/media-parser/containers/iso-base-media/traversal';\nconst stsz = getStszBox(trakBox);\nif (stsz?.countType === 'fixed') { getGroupedSamplesPositionsFromMp4({trakBox, bigEndian}); } else { /* use variable-size path */ }","typeGuard":"const hasFixedStsz = (trak: TrakBox): boolean => getStszBox(trak)?.countType === 'fixed';","tryCatchPattern":"try { getGroupedSamplesPositionsFromMp4({trakBox, bigEndian}); } catch (e) { if (e.message === 'Only supporting fixed count type in stsz box') { /* fall back to general path */ } else throw e; }","preventionTips":["Reserve getGroupedSamplesPositionsFromMp4 for fixed-size-sample tracks.","Check stsz.countType before choosing the grouped path.","Use getSamplePositionsFromTrack for compressed/variable-size tracks."],"tags":["mp4","samples","stsz","lpcm","api-misuse"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}