{"record":{"id":"2cbbcb7180a2ce50","repo":"remotion-dev/remotion","slug":"no-trak-box-found","errorCode":null,"errorMessage":"No trak box found","messagePattern":"No trak box found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/iso-base-media/get-seeking-byte-from-fragmented-mp4.ts","lineNumber":68,"sourceCode":"\n\tif (!firstTrack) {\n\t\tthrow new Error('no video and no audio tracks');\n\t}\n\n\tconst moov = getMoovBoxFromState({\n\t\tstructureState: structure,\n\t\tisoState,\n\t\tmp4HeaderSegment,\n\t\tmayUsePrecomputed: true,\n\t});\n\tif (!moov) {\n\t\tthrow new Error('No moov atom found');\n\t}\n\n\tconst trakBox = getTrakBoxByTrackId(moov, firstTrack.trackId);\n\n\tif (!trakBox) {\n\t\tthrow new Error('No trak box found');\n\t}\n\n\tconst tkhdBox = getTkhdBox(trakBox);\n\tif (!tkhdBox) {\n\t\tthrow new Error('Expected tkhd box in trak box');\n\t}\n\n\tconst isComplete = areSamplesComplete({\n\t\tmoofBoxes: info.moofBoxes,\n\t\ttfraBoxes: info.tfraBoxes,\n\t});\n\n\tconst {samplePositions: samplePositionsArray} =\n\t\tcollectSamplePositionsFromMoofBoxes({\n\t\t\tmoofBoxes: info.moofBoxes,\n\t\t\ttkhdBox,\n\t\t\tisComplete,\n\t\t\ttrexBoxes: getTrexBoxes(moov),","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/iso-base-media/get-seeking-byte-from-fragmented-mp4.ts#L50-L86","documentation":"Thrown by getSeekingByteFromFragmentedMp4 when getTrakBoxByTrackId(moov, firstTrack.trackId) returns null. The moov atom parsed fine and a track was registered with a given trackId, but no trak inside moov has a matching tkhd.trackId. This indicates a mismatch between the track objects the parser exposes and the actual trak boxes in the moov — typically a state inconsistency or a moov that was replaced between parse and seek.","triggerScenarios":"A track object in state.tracks carries a trackId that does not correspond to any trak in the current moov (e.g. moov was re-fetched or swapped, e.g. across HLS variant switches). Also reachable if trackId is 0 or unset because tkhd was malformed during track construction.","commonSituations":"Adaptive streaming where the active variant's moov changed but the track list still references the old trackId. Damaged moov where tkhd.trackId was misread. Custom readerInterface returning different bytes for the same range across calls. Race during variant switch.","solutions":["Reset/rebuild the tracks array whenever the moov is reloaded (e.g. on HLS variant switch).","Validate that every track.trackId corresponds to a trak in the current moov before seeking.","If the source is adaptive, pin to a single variant during a seek operation.","Ensure tkhd.trackId is parsed correctly; if 0 or NaN, treat the file as corrupt."],"exampleFix":"// before\nawait parser.seek(time);\n\n// after\nconst trakIds = new Set(getTraks(moov).map((t) => getTkhdBox(t)?.trackId));\nif (!tracks.every((t) => trakIds.has(t.trackId))) {\n  // moov changed under us; rebuild tracks before seeking\n  await reloadTracks();\n}\nawait parser.seek(time);","handlingStrategy":"validation","validationCode":"import type {MoovBox} from './moov/moov';\nimport {getTraks, getTkhdBox} from './traversal';\nfunction moovHasTrackId(moov: MoovBox, trackId: number): boolean {\n  return getTraks(moov).some((t) => getTkhdBox(t)?.trackId === trackId);\n}","typeGuard":"import type {MoovBox} from './moov/moov';\nimport {getTraks, getTkhdBox} from './traversal';\nfunction moovHasTrakForTrack(moov: MoovBox, trackId: number): boolean {\n  return getTraks(moov).some((t) => getTkhdBox(t)?.trackId === trackId);\n}","tryCatchPattern":"try {\n  await parser.seek(time);\n} catch (err) {\n  if (/No trak box found/i.test(String(err?.message))) {\n    // moov changed under us; rebuild tracks then retry\n    await reloadTracksFromCurrentMoov();\n    return parser.seek(time);\n  }\n  throw err;\n}","preventionTips":["Rebuild the tracks array whenever the moov is reloaded (e.g. HLS variant switch).","Pin a single variant during an active seek operation.","Validate trackId against the current moov before seeking.","Discard stale track references after moov replacement."],"tags":["mp4","isobmff","media-parser","fmp4","seeking","trak","track-id"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}