Extracting h264 data from the PS stream of Hoi Hong

Source: Internet
Author: User
Tags documentation pack

Hoi Hong 7816 uses the PS stream to encapsulate the H. P data, the decoder used here does not recognize the PS stream, so the h264 data needs to be extracted from the PS stream

Refer to the 13818-1 documentation for PS flow rules

Here we get some data samples from 7816.

The B8 of the BA--------------------------FE FF FF, 0100, BC00 5A E0 FF, 0E, 4 B, 0D AF C5 D3 E0 0 7 FF FF FF FF 4 b xx xx xx xx xx xx xx xx xx 2C 1 b E0 40 0E xx A0, C0 02, XX 1F ff 1C C0 (0C) 0A (FE) 7D E8, FF BD BD, BF bf, XX, xx, 0000, E0 1 a 8C 0A 1C C9 AE 0D FF FF FF FF FC P/F 00 00 01 A8 2C XX/1E + + 0E 0003 ff 00 3C, E0 (8C)----XX

As above is the beginning of the data of an I-frame, as follows is a non-I-frame of the beginning of the data section

The xx--------BA----------------------------------E0 8C 0A 1C C9 E6 4D FF FF FF F8 ...

Can be seen in the beginning of the XX, this is the PS Baotou (Program Stream Pack header), where 00 00 01 is Pack_start_code, is the beginning of a packet identification, the next 1byte (BA) is the stream identity (stream _ID), in the table 2-33 and 2.5.3.4 section of document 13818-1, there is a description of the program Stream Pack header.

Here is a list of the above I frames (Program Stream pack header)

XX (BA) B8-FE FF FF 00 00 00 01

According to the document description Baotou has a minimum of 14 bytes, the last 3bit of the 14th byte describes the length of the padding data after 14 bytes of Baotou, here is pack_stuffing_length=fe&0x07= 6, with 6byte of fill data, both FF FF 00 00 00 01, Hai Kang 7816 Use this part of the fill data to illustrate the ordinal of each frame, 01 is the 1th frame of data.

Note that Baotou may also have the system header, the ID is BB, he is also part of the Baotou, and his length is not counted in the pack_stufing_length, such as:

0C CC F5 E1 7F E0 E0 E8 C0 C0 20

The 0C after the starting code shows the length of the subsequent data, which is 12 bytes

After the program stream Pack header is a package that begins with the BC, 00 00 01 is the PACK_START_CODE,BC is the stream_id stream ID, which is illustrated with the program stream pack header After that is the program Stream map. Table 2-35 and 2.5.4.2 section of document 13818-1 has a description of the program Stream Pack header.

The two-bit following the BC is a description of the program Stream map, he is also a kind of PES package, the length of the package program_stream_map_length, here is 5 A, the following data length is 90, Skip this. The following 90byte data is a package starting with E0, E represents the PES package for the gb/txxxx.2 or gb/taaaa.2 video stream number XXXX specification, and 0 indicates that the stream ID is 0,h264 data in this package.

From program Stream Map We can also tell what stream the PEs stream is (Stream_type and elementary_stream_id indicate), and the frame rate (), etc.

1110XXXX (0XEX) for video data, 111XXXXX for audio data, after the frame about the information of 5 bytes, 2 bytes pes packet length is 1 A, indicating that the length of this PES packet is 0x001a or 26 bytes; 2 bytes Standard bit information is 8C 80, the last byte in 5 bytes indicates that the additional data length is 0 A, followed by the length of the attached data is the video data payload.

PES package can have multiple, here I-frame to put the data into a number of PES package, where the non-I-frame there is only one PES package

With the above information can be stripped from 7816 h246 data, more detailed instructions please refer to the documentation.

Capture a section of PES Baotou for analysis

XX E0 1 A 8C 0A 1C C9 AE 0D FF FF FF FF FC
The 1a:2 byte indicates the length
8C (10 00 1 1 00): The first is a fixed value of 10.
The next two bits are (PES scrambling control field) Pes_scrambling_control, this is 00, which means no scrambling (encryption). The rest of the 01,10,11 is custom-defined by the user.
The next 4th bit is the PES Priority field (pes_priority), when 1 is the high priority and 0 is the low priority. Here is 1.
The next 3rd bit is the (Data Alignment indicator field) Pesdata_alignment_indicator,
The next 2nd place is the copyright bit,
The next 1th place is the copyright bit,
80 (10 000000):
The first is the PTS,DTS flag field, which is 10, which indicates that there are PTS and no DTS.
The next 6th bit is the ESCR flag field, which is 0, indicating that there is no segment
The next 5th bit is the ES rate Flag field, which is 0, indicating that there is no segment
The next 4th bit is the DSM stunt mode flag field, which is 0, which means there is no segment
The next 3rd bit is the additional copyright Information Flag field, which is 0, indicating that there is no segment
The next 2nd bit is the PES CRC flag field, which is 0, indicating that there is no segment
The next 1th bit is the PES extension flag field, which is 0, which means there is no segment
0A (10): 8 bytes, which indicates the total number of bytes occupied by the optional field and any padding bytes contained in the PES group header. The bytes before the field indicate that there are no optional fields (only pts here).
Because here the PTS,DTS flag field is 10, then there are 5 bytes of PTS segment, that is here 1C C9 AE 0D
The last five bytes of FF FF FF FC is one of the self-reducing count values of Hai Kang



[CPP]  View plain copy #pragma  pack (1)       union littel_endian_size   {        unsigned short int  length;        unsigned char       byte[2];  };      struct pack_start_code   {       unsigned char  start_code[3];       unsigned char stream_id[1];  };       struct program_stream_pack_header   {        pack_start_code PackStart;// 4       unsigned char buf[ 9];       unsigned char stuffinglen;  };       struct program_stream_map   {       pack_start_code  Packstart;       littel_endian_size PackLength;//we mast do exchange        //program_stream_info_length       //info        //elementary_stream_map_length       //elem   };      struct program_stream_e   {        pack_start_code     packstart;       littel_endian_size   PackLength;//we mast do exchange       char                 PackInfo1[2];        unsigned char       stuffing_length;   };      #pragma  pack ()       int inline  ProgramstreampackheAder (char* pack, int length, char **nextpack, int *leftlength)    {        //printf ("[%s]%x %x %x %x\n",  __function__, pack[ 0], PACK[1], PACK[2], PACK[3]);  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.