HEVC中的运动估计采用的方法:
1、小范围内全搜索(主要用于B帧,第二次遍历计算出较小cost的MV)
2、大范围内菱形搜索(TZSearch)
全搜索:
1、设置好搜索范围,获取当前PU在参考帧重建帧中的位置,获取重建帧的步幅(包含padding)
2、遍历完范围内的所有整数点,逐像素作差得到SAD,获取编码运动矢量的bit数,加在一起形成cost,如果当前SAD比之前最好的SAD小,那么将当前运动矢量x,y赋给rcMV,cost赋给ruiCost
/*
基于当前最优MVP做运动估计:
Input:
1、当前CU
2、当前原始图像的Yuv数据(对应CU大小)
3、当前PU的索引
4、参考图像列表
5、当前参考帧最优MVP(cMvPred[iRefList][iRefIdxTemp])
6、参考帧索引
7、cMvTemp[iRefList][iRefIdxTemp]的引用,对当前参考帧最优MV会存在这里
8、编码所需bit数、RDcost
9、是不是双向运动估计
Output:
1、针对当前帧最优MV
2、针对当前数据编码的bit数以及RDcost大小
*/
Void TEncSearch::xMotionEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPartIdx, RefPicList eRefPicList, TComMv* pcMvPred, Int iRefIdxPred, TComMv& rcMv, UInt& ruiBits, Distortion& ruiCost, Bool bBi )
{
UInt uiPartAddr; //当前PU的起始4x4块的位置
Int iRoiWidth;
Int iRoiHeight;
TComMv cMvHalf, cMvQter; //亚精度、1/4精度
TComMv cMvSrchRngLT; // MV搜索范围
TComMv cMvSrchRngRB;
TComYuv* pcYuv = pcYuvOrg;
assert(eRefPicList < MAX_NUM_REF_LIST_ADAPT_SR && iRefIdxPred<Int(MAX_IDX_ADAPT_SR));
m_iSearchRange = m_aaiAdaptSR[eRefPicList][iRefIdxPred]; //cfg文件中会写明Search Range
Int iSrchRng = ( bBi ? m_bipredSearchRange : m_iSearchRange ); //双向搜索范围:默认为4
TComPattern tmpPattern;
TComPattern* pcPatternKey = &tmpPattern;
Double fWeight = 1.0;
pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
if ( bBi ) // Bipredictive ME,用于第二次对cost较大的参考图像列表再搜索获取最优MV
{
TComYuv* pcYuvOther = &m_acYuvPred[1-(Int)eRefPicList];
pcYuv = &m_cYuvPredTemp;
pcYuvOrg->copyPartToPartYuv( pcYuv, uiPartAddr, iRoiWidth, iRoiHeight ); //先把原始像素值拷贝到当前pcYuv中
pcYuv->removeHighFreq( pcYuvOther, uiPartAddr, iRoiWidth, iRoiHeight, pcCU->getSlice()->getSPS()->getBitDepths()