优化`init`生成

This commit is contained in:
nilaoda 2022-11-28 02:10:12 +08:00
parent 60f639a115
commit 4db9ad35a7
1 changed files with 18 additions and 8 deletions

View File

@ -221,9 +221,11 @@ namespace N_m3u8DL_RE.Parser.Mp4
var tencPayload = new List<byte>(); var tencPayload = new List<byte>();
tencPayload.AddRange(new byte[] { 0, 0 }); tencPayload.AddRange(new byte[] { 0, 0 });
tencPayload.Add(0x1); //default_IsEncrypted tencPayload.Add(0x1); //default_IsProtected
tencPayload.Add(0x8); //default_IV_size tencPayload.Add(0x8); //default_Per_Sample_IV_size
tencPayload.AddRange(HexUtil.HexToBytes(ProtecitonKID)); //default_KID tencPayload.AddRange(HexUtil.HexToBytes(ProtecitonKID)); //default_KID
//tencPayload.Add(0x8);//default_constant_IV_size
//tencPayload.AddRange(new byte[8]);//default_constant_IV
var tencBox = FullBox("tenc", 0, 0, tencPayload.ToArray()); var tencBox = FullBox("tenc", 0, 0, tencPayload.ToArray());
var schiBox = Box("schi", tencBox); var schiBox = Box("schi", tencBox);
@ -497,15 +499,15 @@ namespace N_m3u8DL_RE.Parser.Mp4
writer.WriteByte(0); writer.WriteByte(0);
} }
writer.WriteUShort(0x18); //depth writer.WriteUShort(0x18); //depth
writer.WriteShort(-1); //pre defined writer.WriteUShort(65535); //pre defined
var codecPrivateData = HexUtil.HexToBytes(CodecPrivateData); var codecPrivateData = HexUtil.HexToBytes(CodecPrivateData);
if (FourCC == "H264" || FourCC == "AVC1" || FourCC == "DAVC" || FourCC == "AVC1") if (FourCC == "H264" || FourCC == "AVC1" || FourCC == "DAVC" || FourCC == "AVC1")
{ {
var arr = CodecPrivateData.Split(new[] { StartCode }, StringSplitOptions.RemoveEmptyEntries); var arr = CodecPrivateData.Split(new[] { StartCode }, StringSplitOptions.RemoveEmptyEntries);
var sps = HexUtil.HexToBytes(arr[0]); var sps = HexUtil.HexToBytes(arr.Where(x => (HexUtil.HexToBytes(x[0..2])[0] & 0x1F) == 7).First());
var pps = HexUtil.HexToBytes(arr[1]); var pps = HexUtil.HexToBytes(arr.Where(x => (HexUtil.HexToBytes(x[0..2])[0] & 0x1F) == 8).First());
//make avcC //make avcC
var avcC = GetAvcC(sps, pps); var avcC = GetAvcC(sps, pps);
writer.Write(avcC); writer.Write(avcC);
@ -523,9 +525,9 @@ namespace N_m3u8DL_RE.Parser.Mp4
else if (FourCC == "HVC1" || FourCC == "HEV1") else if (FourCC == "HVC1" || FourCC == "HEV1")
{ {
var arr = CodecPrivateData.Split(new[] { StartCode }, StringSplitOptions.RemoveEmptyEntries); var arr = CodecPrivateData.Split(new[] { StartCode }, StringSplitOptions.RemoveEmptyEntries);
var vps = HexUtil.HexToBytes(arr[0]); var vps = HexUtil.HexToBytes(arr.Where(x => (HexUtil.HexToBytes(x[0..2])[0] & 0x3F) == 0x20).First());
var sps = HexUtil.HexToBytes(arr[1]); var sps = HexUtil.HexToBytes(arr.Where(x => (HexUtil.HexToBytes(x[0..2])[0] & 0x3F) == 0x21).First());
var pps = HexUtil.HexToBytes(arr[2]); var pps = HexUtil.HexToBytes(arr.Where(x => (HexUtil.HexToBytes(x[0..2])[0] & 0x3F) == 0x22).First());
//make hvcC //make hvcC
var hvcC = GetHvcC(sps, pps, vps); var hvcC = GetHvcC(sps, pps, vps);
writer.Write(hvcC); writer.Write(hvcC);
@ -799,8 +801,16 @@ namespace N_m3u8DL_RE.Parser.Mp4
var mvexBox = Box("mvex", mvexPayload); //Movie Extends Box var mvexBox = Box("mvex", mvexPayload); //Movie Extends Box
moovPayload = moovPayload.Concat(mvexBox).ToArray(); moovPayload = moovPayload.Concat(mvexBox).ToArray();
/*if (IsProtection) //gen pssh
{
var pssh = HexUtil.HexToBytes(ProtectionData);
var psshBox = FullBox("pssh", 1, 0, pssh);
moovPayload = moovPayload.Concat(psshBox).ToArray();
}*/
var moovBox = Box("moov", moovPayload); //Movie Box var moovBox = Box("moov", moovPayload); //Movie Box
stream.Write(moovBox); stream.Write(moovBox);
return stream.ToArray(); return stream.ToArray();