Mpegts-hls Analyzing a Frame packet (H264)

Source: Internet
Author: User
Tags reserved split
analyze the first frame of a TS file (SRS supports the TS file generated by HLS protocol) 1. PAT (Ignore) 2. PMT (Ignore) 3. First FRAME (PES Packet)
Usually a frame of data is a PES package. A PES package can typically be split into multiple TS packages (it is also possible to split into only one TS package, that is, the PES package is less than 188 bytes in length).

Pespacket==tspacket1+tspacket2+tspacket3+...+tspacketn PES Packet = = ts Packet1 + ts Packet2 + ts Packet3 + ... + TS Packe Tn

4. PES Packet TS Packet (Package A frame of data as a TS package)

TS Package Structure :

3.1 First TS Package:

In the ten-7E, the E0-xx-C0 0A------------
00 From D8 to
0D C0 (2B), and the above, at the xx-xx-xx------
E0 (XX) in the C0 of the 00, the 0C B8, and the F0 of the B0 of the above-
0E 3F D5 2E C8 A5 E1 CE F4 the B3 F2 CA D2 All-in-a-
B1 BA B6 B0 7B-A8-D0
9A CB C7 D1 DC A8 51 E9 be
6D F9 CF 1 A BA 3D 1 0C b 7C
9B 3D F1 FF Geneva AB C6

3.1.1 Simple Analysis (each one will be analyzed in detail later)

First TS package = TS Header + TS adaptive field + PES head + pes optional head + SEI + SPS + PPS + TS load (IDR Frame)

TS Header : 47 41 01 30
TS Header Adaptationfield : 7E 00

PES Header : E0 00 00
PES Optional Header : C0 0A 05 11 00 39 90 81

Nalu AUD : xx F0

Nalu Delimiter : 00 00 01
Nalu Unit : from D8 to 0D C0 (SEI -A-& 0x1f-XX) at the XX = 6)

Nalu Delimiter : 00 00 01
Nalu Unit : AC 2B 3C F2 E0 (XX) in the Geneva, XX, 3D, C0, XX, and the F0 0C B8 (SPS & 0x1f = = 7)

Nalu Delimiter : 00 00 01
Nalu Unit : EE 3C B0 (PPS& 0x1f = = 8)

Nalu Delimiter : 00 00 01
Nalu Unit : 0E 3F D5 2E C8 A5 E1 CE F4 the B3 F2 CA D2 £ º B1 BA B6 B0 7B A8 D0 77 9A CB C7 D1 DC A8 $ E9 be 6D F9 CF 1 a 1 b 3D 0C 7C F1 FF Geneva AB C6 9B DB Wuyi ( idr Frame & 0x1f = = 5) 3.1.2. Detailed Analysis

A). TS Header : 47 41 01 30

Syncbyte (8 bits): 0x47 
transporterrorindicator (1 bit): 0
payloadunitstartindicator (1 bit): 1
Transportpriority (1 bit): 0
Pid (bits): 257
Transportscramblingcontrol (2 bits): 0
Adaptionfieldcontrol (2 bits): 3
Continuitycounter (4 bits): 0

B). TS Header Adaptationfield : 7E 00

TS Header Adaptationfield : TS Headers Adaptive field (top 2 bytes), 07 10

Adaptationfieldlength (8 bits): 7
discontinuityindicator (1 bit): 0
randomaccessindicator (1 bit): 0
elementarystreampriorityindicator:0
Pcrflag (1 bit): 1
opcrflag (1 bit): 0
Splicingpointflag (1 bit): 0
  
   trasportprivatedataflag (1 bit): 0
Adaptationfieldextensionflag (1 bit): 0
  

TS Header Adaptationfield Optional fields: TS header Adaptive field, optional field, 7E 00

The system clock frequency specified by the mpeg2-ts is 27mhz.pts, which is a count value of 300 in the system clock (divided by 300, refer to Iso-13818-1)

Pts converted to seconds: 1/(27mhz/300) = 1/90000

if (Pcr_flag = ' 1 ')
{
    program_clock_reference_base//Bits
    Reserved//6 bits
    Program_clock_ Reference_extension//9 bits
}

PCR : 7E 00 to 10 binary = = 30668783104

pcr_base : 30668783104 >> 15 = = 935936
pcr_ext : 30668783104 & 0x1ff = = 0

pcr_base turn into seconds: 935936/90000 = 10.39928888888889

PCR (i) =pcrbase (i) ∗300+pcrext (i) PCR (i) = PCR Base (i) * + PCR Ext (i)

