Multimedia Development --- h264 height and width acquisition

Source: Internet
Author: User
Tags coding standards
(School of Computer Science & Technology, Soochow University, Suzhou 215006 ;) Abstract:H. 264 is the newest video coding standard, and it will be widely used. in this article, the problem of the Structure of coding streaming in H. 264 is discussed. firstly, the simple profile of H. 264. Video is introduced. secondly, the structure of coding streaming is discussed, and then give the graph on it. finally, by a simple experiment, give the method of getting picture's width and height from the coding stream. Keywords:H.264; nal; structure of coding streaming IntroductionH. 264 is a new generation of video coding standards, has a wide range of application prospects, is the ITU-T video coding Expert Group (VCEG) and ISO/IEC activity image coding Expert Group (mPEG) A new digital video encoding standard developed by video groups. It is not only an ITU-t h. 264 is part 2 of the MPEG-4 of ISO/IEC. H.264, like the previous standard, is also a hybrid encoding mode for DPCM plus transform encoding. It has a wide range of application targets and can meet various video applications at different rates and in different scenarios. It has good anti-error code and anti-packet loss processing capabilities. H. 264 of basic systems do not need to use copyrights. They are open in nature and can well adapt to the use of IP addresses and wireless networks, this is of great significance to the transmission of multimedia information over the Internet and broadband information in mobile networks. 1 H.264 framework IntroductionH.264 defines three frameworks [2]. Each Framework supports a series of codec functions and has a series of applications. The following is a brief introduction: (1) Baseline profile: as a simple version of H.264, it is widely used. It supports inter-frame and intra-frame encoding, I-frame and p-frame, and cavlc. Its main applications are videophone video conferencing and wireless communication. (2) Main Frame (main profile): supports staggered videos and B frames, mainly used for inter-frame encoding, weight prediction, entropy encoding, and cabac. Its main applications are video storage and television broadcasting. It adopts a number of technical measures to improve image quality and increase compression ratio, and can be used for sdtv, HDTV, and DVD. (3) extended profile: video and cabac are not supported, but some effective frame modes are added for bit stream switching, si switching I frame and SP switching P frame can effectively improve the ability to recover from errors. Its main application is video stream transmission applications on various networks. 2 h264 code stream Structure 2.1 h264 layered structureThe stream structure defined by H.263 is a hierarchical structure with four layers in total. From top to bottom: picturelayer, Gob layer, macroblock layer, and block layer ). Compared with H.263, H.264's bitstream structure is very different from H.263's. It no longer uses a strict hierarchical structure. H.264 has two functions: the video encoding layer (VCL) and the network extraction layer (NAL). The VCL data is the video data sequence after compression and encoding. VCL data can be transmitted or stored only after it is encapsulated in the nal unit. NAL unit format [2] Table 1:
Table 1 nal unit format
NAL Header Rbsp NAL Header Rbsp
Rbsp: The data encapsulated in the network abstraction unit is called the original byte sequence load rbsp, which is the basic transmission unit of Nal. Among them, rbsp is divided into video encoding data and control data. The basic structure is that the ending bit is added after the original encoding data. One bit "1" several BITs "0" for byte alignment. 2.2 H.264 code stream StructureBased on relevant knowledge, the code stream structure of H.264 is summarized as shown in [2] 1:

 

 

Figure 1 code stream structure of H.264


 

