帧内预测模式提取

if (input->rdopt)
    {
      int mb_available_up;
      int mb_available_left;
      int mb_available_up_left;
     
      min_rdcost = max_rdcost;
     
      // precompute all new chroma intra prediction modes
   //++ 对色度进行帧内预测
      IntraChromaPrediction8x8(&mb_available_up, &mb_available_left, &mb_available_up_left);
     
   //++ 分别在四种色度模式下进行 RDO 计算,如果是 inter 模式,因为色度预测模式与 SSD 计算
   //++ 无关,因此只需要计算一次(利用 currMB->c_ipred_mode == DC_PRED_8 条件限制来实现)
      for (currMB->c_ipred_mode=DC_PRED_8; currMB->c_ipred_mode<=PLANE_8; currMB->c_ipred_mode++)
      {
       
        // bypass if c_ipred_mode is not allowed
        if ((currMB->c_ipred_mode==VERT_PRED_8 && !mb_available_up) ||
          (currMB->c_ipred_mode==HOR_PRED_8 && !mb_available_left) ||
          (currMB->c_ipred_mode==PLANE_8 && (!mb_available_left || !mb_available_up || !mb_available_up_left)))
          continue;
       
       
        //===== GET BEST MACROBLOCK MODE =====
        for (ctr16x16=0, index=0; index<7; index++)
        {
          mode = mb_mode_table[index];
         
          //--- for INTER16x16 check all prediction directions ---
          if (mode==1 && img->type==B_SLICE)
          {
            best8x8pdir[1][0] = best8x8pdir[1][1] = best8x8pdir[1][2] = best8x8pdir[1][3] = ctr16x16;
            if (ctr16x16 < 2) index--;
            ctr16x16++;
          }
         
          img->NoResidueDirect = 0;
         
          if (valid[mode])
          {
            // bypass if c_ipred_mode not used
    //++ 设置当前宏块类型以及其中每个8*8块的分割方式和预测方向,每个4*4块的参考帧索引
    //++ 该函数在下面的 RDCost_for_macroblocks 函数内再次调用,进行了重复操作
            SetModesAndRefframeForBlocks (mode);
            if (currMB->c_ipred_mode == DC_PRED_8 || //++ 利用这个条件限制来实现 inter 模式时只计算一次 RDO
              (IS_INTRA(currMB) ))
            {
              if (RDCost_for_macroblocks (lambda_mode, mode, &min_rdcost)) //++ 帧内模式时亮度存在重复计算情况:因为色度预测模式与亮度预测模式无关,所以在该色度模
              {                 //++ 式循环中每次计算得到的 intra16*16 和 intra4*4 宏块类型的最佳亮度模式都是完全相同的
                //Rate control
                if(mode == P8x8)
                {
                  for (i=0; i<16; i++)
                    for(j=0; j<16; j++)
                      diffy[j][i] = imgY_org[img->opix_y+j][img->opix_x+i] - mpr8x8[j][i];
                }else
                {
                  for (i=0; i<16; i++)
                    for(j=0; j<16; j++)
                      diffy[j][i] = imgY_org[img->opix_y+j][img->opix_x+i] - pred[j][i];
                }
               
                store_macroblock_parameters (mode);
              }
            }
          }
          if (valid[0] && bframe && mode == 0 && currMB->cbp && (currMB->cbp&15) != 15) //g050
          {
            img->NoResidueDirect = 1;
            if (RDCost_for_macroblocks (lambda_mode, mode, &min_rdcost))
            {
              //Rate control
              for (i=0; i<16; i++)
                for(j=0; j<16; j++)
                  diffy[j][i] = imgY_org[img->opix_y+j][img->opix_x+i] - pred[j][i];
                store_macroblock_parameters (mode);
            }
          }
        }
      }
    }
    else
    {
      if (valid[0] && bframe) // check DIRECT MODE
      {
        cost = (have_direct?cost_direct:Get_Direct_CostMB (lambda_mode));
        cost -= (int)floor(16*lambda_motion+0.4999);
        if (cost <= min_cost)
        {
          //Rate control
          for (i=0; i<16; i++)
            for(j=0; j<16; j++)
              diffy[j][i] = imgY_org[img->pix_y+j][img->pix_x+i]-img->mpr[i][j];
           
            min_cost = cost;
            best_mode = 0;
        }
      }
      if (valid[I4MB]) // check INTRA4x4
      {
        currMB->cbp = Mode_Decision_for_Intra4x4Macroblock (lambda_mode, &cost); //++ 计算当前宏块采用intra4*4编码时的代价和CBP
        if (cost <= min_cost)
        {
          //Rate control
          for (i=0; i<16; i++)
            for(j=0; j<16; j++)
              diffy[j][i] = imgY_org[img->pix_y+j][img->pix_x+i]-img->mpr[i][j]; //++ 保存采用intra4*4编码时最佳模式的残差块
           
            min_cost = cost;
            best_mode = I4MB;
        }
      }
      if (valid[I16MB]) // check INTRA16x16
      {
        intrapred_luma_16x16 (); //++ 分别计算当前宏块在4种intra16*16帧内预测模式下的预测块
        cost = find_sad_16x16 (&i16mode); //++ 计算intra16*16类型的代价(以SATD作为判断标准,因为该段代码是不采用RDO的处理过程)
        if (cost < min_cost) //++ 如果采用intra16*16类型编码的代价小于采用intra4*4类型编码的代价,则对当前宏块采用intra16*16类型编码
        {
          //Rate control
          for (i=0; i<16; i++)
            for(j=0; j<16; j++)
              diffy[j][i] = imgY_org[img->pix_y+j][img->pix_x+i]-img->mprr_2[i16mode][j][i];
           
            best_mode   = I16MB;
            currMB->cbp = dct_luma_16x16 (i16mode); //++ 对当前宏块采用intra16*16类型进行编码,并计算CBP
        }
      }
    }
   
    if (rerun==0)
    {
      intra1 = (currMB->mb_type==I16MB || currMB->mb_type==I4MB ? 1 : 0);
    }
} // for (rerun=0; rerun<runs; rerun++)

if (input->rdopt)
{
   
    if ((cbp!=0 || best_mode==I16MB ))
      currMB->prev_cbp = 1;
    else if (cbp==0 && !input->RCEnable)
    {
      currMB->delta_qp = 0;
      currMB->qp = currMB->prev_qp;
      img->qp = currMB->qp;
      currMB->prev_cbp = 0;
    }

    set_stored_macroblock_parameters ();
}
else
{
    //===== set parameters for chosen mode =====
    SetModesAndRefframeForBlocks (best_mode); //++ 设置当前宏块的参数,包括:宏块类型(mb_type)、4个8*8块的分割模式和预测方向(b8mode,b8pdir)、16个4*4块的参考帧索引(ref_idx,ref_pic_id)
    if (best_mode==P8x8)
    {
      SetCoeffAndReconstruction8x8 (currMB);
    }
    else
    {
      if (best_mode!=I4MB)
      {
        for (k=0, j=img->block_y; j<img->block_y+4; j++)
          for (     i=img->block_x; i<img->block_x+4; i++, k++)
          {
            ipredmodes    [i][j] = DC_PRED;
            currMB->intra_pred_modes[k] = DC_PRED;
          }
          if (best_mode!=I16MB)
          {
            LumaResidualCoding ();
            //Rate control
            for (i=0; i<16; i++)
              for(j=0; j<16; j++)
                diffy[j][i] = imgY_org[img->pix_y+j][img->pix_x+i]-img->mpr[i][j];
          }
      }
    }
    // precompute all chroma intra prediction modes
    IntraChromaPrediction8x8(NULL, NULL, NULL); //++ 对色度块进行处理,包括:分别计算4种色度帧内预测模式下的预测块、代价(该分支未采用RDO,因此以SATD作为判断标准)、最佳预测模式
    img->i16offset = 0;
    dummy = 0;
    ChromaResidualCoding (&dummy);
    if (best_mode==I16MB)
    {
      img->i16offset = I16Offset (currMB->cbp, i16mode);
    }
    SetMotionVectorsMB (currMB, bframe);
   
    //===== check for SKIP mode =====
    if ((img->type==P_SLICE || img->type==SP_SLICE) && best_mode==1 && currMB->cbp==0 &&
      enc_picture->ref_idx[LIST_0][img->block_x][img->block_y]==0 &&
      enc_picture->mv[LIST_0][img->block_x][img->block_y][0]==allmvs[0][0][0][0][0][0] &&
      enc_picture->mv[LIST_0][img->block_x][img->block_y][1]==allmvs[0][0][0][0][0][1]               )
    {
      currMB->mb_type=currMB->b8mode[0]=currMB->b8mode[1]=currMB->b8mode[2]=currMB->b8mode[3]=0;
    }
   
    if(img->MbaffFrameFlag)
      set_mbaff_parameters();
}

// Rate control
if(input->RCEnable)
{  
    if(img->type==P_SLICE)
    {
      img->MADofMB[img->current_mb_nr] = calc_MAD();
     
      if(input->basicunit<img->Frame_Total_Number_MB)
      {
        img->TotalMADBasicUnit +=img->MADofMB[img->current_mb_nr];
       
        /* delta_qp is present only for non-skipped macroblocks*/
        if ((cbp!=0 || best_mode==I16MB))
          currMB->prev_cbp = 1;
        else
        {
          img->qp -= currMB->delta_qp;
          currMB->delta_qp = 0;
          currMB->qp = img->qp;
          currMB->prev_cbp = 0;
        }
        /* When MBAFF is used, delta_qp is only present for the first non-skipped macroblock of each
        macroblock pair*/
        if (input->MbInterlace)
        {
          if(!currMB->mb_field)
          {
            DELTA_QP = currMB->delta_qp;
            QP      = currMB->qp;
          }
          else
          {
            DELTA_QP2 = currMB->delta_qp;
            QP2      = currMB->qp;
          }
        }      
      }
    }
}

   
if(input->rdopt)
    rdopt->min_rdcost = min_rdcost;
else
    rdopt->min_rdcost = min_cost;

if(img->MbaffFrameFlag)
{
    if (img->current_mb_nr%2) //bottom
    {
      if ((currMB->mb_type ? 0:((img->type == B_SLICE) ? !currMB->cbp:1)) // bottom is skip
        &&(prevMB->mb_type ? 0:((img->type == B_SLICE) ? !prevMB->cbp:1))) // top is skip
      {
        if (!(field_flag_inference() == curr_mb_field))
        {
          rdopt->min_rdcost = 1e30; // don't allow coding of an MB pair as skip if wrong inference
        }
      }
    }
}

//===== Decide if this MB will restrict the reference frames =====
if (input->RestrictRef==1)
{
    if (input->rdopt==1)
    {
      refresh_map[2*img->mb_y ][2*img->mb_x ] = (intra ? 1 : 0);
      refresh_map[2*img->mb_y ][2*img->mb_x+1] = (intra ? 1 : 0);
      refresh_map[2*img->mb_y+1][2*img->mb_x ] = (intra ? 1 : 0);
      refresh_map[2*img->mb_y+1][2*img->mb_x+1] = (intra ? 1 : 0);
    }
    else if (input->rdopt==2)
    {
      refresh_map[2*img->mb_y ][2*img->mb_x ] = (intra1==0 && (currMB->mb_type==I16MB || currMB->mb_type==I4MB) ? 1 : 0);
      refresh_map[2*img->mb_y ][2*img->mb_x+1] = (intra1==0 && (currMB->mb_type==I16MB || currMB->mb_type==I4MB) ? 1 : 0);
      refresh_map[2*img->mb_y+1][2*img->mb_x ] = (intra1==0 && (currMB->mb_type==I16MB || currMB->mb_type==I4MB) ? 1 : 0);
      refresh_map[2*img->mb_y+1][2*img->mb_x+1] = (intra1==0 && (currMB->mb_type==I16MB || currMB->mb_type==I4MB) ? 1 : 0);
    }
}
else if (input->RestrictRef==2)
{
    refresh_map[2*img->mb_y ][2*img->mb_x ] = (currMB->mb_type==I16MB || currMB->mb_type==I4MB ? 1 : 0);
    refresh_map[2*img->mb_y ][2*img->mb_x+1] = (currMB->mb_type==I16MB || currMB->mb_type==I4MB ? 1 : 0);
    refresh_map[2*img->mb_y+1][2*img->mb_x ] = (currMB->mb_type==I16MB || currMB->mb_type==I4MB ? 1 : 0);
    refresh_map[2*img->mb_y+1][2*img->mb_x+1] = (currMB->mb_type==I16MB || currMB->mb_type==I4MB ? 1 : 0);
}

if(input->FMEnable)
    skip_intrabk_SAD(best_mode, listXsize[LIST_0+list_offset]);
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/455801.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Django简介以及安装

Django简介 1. 认识Django Django是一个高级的Python Web框架&#xff0c;它鼓励快速开发和清洁&#xff0c;务实的设计。由经验丰富的开发人员构建&#xff0c;它负责Web开发的许多麻烦&#xff0c;因此您可以专注于编写应用程序&#xff0c;而无需重新创建轮子。它是免费的…

python基础笔试面试题_python基础面试常见题

Python是目前市面上&#xff0c;我个人认为是最简洁、最优雅、最有前途、最全能的编程语言&#xff0c;没有之一。 2、通过什么途径学习的Python&#xff1f; 通过自学&#xff0c;包括网上查看一些视频&#xff0c;购买一些相关专业的书籍。 3、Python和Java、PHP、C、C#、C等…

django-rest-swagger显示接口备注内容

Swagger是一個API開發者的工具框架&#xff0c;用於生成、描述、調用和可視化RESTful風格的Web服務。總體目標是使客戶端和文件系統服務器以同樣的速度來更新&#xff0c;方法&#xff0c;參數和模型緊密集成到服務器端的代碼中&#xff0c;允許API始終保持同步。 在使用 djan…

安全和连接是IoT联网设备2大挑战

IoT正在推动500亿个联网设备在未来10年内从工业、零售、智能照明、智慧城市、汽车、农业、可穿戴设备、智能建筑、医疗市场涌现出来&#xff0c;ARM处理器部门市场营销总监Ian Smythe表示&#xff1a;“到2020年&#xff0c;消费电子和健康、智慧城市和物流、汽车和运输领域的I…

windows下部署免费ssl证书(letsencrypt)

随着网络的发展&#xff0c;网络安全也越来越重要&#xff0c;对于网站来说&#xff0c;从Http升级到https也是我们要做的首要事情。要实现https&#xff0c;首先我们需要申请一张SSL证书&#xff0c;这篇文章我主要介绍下边这几个方面&#xff1a; 1. SSL简单介绍 2. 免费Lete…

Django之URLconf路由

URLconf路由 一个干净优雅的URL方案是高质量Web应用程序中的一个重要细节。 Django可以让你设计URL&#xff0c;无论你想要什么&#xff0c;没有框架限制。 要为应用程序设计URL&#xff0c;您可以非正式地创建一个名为URLconf&#xff08;URL配置&#xff09;的Python模块。…

python中什么是关键字参数_如何使用python语言中函数的关键字参数的用法

一般情况下&#xff0c;在调用函数时&#xff0c;使用的是位置参数&#xff0c;即是按照参数的位置来传值&#xff1b;关键字参数是按照定义函数传入的参数名称来传值的。那么&#xff0c;关键字参数怎么使用&#xff1f;工具/原料 python pycharm 截图工具 WPS 方法/步骤 1 打…

HTML块级元素

在HTML5出现之前&#xff0c;人们一般把元素分为块级、内联和内联块元素。本文将详细介绍HTML块级元素h标题(Heading)元素有六个不同的级别&#xff0c;<h1>是最高级的&#xff0c;而<h6>则是最低的。一个标题元素能简要描述该节的主题从<h1>到<h6>&am…

【SSL】HTTPS配置全过程

服务器配置https协议 HTTPS&#xff0c;是以安全为目标的HTTP通道&#xff0c;简单讲是HTTP的安全版。即HTTP下加入SSL层&#xff0c;HTTPS的安全基础是SSL&#xff0c;因此加密的详细内容就需要SSL。 配置HTTPS就需要证书&#xff0c;关于证书方面不做过多解释&#xff0c;只…

iOS开发UI篇—懒载入

iOS开发UI篇—懒载入 1.懒载入基本 懒载入——也称为延迟载入&#xff0c;即在须要的时候才载入&#xff08;效率低&#xff0c;占用内存小&#xff09;。所谓懒载入&#xff0c;写的是其get方法. 注意&#xff1a;假设是懒载入的话则一定要注意先推断是否已经有了。假设没有那…

python之虚拟环境

Virtualenv(虚拟环境) VirtualEnv用于在一台机器上创建多个独立的Python虚拟运行环境&#xff0c;多个Python环境相互独立&#xff0c;互不影响.这样有很多优点,宝宝们要记住哦,比如: 在没有权限的情况下安装新套件 不同应用可以使用不同的套件版本 套件升级不影响其他应用 …

【解决】subprocess.CalledProcessError: Command ‘(‘lsb_release‘, ‘-a‘)‘ returned non-zero exit status 127

pip list 报错 Traceback (most recent call last):File "/home/sensetime/.pyenv/versions/3.6.5/bin/pip", line 11, in <module>sys.exit(main())File "/home/sensetime/.pyenv/versions/3.6.5/lib/python3.6/site-packages/pip/_internal/cli/main.p…

输出四位完全平方数_完全平方数中的规律

PS&#xff1a;很近之前自己收集的资料一个正整数如果是另一个整数的完全平方&#xff0c;那么我们就称这个数为完全平方数&#xff0c;也叫做平方数。如&#xff1a;0&#xff0c;1&#xff0c;4&#xff0c;9&#xff0c;16&#xff0c;25&#xff0c;36&#xff0c;49&#…

RTP格式图 NNEXB格式和RTP格式

Dove(12337127) 10:15:45我看JM代码里面有些疑问 看好多地方都出现了ANNEXB 时空互换(178316135) 10:16:08h264的2种码流编码格式Dove(12337127) 10:16:19我就不太理解是什么意思 刚才翻标准看见了 刚准备认真看看 Dove(12337127) 10:16:29annexb rtp 是么&#x…

第一阶段冲刺第二天

昨天把以前写过的Java普通用户类和订单类看了看&#xff0c;添加了一些变量 看了一些其他网页的代码 今天继续写关于收藏部分的代码 遇到的困难&#xff1a;还是没有什么头绪&#xff0c;做不到真正的实现转载于:https://www.cnblogs.com/lzxw/p/6800311.html

为企业提供本地销售人员的Universal Avenue获1000万美元A轮融资

为各类B2B企业提供本地销售人员的瑞典初创企业Universal Avenue近日获得了1000万美元的A轮融资。此轮融资由Eight Roads&#xff08;富达国际的投资机构&#xff09;领投&#xff0c;原有投资者Northzone和MOOR跟投&#xff0c;加上2015年获得的500万美元种子轮融资&#xff0c…

Python02期预科课程笔记索引

Python index day01 Python简介 Python发展历程 Python安装以及版本检测PyCharm的安装和破解 day02 Python注释及语句分类 Python命令方式和关键字Python中的变量Python的数据类型PyCharm中的快捷键 day03 Python数据类型转换Python中的运算和运算符Python流程控制 day0…

【Linux分享】Linux常用命令+教程分享

今天分享分为两部分 :) PART01 Linux常用命令分享/ PART02 关于BD面试经验分享 30mins Linux Command: PART 1 你本可以张口就来..... 本篇内容分享的宗旨: 拿下Linux面试 别面试的时候呆呆地说个ls了&#x1f691; 本篇分享详细地介绍了常用Linux指令的功能、语法、参…

万能无线鼠标对码软件_400元就能买ROG无线游戏鼠标,ROG影刃2无线版使用体验...

影刃2是ROG刚刚推出的一款新产品&#xff0c;定位入门游戏玩家。目前市面上定位入门游戏玩家的无线鼠标真不多&#xff0c;400块以内的预算想要选购一款合适的无线游戏鼠标&#xff0c;选择其实非常有限。 就ROG产品线而言&#xff0c;烈刃2的价格到了700块钱&#xff1b;罗技G…

[转帖]H.264 RTP payload 格式(有效载荷)

1. 网络抽象层单元类型 (NALU)NALU 头由一个字节组成, 它的语法如下:---------------|0|1|2|3|4|5|6|7|--------|F|NRI| Type |---------------F: 1 个比特.forbidden_zero_bit. 在 H.264 规范中规定了这一位必须为 0.NRI: 2 个比特.nal_ref_idc. 取 00 ~ 11, 似乎指示这个 NAL…