The operating process of the encode_one_macroblock function in jm8.6

Source: Internet
Author: User
Operating Process of the encode_one_macroblock function in jm8.6 [Use of macro block cost function or selection of intra-frame mode]

 

In JM, the most important function is encode_one_macroblock. This function is the core of the entire encoder. In fact, you can find it by reading the source code, most of the work in encode_one_macroblock is to select the mode. Next we will followCodeLet's take a look at the specific process: (we assume that both frames are allowed at the same time)

 

1.The Macro Block-level mode (16x16, 16x8, 8x16) between three frames is optimized.


Initialize min_cost to the maximum value and best_mode to 1 (16x16)

1.1. Calculate the best price for each block in three modes

16*16The splitting method only needs to be calculated once,16*8And8*16The split method must be calculated twice.

1.1.1Sports search

In the partitionmotionsearch function, perform a motion search for the mode. In the search, use mv_cost to calculate the search cost. The optimal cost of the mode is saved in motion_cost and the optimal MV is saved inIMG->All_mvMedium.

It also includes the best choice for the p-frame skip mode in non-rdo mode.

1.1.2 frame selection

The ref _ cost function is used in calculation to get the reference frame cost, and the search cost of the corresponding reference frame is added in the corresponding mode, select the reference frame at the total cost (the ref_cost method is used to determine whether it is rdo or not. If the rdo method is used, select the optimal reference frame in this method.

In addition, back-to-back and two-way references should be considered for frame B.

P frame, that is, forward reference

Only add the forward reference price to the cost. The cost is based on all the costs of the entire macro block and

1.2 select the optimal cost based on the cost of an entire Macro Block

 

2. The sub-Macro Block Mode between frames (p8x8 mode: 8x8, 8x4, 4x8, 4x4) is cyclically optimized.


An entire macro block is divided into four 8x8 blocks, and then each 8x8 block is selected in the p8x8 mode.

When p8x8 is selected, min_cost8x8 (non-rdo) is initialized to be the maximum, and min_rdcost (rdo) is the maximum.

2. 1. Motion Search,


Similar to macro block-level

The cost function uses MV _ cost (including the best choice for the p-frame skip mode in non-rdo mode );

Step 2: select the best frame for reference, and use ref _ cost for the cost function;

Step 2: select the best among the three modes, and the cost function uses mode _ cost;

Step: for non-rdo modes, compare the optimal result of step with the optimal Large Mode in step 1 and select the optimal

Mode.

Step 3 select best among all modes

Step in the rdo mode, the three inter-frame bulk mode, the best P8 mode, the two intra-frame prediction modes, as well as the Skip, direct

Mode:

Step3. 1. Four Color Block intra-Frame Prediction Pattern loops;

Step: Set the Motion Prediction and reference frame mode;

Step calculate the cost mode _ cost of the seven rdo modes for comparison and decision-making.

In the non-rdo mode of step, compare the best result of step 2 with the direct mode and intra-frame prediction mode:

Step. 1. Obtain the cost mode _ cost in direct mode for better performance;

Step: Perform 4x4 and 16x16 intra-frame prediction, and use mode _ cost to select the best prediction mode.

 

 

 

 

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.