With the popularity of H.265, more and more developers hope that the DANniu Live SDK can support RTSP H.265 playback with low latency, and share relevant experience:

Implementation idea:

For the RTSP, playing H265 requires only proper parsing of SDP and RTP packets. Here are some introductions to these related contents.

1. H265 Nal Unit Header

The Nal Unit header of H264 is one byte, and 265 becomes two bytes:



F: 1 bit. Forbidden_zero_bit. 265

The value is 32 for VPS, 33 for SPS, 34 for PPS, 39 for SEI, 19 for IDR, and 20 for IDR.

LayerId: 6 bits. nuh_layer_id. It is now 0 and may be extended in the future.

Nuh_temporal_id_plus1. TemporalId is TID-1.

2. SDP parameters:

2.1 Media subtypes assigned to H265 by the IETF are as follows: Type name: Video Subtype Name: H265 Optional: profile-space, tier-flag, profile-id, profile-compatibility-indicator, interop-constraints,level-id, Sprop-sub-layer-id, recv-sub-layer-ID, max-recv-level-ID, TX-mode, Sprop-VPS, Sprop-SPS, sprop-PPS, etc. Please refer to relevant documents for details. You are advised to resolve Sprop-VPS, Sprop-SPS, and Sprop-PPS.

2.2 SDP Example: m=video 0 RTP/AVP 96 A = RTPmap :96 H265/90000 A = FMTP :96 profile-space=0; profile-id=0; tier-flag=0; level-id=0; interop-constraints=000000000000; sprop-vps=QAEMAf//AIAAAAMAAAMAAAMAAAMAALUCQA==; sprop-sps=QgEBAIAAAAMAAAMAAAMAAAMAAKACgIAtH+W1kkbQzkkktySqSfKSyA==; Sprop-pps =RAHBpVgeSA== Note that the code name must be H265 and Clock reate must be 90000.

3. RTP package format

In practice, there are two formats, one is a NAL unit packaged into an RTP packet. One is that the NAL unit is large and the fragments are packed into multiple RTP.

3.1 Packing a SINGLE Nal Unit:

PayloadHdr just fills in the NAL unit header.

3.2 Fragmented packaging of Nal units:

PayloadHdr copies the NAL unit header, but changes the Type to 49. FU header is a single byte, and the format is as follows:

+—————+

|0|1|2|3|4|5|6|7|

+-+-+-+-+-+-+-+-+

|S|E| FuType |

+—————+

S: 1 indicates the first shard. E: 1 indicates the last fragment. FuType is the actual Nal type.

4. Summary:

H265 is similar to H264 in that it has SPS and PPS and is separated by 00 00 00 01 nal units.

Relevant information sharing: RTP Payload Format for HEVC: pike. Lysator. Liu. Se/docs/ietf/r…