210 likes | 695 Views
Motion Estimation and Prediction. Present by : fakewen. Motion Estimation and Prediction. 主要分布位置 Tcomprediction.cpp TEncSearch.cpp. predInterSearch. I frame.
E N D
Motion Estimation and Prediction Present by :fakewen
Motion Estimation and Prediction • 主要分布位置 • Tcomprediction.cpp • TEncSearch.cpp
I frame xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp); I frame自己重算motion vector I frame
P frame I frame pcCU->getSlice()->getNoBackPredFlag()==1 P frame enumRefPicList { REF_PIC_LIST_0 = 0, ///< reference list 0 REF_PIC_LIST_1 = 1, ///< reference list 1 #if DCM_COMB_LIST REF_PIC_LIST_C = 2, ///< combined reference list for uni-prediction in B-Slices #endif REF_PIC_LIST_X = 100 ///< special mark }; 如果很smooth且cost不高 ->SKIPMODE 直接拿之前的Motion vector來用 否則再從他的ref framelist裡找
B frame I frame P frame 如果很smooth且cost不高 ->SKIPMODE 直接拿之前的Motion vector來用 否則再從他的ref framelist裡找
Advancedmotionvectorprediction • AMVP • It allows the selectionof the best predictor from • threespatially adjacent motion vectors(a,b,c) • their median • temporalmotion vector. xCheckBestMVP 計算哪種的cost較低
xEstimateMvPredAMVP Step 1 check AMVP mode還有number of motion vector predictor candidates for ( i = 0 ; i < pcAMVPInfo->iN; i++) 算uiBestCost rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; 從裡面選一個最像的當Mvpredict 並記錄cost還有選到的鄰居
Merge xMergeEstimation 算出最小的cost的合併方式 xMergeEstimation(…); UIntuiMRGCost = uiMRGError + m_pcRdCost->getCost( uiMRGBits ); if ( bMergeValid && uiMRGCost < uiMECost) 合併!
xMotionEstimation if ( !m_iFastSearch || bBi ) xPatternSearch xPatternSearchFast Mv初始值用傳入參數 xTZSearch xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost )
xTZSearch range test whether one of PRED_A, PRED_B, PRED_C MV is better start point than Median predictor PK raster search if distance is too big idist raster refinement P.s. 若idist==1 則只考慮上下左右
raster refinement Idist too big
motionCompensation Step 1 Check iPartIdx >= 0 Step 2 eRefPicList!= REF_PIC_LIST_X(B frame) xPredInterLumaBlk xPredInterUni xPredInterBi xPredInterChromaBlk xPredInterLumaBlk_ha xPredInterChromaBlk_ha
motionCompensation Void motionCompensation( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicListeRefPicList = REF_PIC_LIST_X, IntiPartIdx = -1 );初始 Motion Compensation pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight ); iPartIdx >= 0? getPartIndexAndSize For(pcCU->getNumPartInter()) eRefPicList != REF_PIC_LIST_X ? eRefPicList看是I還是Pframe xPredInterUni xPredInterBi
predInterSearch SPS: sequence parameter set predInterSearch pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight);得到這個block的info if (pcCU->getWidth( 0 ) > 8 && iNumPart == 2 && iPartIdx == 0) bTestNormalMC = false; For(iNumPredDir) iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2; P是1B是2 FOR(pcCU->getSlice()->getNumRefIdx(eRefPicList) enumRefPicList { REF_PIC_LIST_0 = 0, ///< reference list 0 REF_PIC_LIST_1 = 1, ///< reference list 1 #if DCM_COMB_LIST REF_PIC_LIST_C = 2, ///< combined reference list for uni-prediction in B-Slices #endif REF_PIC_LIST_X = 100 ///< special mark }; RefPicList標示現在是IPB RefPicListeRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); iRefList//若是Iframe則0 pcCU->getSlice()->getNoBackPredFlag()… 判斷式 pcCU->getSlice()->getNoBackPredFlag() || pcCU->getSlice()->getSPS()->getUseLDC() 判斷式 cMvTemp[1][iRefIdxTemp] = cMvTemp[0][iRefIdxTemp]; SKIPMODE xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp); I frame自己重算motion vector uiCostTemp = uiCostTempL0[pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)]; 用相近的block
predInterSearch(cont.) // set motion cMv[iRefList] = cMvTemp[iRefList][iRefIdxTemp]; iRefIdx[iRefList] = iRefIdxTemp; pcCU->getCUMvField(eRefPicList)->setAllMvField( cMv[iRefList], iRefIdx[iRefList], ePartSize, uiPartAddr, iPartIdx, 0 ); 紀錄最後結果 接著做AMVP xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp]); aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr); aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr); uiBitsTemp+= m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][aaiMvpNum[iRefList][iRefIdxTemp]]; for( UIntui = 0; ui < MRG_MAX_NUM_CANDS; ui++ ) { pcCU->setNeighbourCandIdxSubParts( ui, ucNeighCand[ui], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); } if ( bMergeValid && uiMRGCost < uiMECost ) { // 可以merge且merge cost較低>>set Merge result } else { // set ME result記錄自己的motion estimation }
xEstimateMvPredAMVP if( pcCU->getAMVPMode(uiPartAddr) == AM_NONE || (pcAMVPInfo->iN <= 1 && pcCU->getAMVPMode(uiPartAddr) == AM_EXPL) ) no AMVP mode或是number of motion vector predictor candidates小於一 if (pcCU->getAMVPMode(uiPartAddr) == AM_EXPL && bFilled) 來亂的 for ( i = 0 ; i < pcAMVPInfo->iN; i++) 算uiBestCost rcMvPred = pcAMVPInfo->m_acMvCand[pcCU->getMVPIdx(eRefPicList,uiPartAddr)]; 從裡面選一個最像的當Mvpredict 並記錄cost還有選到的鄰居
xMotionEstimation xSetSearchRange ( pcCU, cMvPred, iSrchRng, cMvSrchRngLT, cMvSrchRngRB); 先設定一下range(Pframe) if ( !m_iFastSearch || bBi ) xPatternSearch xPatternSearchFast Mv初始值用傳入參數 xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost ) rcMv <<= 2; rcMv += (cMvHalf <<= 1); rcMv += cMvQter; 紀錄結果
motionCompensation Void motionCompensation( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicListeRefPicList = REF_PIC_LIST_X, IntiPartIdx = -1 );初始 Motion Compensation pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight ); iPartIdx >= 0? getPartIndexAndSize For(pcCU->getNumPartInter()) eRefPicList != REF_PIC_LIST_X ? eRefPicList看是I還是Pframe xPredInterUni xPredInterBi