Introduction and judging method of IBP frame in video

Source: Internet
Author: User

In MPEG4 video, I-frame, p-frame, B-frame determination

Each frame of the MPEG4 is fixed at the beginning: B6, then how do we determine what frame the current frame belongs to? In the next 2bit, we will tell you the answer. Note: 2bit, not Byte, the following is the corresponding relationship between various types of frames and 2bit:

00:i Frame
01:p Frame
10:b Frame

To better illustrate, let's take a few examples, the following is the video encoding for the 16 binary display:

XX B6 10 34 78 97 09 87 06 57 87 ... I-Frame

B6------------CC B3 89 ... P-Frame

XX B6 96 88 99 06 54 34 78 90 98 ... B-Frame

Let's analyze why they are I, P, b frames, respectively.

0x10 = 0001 0000

0x50 = 0101 0000

0x96 = 1001 0100

We look at the red 2bit, and then against the beginning of the frame and 2bit corresponding relationship, is not consistent with it.

Here is a section of C + + code for everyone to refer to:[CPP]View plain copy switch (Buf[i] & (BYTE) 0xc0) {case 0x00://i Frame break;   Case 0x40://p Frame break;   Case 0x80://b Frame break;   Default:break; } From:
Http://www.cnblogs.com/ManMonth/archive/2010/02/09/1666328.html


[Go] i-p-b frame Introduction
Three types of frames
The if--i-frame abbreviation, which is the keyframe. KeyFrames are the first frame that forms a frame group (Gop,group of picture). If all the information for a scene is preserved. The compression ratio is 1:7.
The pf--p-frame abbreviation, the future individual prediction frame, stores only the difference from the previous uncompressed screen. The compression ratio is 1:20.
Bf--b-frame abbreviation, that is, two-way prediction frame, in addition to the reference before the extracted screen, will also refer to the screen information in the following frame. The compression ratio is 1:50.
There are four predictive modes for b-frame (the correct name is B-VOP in MPEG-4):
A. Forward forward forecast, refer to the previous screen, record the gap with the previous picture. The same as P-frame's prediction method.
B. Backward reverse prediction, refer to the next picture, record and the next picture of the gap.
C. bi-directionally Two-way prediction, referring to the front and back of the two screen, recording is and "two images before and after the average" gap. Also called interpolation prediction, the compression rate is the highest.
D. Direct mode, do not search, record the action vector, directly from the next P frame deduced the action vector. For example, I b P, we can predict that the B-screen action must be between the I and p two screen, so we can directly use P's MV/2 as the action vector of B, this can save the recording MV space.
Compression of the B-frame will be selected from the above several predictive mode of the smallest mode to use.


The principle of MPEG-2 image compression is to take advantage of two features in the Image: spatial correlation and temporal correlation. These two correlations make a large amount of redundant information available in the image. If we can remove these redundant information and only keep a small amount of non-related information for transmission, we can save the transmission band greatly. The receiver utilizes these non-related information, according to certain decoding algorithm, can restore the original image under the premise of guaranteeing certain image quality. A good compression coding scheme is the ability to maximize the removal of redundant information in the image.

MPEG-2 encoded images are divided into three categories, called I-frames, p-frames, and B-frames, respectively.

I-frame images are encoded in-frame, that is, using only spatial correlations within a single-frame image, rather than using temporal correlation. P-Frame and B-frame images use inter-frame encoding, i.e., the correlation between space and time is utilized simultaneously. The P-Frame image only uses forward-time prediction, which can improve the compression efficiency and image quality. The P-frame image can contain part of the intra-frame encoding, that is, each macro block in the P-frame can be forward-predicted or intra-frame encoded. B-Frame image adopts bidirectional time prediction, which can greatly improve the compression ratio.


I,b,p Frame
B-Frameb Frames (b frame)Basic ConceptsB-Frame method is the inter-frame compression algorithm for bidirectional prediction. When a frame is compressed into B-frame, it compresses the frame according to the different points of the adjacent previous frame, the frame and the next frame data, or only the difference between the frame and the front and back frames. Only B-Frame compression is used to achieve a high compression of 200:1.B-Frame modeB frame in the MPEG-4 there are four reference modes, if it is the same reference before and after the picture compression, then the record is and (the front screen pixel value after the screen pixel value)/2 of the difference, that is, and "front and rear screen average" difference. So the number of differences recorded is the same as the P-frame, only one, no increase.
And because B frame is in the middle of the front and rear screen, with "average before and after", that is, "the middle value of front and rear screen" as the predictive value (predict the pixel value of B frame. If there is an error, then record the difference), so that the predicted value will be compared to the previous screen alone to predict, closer to the current real B-frame values, it is conceivable that so the need to record the difference will be very small or even no record, so you can save a lot of bits, improve the compression ratio.
For example, brightness change I B P 7 8 9
If B is only referring to the previous screen compression, the difference value of 1 must be recorded. If you compress with (I P)/2, the difference is 0, and you do not need to record the difference. (although to record two vectors, but the vector can also be further predictive compression, in general, it will be more than a single reference to the previous screen compression is much smaller) if the screen is not such a change what to do. Generally speaking, the picture will be such a change, if it is not so change we do not use B frame even if the change is not so the rule, in other ways, b frame can refer to the screen or more than the P frame, how to find, also is B-frame can find the smaller error box to use the probability of a large (because you can choose, reference B-frames are still higher than the compression ratio of P-frames. (And much higher, the gap is very large)
In addition to the compression rate, the effect of B-frames on picture quality ... Yes, because the B-frame before and after the image of the characteristics of the screen is equal to the effect of interpolation (interpolation), so you can reduce noise.
The B-frame in the MPEG-4 is also very powerful, with the exception of the previous three reference modes and Direct mode, which saves the vector records. Although there are 4MV functions in the MPEG-4, can record four vectors, but the encoder in the compression will be judged, in the end is the use of 4MV pressure out of the results of small, or the use of traditional methods to press out the results of small.
If the result of using the traditional method is small, it is recorded using the traditional method, if the result of using 4MV is small, 4MV is used to record it.
(Ps. 4MV not used in backward predictions)
You can observe the blue Line displayed on the screen when the VirtualDub is compressed, and you will find that the blue line and the blue Line usually have a very short blue line in the middle, resulting in gaps, and the gap is very large, this is sandwiched between P B in play compression power if it is more obvious with DivX 5, because DivX 5 can only use IB PBPBPB ... This is a form B followed by a P, so the blue line on the screen is "a long, short, long, short" arrangement.
Connection and difference between keyframes and transition frames
1. The middle of two keyframes can have no transition frames (such as frame-wise animation), but there must be keyframes before and after the transition frame, because the transition frame is attached to the keyframe;
2. KeyFrames can modify the contents of the frame, but the frame cannot be modified by the transition frame.
3. KeyFrames can contain many types of elements, such as shapes, clips, groups, and many other elements, but the objects in the transition frame can only be clips (movie clips, graphic clips, buttons), or independent shapes. Image (frame) is a frame-coded image that compresses the amount of transmitted data by removing redundant information from the image as much as possible; P-image (frame) is a coded image, also called a predictive frame, that compresses the amount of data transmitted by a sufficiently redundant information that is less than the previously encoded frame in the image sequence; b Image (frame , it also takes into account the time redundancy information between the encoded frames behind the source image sequence to compress the encoded image of the transmitted data, also called the bidirectional prediction frame; Generally, I frame compression efficiency is the lowest, the P frame is higher and the B frame is the highest.

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.