JM8.5中的7种宏块模式问题 - zhoujunming的专栏 - CSDN博客

来源:互联网 发布:如何成为网络段子手 编辑:程序博客网 时间:2024/06/02 03:55

JM8.5中的7种宏块模式问题 收藏
Outline:

1、  CFG文件中有关可变尺寸宏块模式的相关选项
2、  7种宏块模式对应的数值常量
3、  7种宏块模式被分成宏块和亚宏块
4、  如何对宏块和亚宏块的运动估计,采用一个共同的函数来处理
5、  遗留问题
 

 1、CFG文件中有关可变尺寸宏块模式的相关选项

###############################################################################
#Encoder Control
###############################################################################
InterSearch16x16      =  1  # Inter block search 16x16 (0=disable, 1=enable)
InterSearch16x8       =  1  # Inter block search 16x8  (0=disable, 1=enable)
InterSearch8x16       =  1  # Inter block search  8x16 (0=disable, 1=enable)
InterSearch8x8        =  1  # Inter block search  8x8  (0=disable, 1=enable)
InterSearch8x4        =  1  # Inter block search  8x4  (0=disable, 1=enable)
InterSearch4x8        =  1  # Inter block search  4x8  (0=disable, 1=enable)
InterSearch4x4        =  1  # Inter block search  4x4  (0=disable, 1=enable)

解释:

各种宏块尺寸可以在程序外部进行选择。

2、  7种宏块模式对应的数值常量

各种宏块模式对应的数值常量如下:
16×16-1     16×8-2       8×16-3       8×8-4    8×4-5     4×8-6      4×4-7 

以上的数值常量的rdopt.c的encode_one_macroblock()中的valid[]数组和mode变量中会用到,另外在mv_search.c的PartitionMotionSearch()中的blocktype变量也会用到。

 

3、   7种宏块模式被分成宏块和亚宏块

16x16, 16x8, 8x16(,8×8)被称为宏块级,而8×8,8×4,4×8,4×4被称为亚宏块级。
所用到的函数是:encode_one_macroblock(),rdopt.c
该函数的作用是编码一个宏块(包括帧间、帧内、帧内预测的方式)。
其中重要的程序段如下:
 
//宏块级运动估计
//===== MOTION ESTIMATION FOR 16x16, 16x8, 8x16 BLOCKS =====
for (min_cost=1<<20, best_mode=1, mode=1; mode<4; mode++)
{
    if (valid[mode])//对应于程序外部(即CFG文件中)的设置
    {
        //对于16×16,MB只分一个块;对于16×8和8×16,MB被分成两个块
        for (cost=0, block=0; block<(mode==1?1:2); block++)
        {
            //块匹配!!!lambda_motion用来求运动矢量消耗的码率
           PartitionMotionSearch (mode, block, lambda_motion);
            …
//亚宏块级运动估计
if (valid[P8x8])
{
  …
//=====  LOOP OVER POSSIBLE CODING MODES FOR 8x8 SUB-PARTITION  =====
for (min_cost8x8=(1<<20), min_rdcost=1e30, index=(bframe?0:1); index<5; index++)
{
    if (valid[mode=b8_mode_table[index]])//b8_mode_table[6] = {0, 4, 5, 6, 7};
    {
       curr_cbp_blk = 0;
        if (mode==0) //--- Direct Mode ---
        {
            …
        } // if (mode==0)
        else
        {
            //--- motion estimation for all reference frames ---
            PartitionMotionSearch (mode, block, lambda_motion);
         …
NOTE:从上面程序段中可以看出JM8.5中对7种宏块模式是采用全部遍历的方式,所以导致的计算复杂度很高。
 4、  如何对宏块和亚宏块的运动估计,采用一个共同的函数来处理
从3中的程序可以看到,对于宏块和亚宏块级的运动估计,都采用了一个共同的函数:PartitionMotionSearch(), mv_search.c
其中重要的程序段如下:

……
//各种宏块模式下的子块的起始偏移量,相对4*4块来讲,这有利于运动矢量的存放
//[5]表示宏块的类型,[4]表示各种类型下的子块序号,最多子块情况为P8X8模式下有4个
static int  bx0[5][4] = {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,2,0,0}, {0,2,0,2}};
static int  by0[5][4] = {{0,0,0,0}, {0,0,0,0}, {0,2,0,0}, {0,0,0,0}, {0,0,2,2}};
……
int   parttype  = (blocktype<4?blocktype:4);//亚宏块的parttype都设为4
 
//step_?是用来求4*4块级别的步长,

//由于parttype和blocktype的区别使得两组步长之间存在微妙的差异,为下面的循环做好了铺垫

int   step_h0   = (input->blc_size[ parttype][0]>>2);
int   step_v0   = (input->blc_size[ parttype][1]>>2);
int   step_h    = (input->blc_size[blocktype][0]>>2);
int   step_v    = (input->blc_size[blocktype][1]>>2);
 
//===== LOOP OVER SUB MACRO BLOCK partitions
//这里对于亚宏块的循环是自适应的,
//假如小于8*8块尺寸时,自动采取循环
for (v=by0[parttype][block8x8]; v<by0[parttype][block8x8]+step_v0; v+=step_v)
{
    pic_block_y = img->block_y + v;
    for (h=bx0[parttype][block8x8]; h<bx0[parttype][block8x8]+step_h0; h+=step_h)
    {
……
原创粉丝点击