简体   繁体   English

通过 RTP 发布解码 H264

[英]Issue decoding H264 over RTP

I'm trying to read H264 frames from an MPEG2-TS stream (via HLS) and getting stuck, after studying the RTP rfc and ISO 13818-1 (MPEG2-TS).在研究了RTP rfc和 ISO 13818-1 (MPEG2-TS) 之后,我正在尝试从 MPEG2-TS ZF7B44CFFAFD5C52223D5498196C8A2E7BZ(通过 HLS)读取 H264 帧并卡住了。 I've parsed the PES packets from the MPEG-TS stream, and am trying to read the RTP/H264 payload however it doesn't seem to decode correctly (and I am probably missing something).我已经解析了来自 MPEG-TS stream 的 PES 数据包,并试图读取 RTP/H264 有效负载,但它似乎没有正确解码(我可能遗漏了一些东西)。 The first start marker of 00 00 00 01 is as expected, but the following byte (0xE0) seems invalid. 00 00 00 01的第一个开始标记符合预期,但后面的字节 (0xE0) 似乎无效。 There are also multiple start markers followed by very little data in the 188 byte packet:在 188 字节数据包中还有多个起始标记,后面跟着非常少的数据:

single 188 byte packet:单个 188 字节数据包:

47 41 00 30 07 50 00 00 00 00 FE 00 00 00 01 E0 00 00 80 80 05 21 00 01 00 03 00 00 00 01 09 F0 00 00 00 01 67 64 00 2A AC 2C 6A 81 E0 08 9F 97 01 6E 02 02 02 80 00 00 03 00 80 00 00 1E 42 00 00 00 01 68 EE 3C B0 00 00 00 01 06 E5 01 6C 80 00 00 00 01 65 B8 00 00 1C D9 C0 00 05 FF 6D 0B 52 D2 A2 D1 EF 11 EC FF C5 4A EC 63 C1 47 9F A7 78 36 7B 1F 30 0A 24 C8 0C 35 2D 96 BD BC 97 B5 E0 AA 40 A3 9F 3E 4A 42 C2 9B D0 43 63 6F 82 CD 94 2C 3C 7F A2 C1 A4 29 DE 73 80 5E BF 1C 1B E9 73 0B F5 FE FD BC 92 ED 11 67 8C 94 63 AB CE 40 4C 5C D2 68 DC 2D 91 CE 19 2E BB 98 47 41 00 30 07 50 00 00 00 00 FE 00 00 00 01 E0 00 00 80 80 05 21 00 01 00 03 00 00 00 01 09 F0 00 00 00 01 67 64 00 E 1 0 6 AC 2C 9F 7 8 E 02 02 02 80 00 00 03 00 80 00 00 1E 42 00 00 00 01 68 EE 3C B0 00 00 00 01 06 E5 01 6C 80 00 00 00 01 65 B8 00 00 1C D9 C0 00 02 D A 2D 1D 6 EF 11 EC FF C5 4A EC 63 C1 47 9F A7 78 36 7B 1F 30 0A 24 C8 0C 35 2D 96 BD BC 97 B5 E0 AA 40 A3 9F 3E 4A 42 C2 9B D0 43 63 6F 82 CD 94 C1 2C 3C 7F A2 A4 29 DE 73 80 5E BF 1C 1B E9 73 0B F5 FE FD BC 92 ED 11 67 8C 94 63 AB CE 40 4C 5C D2 68 DC 2D 91 CE 19 2E BB 98

I decoded the first byte of the NAL unit header after the start marker (0xE0) as:我在开始标记(0xE0)之后将 NAL 单元 header 的第一个字节解码为:

//  forbidden_zero_bit = 1 bit (for error checking, should be 0)
//  ref_idc = 2 bits: is a reference field / frame / picture
//  unit_type = 5 bits: Specifies the NAL payload type.
var nalUnitHeader = 0xE0; // 1110 0000
var forbidden_zero = nalUnitHeader.GetBits(1, 1); // 0000 0001, 1 bit (is invalid)
var ref_idc = nalUnitHeader.GetBits(2, 2); // 0000 0011, next 2 bits
var nalUnitType = nalUnitHeader.GetBits(5, 4); // 0000 0000, next 5 bits

The spec says forbidden_zero field must always be 0, so it would appear I'm missing something.规范说禁止零字段必须始终为 0,所以看起来我错过了一些东西。 Above, GetBits() is a helper that just calculates the mask and shift offset and I confirmed it is correct unless endianness is the other way, but I checked how others do it and looks correct compared to their results.上面, GetBits()是一个助手,它只计算掩码和移位偏移量,我确认它是正确的,除非字节顺序是另一种方式,但我检查了其他人是如何做到的,并且与他们的结果相比看起来是正确的。

It turns out it was a bug in the TsDecoder library I was using to process the transport packets in the MPEG2-TS stream, that wasn't processing the adaption_field_length properly.事实证明,这是我用来处理 MPEG2-TS stream 中的传输数据包的TsDecoder库中的一个错误,它没有正确处理 adaption_field_length。 It was off by only 1 byte, but that ended up giving me an incorrect offset, and what I thought was the start of a NAL unit ended up actually being the unprocessed byte 00 and start of the Pes packet header 00 00 01 E0 .它只关闭了 1 个字节,但最终给了我一个不正确的偏移量,我认为 NAL 单元的开始实际上是未处理的字节00和 Pes 数据包 header 00 00 01 E0的开始。 Confusing, as it sure looks a lot like a NAL unit start marker 00 00 00 01 !令人困惑,因为它看起来很像 NAL 单元开始标记00 00 00 01

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM