{"record":{"id":"4da0401fc24bae0f","repo":"nilaoda/N_m3u8DL-RE","slug":"vtt-cues-in-mp4-with-multiple-mdat-are-not-currently","errorCode":null,"errorMessage":"VTT cues in mp4 with multiple MDAT are not currently supported","messagePattern":"VTT cues in mp4 with multiple MDAT are not currently supported","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE.Parser/Mp4/MP4VttUtil.cs","lineNumber":85,"sourceCode":"                .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 =>\n                {\n                    if (sawMDAT)\n                        throw new Exception(\"VTT cues in mp4 with multiple MDAT are not currently supported\");\n                    sawMDAT = true;\n                    rawPayload = data;\n                }))\n                .Parse(dataSeg,/* partialOkay= */ false);\n\n            if (!sawMDAT && !sawTFDT && !sawTRUN)\n            {\n                throw new Exception(\"A required box is missing\");\n            }\n\n            var currentTime = baseTime;\n            var reader = new BinaryReader2(new MemoryStream(rawPayload!));\n\n            foreach (var presentation in presentations)\n            {\n                var duration = presentation.SampleDuration == 0 ? defaultDuration : presentation.SampleDuration;\n                var startTime = presentation.SampleCompositionTimeOffset != 0 ?\n                    baseTime + presentation.SampleCompositionTimeOffset :","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE.Parser/Mp4/MP4VttUtil.cs#L67-L103","documentation":"ExtractSub expects exactly one 'mdat' box holding the raw WebVTT sample payload; a second 'mdat' would make it impossible to know which payload the TRUN presentations index into. When a second MDAT is seen (sawMDAT already true), the library throws because multi-MDAT WVTT segments are not implemented.","triggerScenarios":"ExtractSub is called on a segment containing two or more 'mdat' boxes (e.g. a muxer emitted multiple payload boxes per fragment).","commonSituations":"Non-standard segment muxers/producers that emit multiple mdat boxes in one media segment; re-muxed or edited segments; unusual HLS packagers.","solutions":["Re-package the segment with a packager that emits a single mdat per fragment (e.g. standard ffmpeg/Shaka packager output).","Pre-process the segment to merge adjacent mdat boxes before calling ExtractSub.","Patch MP4VttUtil to concatenate multiple mdat payloads and adjust presentation offsets.","Use a different subtitle extraction path (demux the segment with ffmpeg and extract WebVTT directly)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// detect multiple mdat boxes before extraction\nint CountMdat(byte[] seg) { int n = 0; int i = 0;\n  while (i + 8 <= seg.Length) { var size = BitConverter.ToUInt32(seg.Reverse().Skip(0).ToArray(), 0); n++; i += (int)size; }\n  return n; }","typeGuard":null,"tryCatchPattern":"try { var subs = MP4VttUtil.ExtractSub(dataSeg, baseTime); }\ncatch (Exception ex) when (ex.Message.Contains(\"multiple MDAT\")) {\n    // fall back to an external demuxer\n    subs = await FallbackExtractWithFfmpegAsync(segmentFile);\n}","preventionTips":["Use standard packagers (ffmpeg, Shaka, Bento4) that emit one mdat per fragment.","Avoid hand-editing or re-muxing fragments in place.","Detect multi-mdat segments once in tests for each new source.","Maintain a fallback demux path for exotic packagers."],"tags":["mp4","subtitles","unsupported"],"backgroundTag":"unsupported-operation","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"}