H264 es stream files differentiate frame boundaries by calculating first_mb_in_slice

Source: Internet
Author: User

Due to my recent reading of h264 files, I encountered the problem of how to read the full frame data, through the use of Elecard Stream Analyzer tools, as well as the combination of "new generation of video compression coding standard--H264/AVC" (second edition) book, and found in the online summary as follows:

First NAL syntax, title syntax, and Nal_unit_type semantics must know:



The above two graphs are truncated from "New generation video compression coding standard--H264/AVC" (second edition)

A simple way to distinguish frames is to read the files when compared to the 0x00 0x00 0x00 0x01, if the equivalence is considered a slice, then read a byte on the corresponding table 6.1 forbidden_zero_bit (1bit), NAL_REF_IDC (2bit), nal _unit_type (5bit), Nal_unit_type value based on table 6.20 to determine the frame type, for 7,8 is not first_mb_in_slice, you can read to the next 0x00 0x00 0x00 0x01 the data between this is the parameter set data. For 1,5 there are first_mb_in_slice and the first first_mb_in_slice of each frame is 0, which is useful for acquiring a frame of data that is divided into multiple pieces.

Here is the analysis of the index Columbus Code: from http://blog.csdn.net/simongyley/article/details/8517817

When parsing the K-Order index Columbus Code, we first look for the first non 0 bits from the current position of the bit stream, and then count the 0 bits found as leadingzerobits, and then compute codenum according to Leadingzerobits. Described in Pseudocode are as follows:

First_mb_in_slice is the need to h264 through the Expgolomb encoded a string of 2 of the number of Expgolomb decoding, through the online search and combined with H264 file analysis, finally found a calculation method, now share with you, If there is something wrong, please correct me.

I frame condition:

As shown in the following illustration:


88 80 = 1000 1000 1000 0000 Assuming the order is 0, then leadingzerobits=0, Codenum (first_mb_in_slice) = 1-1+0=0

06 62 = 0000 0110 0110 0010 Assuming the order is 0, then leadingzerobits=5, Codenum (First_mb_in_slice) =2exp (5) -2exp (0) +10011 (2) =32-1+19 =50

P Frame Condition:

As shown in the following illustration:


9A 00 = 1001 1010 0000 0000 Assuming a order of 0, then leadingzerobits=0, Codenum (first_mb_in_slice) = 1-1+0=0

03 29 = 0000 0011 0010 1001 Assuming the order is 0, then leadingzerobits=6, Codenum (First_mb_in_slice) =2exp (6) -2exp (0) +100101 (2) =64-1+3 7=100

In fact, for the 0-order, the simplest way is to determine whether the first bit of the byte is 1, if it is 1,codenum (first_mb_in_slice), definitely 0, is the first piece of the frame.

The principle explanation finished, hoped to have the help to everybody. Specific calculation First_mb_in_slice code should be more online, you can also refer to the FFmpeg.


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.