From 5b88660518c376a1810c7d69eee3cc40ea781799 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Sat, 29 Oct 2022 17:36:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96`cenc`=E7=9A=84`KID`=E8=AF=BB?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE.Parser/Mp4/MP4InitUtil.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/N_m3u8DL-RE.Parser/Mp4/MP4InitUtil.cs b/src/N_m3u8DL-RE.Parser/Mp4/MP4InitUtil.cs index e8dd1d3..148f850 100644 --- a/src/N_m3u8DL-RE.Parser/Mp4/MP4InitUtil.cs +++ b/src/N_m3u8DL-RE.Parser/Mp4/MP4InitUtil.cs @@ -50,7 +50,6 @@ namespace Mp4SubtitleParser private static void ReadBox(byte[] data, ParsedMP4Info info) { - info.KID = HexUtil.BytesToHex(data[^16..]).ToLower(); //find schm var schmBytes = new byte[4] { 0x73, 0x63, 0x68, 0x6d }; var schmIndex = 0; @@ -66,6 +65,24 @@ namespace Mp4SubtitleParser { info.Scheme = System.Text.Encoding.UTF8.GetString(data[schmIndex..][8..12]); } + + if (info.Scheme != "cenc") return; + + //find KID + var tencBytes = new byte[4] { 0x74, 0x65, 0x6E, 0x63 }; + var tencIndex = 0; + for (int i = 0; i < data.Length - 4; i++) + { + if (new byte[4] { data[i], data[i + 1], data[i + 2], data[i + 3] }.SequenceEqual(tencBytes)) + { + tencIndex = i; + break; + } + } + if (tencIndex + 12 < data.Length) + { + info.KID = HexUtil.BytesToHex(data[tencIndex..][12..28]).ToLower(); + } } } }