3 H.264 code stream analysis applicationIn some cases, relevant information (such as the image width and Image Height) needs to be directly obtained from the H.264 code stream ). The following describes how to obtain the relevant information: The image information is stored in the rbsp structure of the network extraction layer (NAL, it is necessary to obtain the correlation bit of the image. Obtain the pic_width_in_mbs_minus1 and pic_height_in_map_units_minus1 values based on the rbsp structure. The width is (pic_width_in_mbs_minus1 + 1) * 16, and the height is (cost + 1) x, however, in some cases, the value of nnum_ref_frames must be considered. Generally, the value is 1. 3.1Obtain Test DataDevice: sunnic (IP cam) Name: st100factoryfirmware version: p8b8 video format: H. 264 (1) set the device resolution to 176*144, capture a set of data using Ethereal and other packet capture tools, and remove the corresponding RTP Header, the data is 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0x00, 0x1e, 0x99, 0xa0, 0xb1, 0x31. (2) set the device resolution to 720*240, capture a set of data using Ethereal and other packet capture tools, and remove the corresponding RTP Header, the data is 0 x, 0 x, 0 x, 0 x, 0 x, 0x42, 0xe0, 0x1e, 0xda, 0x82, 0xd1, 0xf1. (3) set the device resolution to 720*480, capture a set of data using Ethereal and other packet capture tools, and remove the corresponding RTP Header, the data is 0 x, 0 x, 0 x, 0 x, 0 x, 0x42, 0xe0, 0x1e, 0xdb, 0x82, 0xd1, 0xf1. 3.2 writing related proceduresThe key code of the program is as follows: void geth264resolution (byte * pinbuf, Int & nheight, Int & nwidth, Int & nnum_ref_frames ){...... Ue_v (nindex, nshiftcount, nshiftbuffer, buffers, pframehead); DWORD buffers = 0; myshift (1, nindex, nshiftcount, nshiftbuffer, buffers, pframehead); DWORD buffers = 0; ue_v (nindex, nshiftcount, nshiftbuffer, pic_width_in_mbs_minus1, pframehead); DWORD encoding = 0; ue_v (nindex, nshiftcount, nshiftbuffer, pic_height_in _ Map_units_minus1, pframehead); ue_v (nindex, nshiftcount, nshiftbuffer, buffers, pframehead); nwidth = (Bytes + 1) * 16; // The width of the image nheight = (Bytes + 1) * 16; // Image Height} voidmyshift (intncount, Int & nindex, Int & nshiftcount, byte & nshiftbuffer, DWORD & nrecv, byte * pinbuf) {// obtain the corresponding bit value from the data stream. While (ncount! = 0) {If (ncount> nshiftcount) {nrecv = nrecv <nshiftcount; nrecv | = nshiftbuffer> (8-nshiftcount); nshiftbuffer = pinbuf [++ nindex]; ncount-= nshiftcount; nshiftcount = 8;} else {nrecv = nrecv <ncount; nrecv | = nshiftbuffer> (8-ncount); limit-= ncount; nshiftbuffer <= ncount; ncount = 0 ;}}} 3.3 test results and conclusions(1) put the data stream 0x176, 0 x, 0 x, 0 x, 0 x, 0x00, 0x1e, 0x99, 0xa0, 0xb1, 0x31 into geth1_resolution, and get the nwidth, nheight is 144, and nnum_ref_frames is 1. The result is correct when compared with the original data. (2) put the data stream 0x720, 0 x, 0 x, 0 x, 0x42, 0xe0, 0x1e, 0xda, 0x82, 0xd1, 0xf1 into geth1_resolution, and obtain the nwidth, nheight is 240, and nnum_ref_frames is 1. The result is correct when compared with the original data. (3) put the data stream 0x720, 0 x, 0 x, 0 x, 0x42, 0xe0, 0x1e, 0xdb, 0x82, 0xd1, 0xf1 into geth1_resolution, and obtain the nwidth, nheight is 240, and nnum_ref_frames is 2. Compared with the original data, 240 is exactly half of 480, And the nnum_ref_frames here is exactly 2. Check the relevant information and find that in order to display the data properly, you need to perform the interleave operation on two frames of data to display the data normally. H.264 is a new generation of video encoding standard and has broad application prospects. This method is used to obtain the image height and width before decoding. In some scenarios where the image width and height need to be known, especially in some applications that play h264 videos, it will be of great help. Http://www.cnblogs.com/garywlx/archive/2012/10/17/2728119.html

Multimedia Development --- h264 height and width acquisition

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.