Max
Max

Reputation: 59

How to understand header of H.265

Could someone explain me the difference between the H.264 header and H.265 header? I just need to parse H265 header but I have difficult to find proper reference.

I did a first version of the parser. I need to retrieve the pic_width_in_luma_samples, pic_height_in_luma_samples, and the aspectRatioH, aspectRatioV.

my code is something like:

while (buf->Size > 0)
{
    //forbidden bit

    flushbits(buf, 1); 

    int nNALType = showbits(buf, 6);

    if (nNALType == NAL_TYPE_SPS)
    {
        // flushbits until I retrieve desired parameter

        flushbits(buf, 4); // sps_video_parameter_set_id
    }
    else
    {
        // align bits

        buf->Size -= buf->BitsLeft & 0x7; 
    }
}

this is the correct way to do? There is a method where I can skip bits until I find a "start sequence" that indicates my desired SPS NAL TYPE?

Upvotes: 1

Views: 7023

Answers (2)

Massimo
Massimo

Reputation: 165

follow those step to parse H265

  • each NAL unit starts with a start code that is 3 bytes with value 0x01 (so 00 00 01). Identify each NAL unit;
  • parse the header (2 bytes)
  • for the other part of NAL sequence: find for 3 byte sequence 00 00 03, keep the first 2 bytes (00 00) and discard the 03 byte.
  • with the bytes don't discarded, you can do the parsing (depending of the NAL unit type you have)

Upvotes: 3

Markus Schumann
Markus Schumann

Reputation: 8274

The syntax of H.264 and H.265 is relative similar.

Both have parameter sets (PPS, SPS) you find the details in the specification below. For H.265 - page 33 section 7.3 describes the video parameters sets in detail. The specification is done in 'C' like pseudocode so relatively easy to translate the specification into compiling code.

You can always look at some existing code - for example:

https://github.com/GStreamer/gstreamer/blob/main/subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/gsth265parser.c

The H.264 (AVC) specification is here:

https://www.itu.int/rec/T-REC-H.264-202108-I/en

The H.265 (HEVC) specification is here:

https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-H.265-201802-S!!PDF-E&type=items

Upvotes: 4

Related Questions