PCR =pcr_base*300 + pcr_ext= 935936 * 300 + 0 = 280780800

Programclockreferencebase (in bits): 935936
Reserved (6 bits): 0x3f
programclockreferenceextension (9 bits): 0

C). PES Header : E0 00 00

Multiple TS packages are packaged into one PES package, then the first TS package should contain the PES Header.
Packetstartcodeprefix (BITS):
streamid (8 bits): 0xE0 (video, audio is 0xc0)
pespacketlength (bits): 00 00 (Length not Determine, need to calculate yourself)

D). PES Optional Header : C0 0A 05 11 00 39 90 81

pes Optional header : Transferred PES head (Top 3 bytes), C0 0A

Constten (2 bits): 2
Pesscramblingcontrol (2 bits): 0
pespriority (1 bit): 0
dataalignmentindicator (1 bit): 0
Copyrigh (1 bit) t:0
Originalorcopy (1 bit): 0
ptsdtsflags (2 bits): 3
Escrflag (1 bit): 0
Esrateflag (1 bit): 0
DSMTRICKMODEFL AG (1 bit): 0
Additionalcopyinfoflag (1 bit): 0
Pescrcflag (1 bit): 0
Pesextensionflag (1 bit): 0
Peshe Aderdatalength (8 bits): Ten (0x0A)

pes Optional header Optional field: Optional field in the transferred PES header--05 11 00 39 90 81

if (Ptsdtsflag = = ')//PTS

0x0010 + pts[30...32] + marker__bit + pts[29...15] + marker__bit + pts[14...0] + Marke R__bit

if (Ptsdtsflag = = ' one ')  //Pts,dts

0x0011 + pts[30...32] + marker__bit + pts[29...15] + marker__bit + pts[14...0] + marker__bit
0x0001 + dts[30...32] + marker__bit + dts[29...15] + marker__bit + dts[14...0] + marker__ Bit

PTS : 05 to 10 binary = = 210457193989
DTS : 11 00 39 90 81 into 10 = = 73018216577

Pts[30 ... ((210457193989>>) & 0x7) << 30 = = 0
Pts[30 ... ((210457193989>>) & 0x7fff) << 15 = = 917504
Pts[30 ... ((210457193989>> 1) & 0x7fff) = = 30466

Pts[30 ... ((73018216577>>) & 0x7) << 30 = = 0
Pts[30 ... ((73018216577>>) & 0x7fff) << 15 = = 917504
Pts[30 ... ((73018216577>> 1) & 0x7fff) = = 18496

Parse PTS--947970 (917504 + 30466)/90000 = = 10.533
Parse DTS--936000 (917504 + 18496)/90000 = = 10.4

Pts (BITS): 947970
Dts (bits): 936000

E). Nalu AUD : xx F0

At each frame of the video frame is packaged into PES, its beginning must be added to the F0 of this Nalu AUD.

https://developer.apple.com/library/ios/#documentation/networkinginternet/conceptual/streamingmedia

F). SEI : Nalu unit:06 D8 0D C0 01 07 00 00 18 00 00 03 00 04 80 00

Supplementary Enhancement Information

G). SPS : Nalu unit:27, AC 2B 3C, F2 E0, 80 00 64 30 00 00 64 (3D C0) PNS BD F0 0C B8 00

Sequence Parameter Set

H). PPS : Nalu unit:28 EE 3C B0

Picture Parameter Set

I). IDR : Nalu unit:25 0E 3F D5 2E, C8 A5 E1 CE F4, B3 F2 CA D2, B1 BA B6 B0 7B A8 D0 1 ff 9A CB C7 D1 DC A8 E9 be F9 CF a BA 6D 3D 0C 1-B 7C 9B 3D F1 FF Geneva AB C6 8A D B 51

instantaneous decoding refresh: Instant decoding refreshes.

IDR and I-frame differences: The first I-frame is called an IDR frame. The IDR frame is a subset of the I frames.

I P B frame : YUV Data, Macroblock, frame, Slice. Macro block is the basic unit of encoding processing

Slice Three encoding modes :i_slice,p_slice,b_slice, so according to Slice to differentiate IDR,I, P,B -frame. 3.2 The second TS package to the second-to-last TS package of this frame:

This frame of data (that is, a PES package), a total of 119,756 bytes, is altogether 637 TS packets (119756/188 = 637).

In the middle of the TS Package (2nd-No. 636), a fixed format:

Tspacket=tshe

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.