{"record":{"id":"4e0a3a614e8e94bc","repo":"nilaoda/N_m3u8DL-RE","slug":"tfdt-version-can-only-be-0-or-1","errorCode":null,"errorMessage":"TFDT version can only be 0 or 1","messagePattern":"TFDT version can only be 0 or 1","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE.Parser/Mp4/MP4VttUtil.cs","lineNumber":64,"sourceCode":"\n            bool sawTFDT = false;\n            bool sawTRUN = false;\n            bool sawMDAT = false;\n            byte[]? rawPayload = null;\n            ulong baseTime = 0;\n            ulong defaultDuration = 0;\n            List<Sample> presentations = [];\n\n\n            // parse media\n            new MP4Parser()\n                .Box(\"moof\", MP4Parser.Children)\n                .Box(\"traf\", MP4Parser.Children)\n                .FullBox(\"tfdt\", box =>\n                {\n                    sawTFDT = true;\n                    if (box.Version is not (0 or 1))\n                        throw new Exception(\"TFDT version can only be 0 or 1\");\n                    baseTime = MP4Parser.ParseTFDT(box.Reader, box.Version);\n                })\n                .FullBox(\"tfhd\", box =>\n                {\n                    if (box.Flags == 1000)\n                        throw new Exception(\"A TFHD box should have a valid flags value\");\n                    defaultDuration = MP4Parser.ParseTFHD(box.Reader, box.Flags).DefaultSampleDuration;\n                })\n                .FullBox(\"trun\", box =>\n                {\n                    sawTRUN = true;\n                    if (box.Version == 1000)\n                        throw new Exception(\"A TRUN box should have a valid version value\");\n                    if (box.Flags == 1000)\n                        throw new Exception(\"A TRUN box should have a valid flags value\");\n                    presentations = MP4Parser.ParseTRUN(box.Reader, box.Version, box.Flags).SampleData;\n                })\n                .Box(\"mdat\", MP4Parser.AllData(data =>","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE.Parser/Mp4/MP4VttUtil.cs#L46-L82","documentation":"While parsing a media segment for VTT cues, ExtractSub's 'tfdt' FullBox handler requires the Track Fragment Base Media Decode Time box version to be 0 or 1 (the only ISO BMFF-defined versions). Another version byte means the fragment is corrupt or was misparsed, so the decode-time base cannot be read.","triggerScenarios":"Calling ExtractSub on a media segment whose moof/traf/tfdt full box has a version other than 0 or 1.","commonSituations":"Corrupt or truncated media fragment, a nonstandard muxer, or segment data that is not actually fMP4 (misaligned box parsing yields a bogus version byte).","solutions":["Re-download the media segment; it is likely corrupt or truncated.","Confirm the segment is a valid fMP4 fragment (check with MP4Box/Bento4 dump).","Ensure the init segment passed to CheckInit matches these media segments (same stream).","Catch the exception and skip the affected fragment's cues rather than failing the entire subtitle extraction."],"exampleFix":"// before\nvar sub = MP4VttUtil.ExtractSub(segmentFiles, timescale); // throws on bad tfdt\n\n// after\ntry\n{\n    var sub = MP4VttUtil.ExtractSub(segmentFiles, timescale);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"TFDT version\"))\n{\n    Log.Warning(\"Media fragment has invalid tfdt box; skipping subtitle segment\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var sub = MP4VttUtil.ExtractSub(files, ts); }\ncatch (Exception ex) when (ex.Message.Contains(\"TFDT version\"))\n{ Log.Warning(\"Corrupt fragment (bad tfdt); skipping\"); }","preventionTips":["Re-download segments that fail instead of retrying parse on corrupt data.","Confirm media segments are fMP4 (start with 'styp'/'moof') before MP4 parsing.","Process fragments independently so one bad fragment doesn't kill all cues."],"tags":["mp4","fmp4","parsing","subtitle"],"backgroundTag":"invalid-enum-value","analyzedSha":"e113dee70c924ee08dae5460624909b04d84cb76","analyzedAt":"2026-09-13T02:43:21.078Z","contentChangedAt":"2026-09-13T02:43:21.078Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}