📄 ippvideoencodermpeg4_vop.cpp
字号:
if (mNumIntraMB > mSceneChangeThreshold) { cBS.Reset(); // not RepeatHeaders and InsertGOV here VOP.vop_coding_type = MP4_VOP_TYPE_I; VOP.vop_quant = mQuantPVOP; EncodeVOP_Header(); EncodeIVOP(); mLastIVOP = mFrameCount; } mSyncTimeB = nt; mIndxBVOP ++; if (mIndxBVOP > 2 + mBVOPdist) mIndxBVOP = 2; // reset Sync Time if (VOP.modulo_time_base != 0) mSyncTime = mVOPtime - VOP.vop_time_increment; ExpandFrame(mFrameC->pY, mFrameC->pU, mFrameC->pV); mp4_Swap(mFrameF, mFrameC); } else { isIVOP = (mFrameCount - mLastIVOP >= mIVOPdist); isBVOP = mFrameCount % (mBVOPdist + 1); if (!isBVOP) { VOP.vop_coded = 1; mFrameC = mFrameB; if (isIVOP) { if (mRepeatHeaders && (mFrameCount > 0)) { EncodeHeader(); } if (mInsertGOV) { GOV.time_code = (int)(mVOPtime / VOL.vop_time_increment_resolution); if (mBVOPdist != 0 && (mFrameCount > 0)) { int secB = (int)((mVOPtime - mBVOPdist * VOL.fixed_vop_time_increment) / VOL.vop_time_increment_resolution); if (secB < GOV.time_code) GOV.time_code = secB; } mSyncTime = (Ipp64s)GOV.time_code * (Ipp64s)VOL.vop_time_increment_resolution; EncodeGOV_Header(); } VOP.vop_coding_type = MP4_VOP_TYPE_I; VOP.vop_quant = mQuantIVOP; nt = (int)(mVOPtime - mSyncTime); VOP.modulo_time_base = nt / VOL.vop_time_increment_resolution; VOP.vop_time_increment = nt % VOL.vop_time_increment_resolution; EncodeVOP_Header(); EncodeIVOP(); mLastIVOP = mFrameCount; } else { VOP.vop_coding_type = (VOL.sprite_enable == MP4_SPRITE_GMC) ? MP4_VOP_TYPE_S : MP4_VOP_TYPE_P; VOP.vop_quant = mQuantPVOP; VOP.vop_fcode_forward = mPVOPfcodeForw; if (VOP.vop_coding_type == MP4_VOP_TYPE_S) FindTransformGMC(); nt = (int)(mVOPtime - mSyncTime); VOP.modulo_time_base = nt / VOL.vop_time_increment_resolution; VOP.vop_time_increment = nt % VOL.vop_time_increment_resolution; EncodeVOP_Header(); if (VOP.vop_coding_type == MP4_VOP_TYPE_P) EncodePVOP(); else EncodeSVOP(); if (mNumIntraMB > mSceneChangeThreshold) { cBS.Reset(); if (mRepeatHeaders && (mFrameCount != 0)) { EncodeHeader(); } if (mInsertGOV) { GOV.time_code = (int)(mVOPtime / VOL.vop_time_increment_resolution); if (mBVOPdist != 0 && (mFrameCount > 0)) { int secB = (int)((mVOPtime - mBVOPdist * VOL.fixed_vop_time_increment) / VOL.vop_time_increment_resolution); if (secB < GOV.time_code) GOV.time_code = secB; } mSyncTime = (Ipp64s)GOV.time_code * (Ipp64s)VOL.vop_time_increment_resolution; EncodeGOV_Header(); } VOP.vop_coding_type = MP4_VOP_TYPE_I; VOP.vop_quant = mQuantPVOP; nt = (int)(mVOPtime - mSyncTime); VOP.modulo_time_base = nt / VOL.vop_time_increment_resolution; VOP.vop_time_increment = nt % VOL.vop_time_increment_resolution; EncodeVOP_Header(); EncodeIVOP(); mLastIVOP = mFrameCount; } } mSyncTimeB = nt; ExpandFrame(mFrameC->pY, mFrameC->pU, mFrameC->pV); // reset Sync Time if (VOP.modulo_time_base != 0) mSyncTime = mVOPtime - VOP.vop_time_increment; } else if (mFrameCount > mBVOPdist) { int bIndx; bIndx = mIndxBVOP + 1; if (bIndx > 2 + mBVOPdist) bIndx = 2; mFrameC = &mFrame[bIndx]; mTRD = mBVOPdist + 1; mTRB = mNumBVOP + 1; VOP.vop_coding_type = MP4_VOP_TYPE_B; VOP.vop_quant = mQuantBVOP; VOP.vop_fcode_forward = mBVOPfcodeForw; VOP.vop_fcode_backward = mBVOPfcodeBack; nt = mSyncTimeB - (mBVOPdist - mNumBVOP) * VOL.fixed_vop_time_increment; VOP.modulo_time_base = nt / VOL.vop_time_increment_resolution; VOP.vop_time_increment = nt % VOL.vop_time_increment_resolution; EncodeVOP_Header(); EncodeBVOP(); } // setup next frame if (isBVOP) { mIndxBVOP ++; if (mIndxBVOP > 2 + mBVOPdist) mIndxBVOP = 2; mNumBVOP ++; if (mNumBVOP == mBVOPdist) { // next frame is not B mNumBVOP = 0; mp4_Swap(mFrameF, mFrameB); mFrameC = mFrameB; } else { // next frame is B mFrameC = &mFrame[mIndxBVOP]; } } else { // next frame is B mFrameC = &mFrame[mIndxBVOP]; } } } if (mFrameCount > mBVOPdist + 1 || !isBVOP) { mBitsEncodedFrame = cBS.GetFullness() << 3; mBitsEncodedTotal += mBitsEncodedFrame; if (mRateControl == 1) PostFrameRC(); if (VOP.vop_coding_type == MP4_VOP_TYPE_I) { VOP.vop_rounding_type = 0; // reset rounding_type for next P-VOP } else if (VOP.vop_coding_type != MP4_VOP_TYPE_B) { if (mRoundingControl) VOP.vop_rounding_type ^= 1; // switch rounding_type } } mVOPtime += VOL.fixed_vop_time_increment; mFrameCount ++; return (mFrameCount > mBVOPdist + 1 || !isBVOP) ? MP4_STS_NOERR : MP4_STS_BUFFERED;}/*int ippVideoEncoderMPEG4::EncodeFrame(int noMoreData, int vop_type, Ipp64s vop_time){ int isIVOP, isBVOP, nt; if (!mIsInit) return MP4_STS_ERR_NOTINIT; if (noMoreData) return MP4_STS_NODATA; if (vop_time < mSyncTime) return MP4_STS_ERR_PARAM; mQuantSum = 0; mPSNR_Y = mPSNR_U = mPSNR_V = 0; mNumIntraMB = 0; mNumNotCodedMB = 0; if (VOL.sprite_enable == MP4_SPRITE_STATIC) { // static sprites VOP.vop_coded = 1; if (mFrameCount == 0 && vop_type == MP4_VOP_TYPE_I) { VOP.vop_coding_type = MP4_VOP_TYPE_I; VOP.vop_quant = mQuantIVOP; EncodeVOP_Header(); EncodeIVOP(); ExpandFrame(mCurrPtrY, mCurrPtrU, mCurrPtrV); mQuantSum = VOP.vop_quant * mNumMacroBlockPerVOP; } else if (mFrameCount > 0 && vop_type != MP4_VOP_TYPE_S) { VOP.vop_coding_type = MP4_VOP_TYPE_S; nt = (int)(vop_time - mSyncTime); VOP.modulo_time_base = nt / VOL.vop_time_increment_resolution; VOP.vop_time_increment = nt % VOL.vop_time_increment_resolution; if (VOP.modulo_time_base != 0) mSyncTime = vop_time - VOP.vop_time_increment; EncodeVOP_Header(); EncodeSVOP(); mQuantSum = 0; } else return MP4_STS_ERR_PARAM; } else if (VOL.short_video_header) { // short_video_header nt = (int)(vop_time - mSyncTime); mSyncTime = vop_time; VOP.temporal_reference = nt / 1001; VOP.vop_coded = 1; if (vop_type == MP4_VOP_TYPE_I) { VOP.vop_coding_type = VOP.picture_coding_type = MP4_VOP_TYPE_I; VOP.vop_quant = mQuantIVOP; EncodeVOPSH_Header(); EncodeIVOPSH(); } else if (vop_type == MP4_VOP_TYPE_P) { VOP.vop_coding_type = VOP.picture_coding_type = MP4_VOP_TYPE_P; VOP.vop_quant = mQuantPVOP; EncodeVOPSH_Header(); EncodePVOPSH(); if (mNumIntraMB > mSceneChangeThreshold) { cBS.Reset(); VOP.vop_coding_type = VOP.picture_coding_type = MP4_VOP_TYPE_I; VOP.vop_quant = mQuantIVOP; EncodeVOPSH_Header(); EncodeIVOPSH(); } } else return MP4_STS_ERR_PARAM; mp4_Swap(mForwPtrY, mCurrPtrY); mp4_Swap(mForwPtrU, mCurrPtrU); mp4_Swap(mForwPtrV, mCurrPtrV); } else { VOP.vop_coded = 1; if (vop_type == MP4_VOP_TYPE_I) { if (mRepeatHeaders && (mFrameCount != 0)) { EncodeHeader(); } if (mInsertGOV) { GOV.time_code = (int)(vop_time / VOL.vop_time_increment_resolution); mSyncTime = (Ipp64s)GOV.time_code * (Ipp64s)VOL.vop_time_increment_resolution; EncodeGOV_Header(); } VOP.vop_coding_type = MP4_VOP_TYPE_I; VOP.vop_quant = mQuantIVOP; nt = (int)(vop_time - mSyncTime); VOP.modulo_time_base = nt / VOL.vop_time_increment_resolution; VOP.vop_time_increment = nt % VOL.vop_time_increment_resolution; EncodeVOP_Header(); EncodeIVOP(); mSyncTimeB = nt; } else if (vop_type == MP4_VOP_TYPE_P || ((VOL.sprite_enable == MP4_SPRITE_GMC) && (vop_type == MP4_VOP_TYPE_S))) { VOP.vop_coding_type = vop_type; VOP.vop_quant = mQuantPVOP; VOP.vop_fcode_forward = mPVOPfcodeForw; if (VOP.vop_coding_type == MP4_VOP_TYPE_S) FindTransformGMC(); nt = (int)(vop_time - mSyncTime); VOP.modulo_time_base = nt / VOL.vop_time_increment_resolution; VOP.vop_time_increment = nt % VOL.vop_time_increment_resolution; EncodeVOP_Header(); if (VOP.vop_coding_type == MP4_VOP_TYPE_P) EncodePVOP(); else EncodeSVOP(); if (mNumIntraMB > mSceneChangeThreshold) { cBS.Reset(); if (mRepeatHeaders && (mFrameCount != 0)) { EncodeHeader(); } if (mInsertGOV) { GOV.time_code = (int)(vop_time / VOL.vop_time_increment_resolution); mSyncTime = (Ipp64s)GOV.time_code * (Ipp64s)VOL.vop_time_increment_resolution; EncodeGOV_Header(); } VOP.vop_coding_type = MP4_VOP_TYPE_I; VOP.vop_quant = mQuantPVOP; nt = (int)(vop_time - mSyncTime); VOP.modulo_time_base = nt / VOL.vop_time_increment_resolution; VOP.vop_time_increment = nt % VOL.vop_time_increment_resolution; EncodeVOP_Header(); EncodeIVOP(); } else if (mNumNotCodedMB >= mNumMacroBlockPerVOP) { VOP.vop_coded = 0; cBS.Reset(); EncodeVOP_Header(); EncodeStuffingBitsAlign(); } mSyncTimeB = nt; } else if (vop_type == MP4_VOP_TYPE_B) { //mTRD = mBVOPdist + 1; //mTRB = mNumBVOP + 1; VOP.vop_coding_type = MP4_VOP_TYPE_B; VOP.vop_quant = mQuantBVOP; VOP.vop_fcode_forward = mBVOPfcodeForw; VOP.vop_fcode_backward = mBVOPfcodeBack; //nt = mSyncTimeB - (mBVOPdist - mNumBVOP) * VOL.fixed_vop_time_increment; VOP.modulo_time_base = nt / VOL.vop_time_increment_resolution; VOP.vop_time_increment = nt % VOL.vop_time_increment_resolution; EncodeVOP_Header(); // if ref in the future is not coded, these B are not coded also if (VOP.vop_coded) EncodeBVOP(); } else return MP4_STS_ERR_PARAM; if (vop_type != MP4_VOP_TYPE_B) { ExpandFrame(mCurrPtrY, mCurrPtrU, mCurrPtrV); mp4_Swap(mForwPtrY, mCurrPtrY); mp4_Swap(mForwPtrU, mCurrPtrU); mp4_Swap(mForwPtrV, mCurrPtrV); if (VOP.modulo_time_base != 0) mSyncTime = vop_time - VOP.vop_time_increment; } } mBitsEncodedFrame = cBS.GetFullness() << 3; mBitsEncodedTotal += mBitsEncodedFrame; if (mRateControl == 1) PostFrameRC(); if (VOP.vop_coding_type == MP4_VOP_TYPE_I) { VOP.vop_rounding_type = 0; // reset rounding_type for next P-VOP } else if (VOP.vop_coding_type != MP4_VOP_TYPE_B) { if (mRoundingControl) VOP.vop_rounding_type ^= 1; // switch rounding_type } mFrameCount ++; return MP4_STS_NOERR;}*/inline void ippVideoEncoderMPEG4::MergeBuffersDP(int nBits_1, int nBits_2){ // merge buffer with dp_buff_1 ippsCopy_1u(mBuffer_1, 0, cBS.mPtr, cBS.mBitOff, nBits_1); cBS.mPtr += (cBS.mBitOff + nBits_1) >> 3; cBS.mBitOff = (cBS.mBitOff + nBits_1) & 7; // merge buffer with dp_buff_2 ippsCopy_1u(mBuffer_2, 0, cBS.mPtr, cBS.mBitOff, nBits_2); cBS.mPtr += (cBS.mBitOff + nBits_2) >> 3; cBS.mBitOff = (cBS.mBitOff + nBits_2) & 7;}inline void ippVideoEncoderMPEG4::EncodeDquant(int dquant){ if (dquant != -2) cBS.PutBits(dquant + 1, 2); else cBS.PutBits(1, 2);}// used for short_viseo_headervoid ippVideoEncoderMPEG4::PredictMV(mp4_MacroBlock *MBcurr, int i, int j, IppMotionVector *mvPred){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -