HEVC代码学习10:实现全局使用最小CU划分

来源:互联网 发布:卧龙大数据招聘 编辑:程序博客网 时间:2024/06/14 08:15

今天算是来进行一次练手,实现全局使用最小CU和PU划分进行编码。

HEVC中,支持CU最大尺寸为64x64,最小为16x16,在代码中在xCompressCU中进行CU的划分。首先输入的CU为最大尺寸,由cfg文件中的MaxCUWidth和MaxCUHeight指定,计算各种划分模式的cost,通过xCheckBestMode选择最优模式进行划分,迭代处理,直到达到最大深度结束。
因此,我们可以从xCheckBestMode入手来进行修改,实现全局使用最小CU。可以看到xCheckBestMode对当前划分模式的cost和之前找出的最优模式的cost进行了比较,选择小的作为最优模式。我们可以将其直接删掉,即当前划分永远是最优模式,直到达到最大深度结束。

Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth DEBUG_STRING_FN_DECLARE(sParent) DEBUG_STRING_FN_DECLARE(sTest) DEBUG_STRING_PASS_INTO(Bool bAddSizeInfo) ){  //if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) //比较cost修改最优CU模式  {    TComYuv* pcYuv;    // Change Information data    TComDataCU* pcCU = rpcBestCU;    rpcBestCU = rpcTempCU;    rpcTempCU = pcCU;    // Change Prediction data    pcYuv = m_ppcPredYuvBest[uiDepth];    m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth];    m_ppcPredYuvTemp[uiDepth] = pcYuv;    // Change Reconstruction data    pcYuv = m_ppcRecoYuvBest[uiDepth];    m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth];    m_ppcRecoYuvTemp[uiDepth] = pcYuv;    pcYuv = NULL;    pcCU  = NULL;    // store temp best CI for next CU coding    m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);#if DEBUG_STRING    DEBUG_STRING_SWAP(sParent, sTest)    const PredMode predMode=rpcBestCU->getPredictionMode(0);    if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo)    {      std::stringstream ss(stringstream::out);      ss <<"###: " << (predMode==MODE_INTRA?"Intra   ":"Inter   ") << partSizeToString[rpcBestCU->getPartitionSize(0)] << " CU at " << rpcBestCU->getCUPelX() << ", " << rpcBestCU->getCUPelY() << " width=" << UInt(rpcBestCU->getWidth(0)) << std::endl;      sParent+=ss.str();    }#endif  }}

这样就可以使CU不断进行划分直到划分为最小CU为止,实现了全局使用最小CU划分。划分完成后效果如图,最后码流的所有CU均为最小尺寸8x8。
这里写图片描述

原创粉丝点击