⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ippvideoencodermpeg4_misc.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        mQuantPVOP = par->quantPVOP;        mQuantBVOP = par->quantBVOP;    }    // setup VOP time    mVOPtime = mSyncTime = mSyncTimeB = 0;    // calc length of macroblock_number code    i = mNumMacroBlockPerVOP - 1;    mMBNlength = 0;    do {        i >>= 1;        mMBNlength ++;    } while (i);    return MP4_STS_NOERR;}int ippVideoEncoderMPEG4::SetFrameBasicSpriteWarpCoeffs(int *du, int *dv, int bcf){    int  i;    if (!mIsInit)        return MP4_STS_ERR_NOTINIT;    for (i = 0; i < VOL.no_of_sprite_warping_points; i ++) {        if (du[i] < -16383 || du[i] > 16383 || dv[i] < -16383 || dv[i] > 16383) {            ErrorMessage(VM_STRING("warping_mv_code must be between -16383 and 16383"));            return MP4_STS_ERR_PARAM;        }        VOP.warping_mv_code_du[i] = du[i];        VOP.warping_mv_code_dv[i] = dv[i];    }    if (VOL.sprite_brightness_change) {        if (bcf < -112 || bcf > 1648) {            ErrorMessage(VM_STRING("brightness_change_factor must be between -112 and 1648"));            return MP4_STS_ERR_PARAM;        }        VOP.brightness_change_factor = bcf;    }    return MP4_STS_NOERR;}void ippVideoEncoderMPEG4::ErrorMessage(const vm_char *msg){    vm_debug_trace(4, __VM_STRING("MPEG-4 encoder error: "));    vm_debug_trace(4, msg);    vm_debug_trace(4, __VM_STRING("\n"));}static void mp4_ExpandFrameReplicate(Ipp8u *pSrcDstPlane, int frameWidth, int frameHeight, int expandPels, int step){    Ipp8u   *pDst1, *pDst2, *pSrc1, *pSrc2;    int     i, j;    Ipp32u  t1, t2;    pDst1 = pSrcDstPlane + step * expandPels;    pDst2 = pDst1 + frameWidth + expandPels;    if (expandPels == 8) {        for (i = 0; i < frameHeight; i ++) {            t1 = pDst1[8] + (pDst1[8] << 8);            t2 = pDst2[-1] + (pDst2[-1] << 8);            t1 = (t1 << 16) + t1;            t2 = (t2 << 16) + t2;            ((Ipp32u*)pDst1)[0] = t1;            ((Ipp32u*)pDst1)[1] = t1;            ((Ipp32u*)pDst2)[0] = t2;            ((Ipp32u*)pDst2)[1] = t2;            pDst1 += step;            pDst2 += step;        }    } else if (expandPels == 16) {        for (i = 0; i < frameHeight; i ++) {            t1 = pDst1[16] + (pDst1[16] << 8);            t2 = pDst2[-1] + (pDst2[-1] << 8);            t1 = (t1 << 16) + t1;            t2 = (t2 << 16) + t2;            ((Ipp32u*)pDst1)[0] = t1;            ((Ipp32u*)pDst1)[1] = t1;            ((Ipp32u*)pDst1)[2] = t1;            ((Ipp32u*)pDst1)[3] = t1;            ((Ipp32u*)pDst2)[0] = t2;            ((Ipp32u*)pDst2)[1] = t2;            ((Ipp32u*)pDst2)[2] = t2;            ((Ipp32u*)pDst2)[3] = t2;            pDst1 += step;            pDst2 += step;        }    } else {        for (i = 0; i < frameHeight; i ++) {            ippsSet_8u(pDst1[expandPels], pDst1, expandPels);            ippsSet_8u(pDst2[-1], pDst2, expandPels);            pDst1 += step;            pDst2 += step;        }    }    pDst1 = pSrcDstPlane;    pSrc1 = pSrcDstPlane + expandPels * step;    pDst2 = pSrc1 + frameHeight * step;    pSrc2 = pDst2 - step;    j = frameWidth + 2 * expandPels;    for (i = 0; i < expandPels; i ++) {        ippsCopy_8u(pSrc1, pDst1, j);        ippsCopy_8u(pSrc2, pDst2, j);        pDst1 += step;        pDst2 += step;    }}/*//  padding VOP (for not complete blocks padd by//      0 for DivX(tm) 5.0 AVI streams//      128 for QuickTime(tm) MP4 streams//      replication for other*/void ippVideoEncoderMPEG4::ExpandFrame(Ipp8u *pY, Ipp8u *pU, Ipp8u *pV){    if (mExpandSize) {        int  wL, hL, wC, hC, es = (mExpandSize + 1) >> 1, i;        wL = mSourceWidth;        hL = mSourceHeight;        wC = mSourceWidth >> 1;        hC = mSourceHeight >> 1;        if ((mSourceWidth & 15 || mSourceHeight & 15) && mPadType) {            Ipp8u     pad = (Ipp8u)(mPadType == 1 ? 128 : 0);            if (mSourceWidth & 15) {                Ipp8u *p;                // pad one col                p = pY + mSourceWidth;                for (i = 0; i < mSourceHeight; i ++) {                    *p = pad;                    p += mStepLuma;                }                p = pU + (mSourceWidth >> 1);                for (i = 0; i < mSourceHeight >> 1; i ++) {                    *p = pad;                    p += mStepChroma;                }                p = pV + (mSourceWidth >> 1);                for (i = 0; i < mSourceHeight >> 1; i ++) {                    *p = pad;                    p += mStepChroma;                }                wL ++;                wC ++;            }            if (mSourceHeight & 15) {                // pad one row                ippsSet_8u(pad, pY + mStepLuma * mSourceHeight, mSourceWidth);                ippsSet_8u(pad, pU + mStepChroma * (mSourceHeight >> 1), mSourceWidth >> 1);                ippsSet_8u(pad, pV + mStepChroma * (mSourceHeight >> 1), mSourceWidth >> 1);                hL ++;                hC ++;            }        }        mp4_ExpandFrameReplicate(pY-mExpandSize*mStepLuma-mExpandSize, wL, hL, mExpandSize, mStepLuma);        mp4_ExpandFrameReplicate(pU-es*mStepChroma-es, wC, hC, es, mStepChroma);        mp4_ExpandFrameReplicate(pV-es*mStepChroma-es, wC, hC, es, mStepChroma);/*        if (VOL.interlaced) {            Ipp8u *psb, *pdb, *pst, *pdt;            // pad fields            psb = pY + mStepLuma - mExpandSize;            pdb = psb - mStepLuma - mStepLuma;            pst = pY + mStepLuma * (mSourceHeight - 2) - mExpandSize;            pdt = pst + mStepLuma + mStepLuma;            for (i = 0; i < 8; i ++) {                ippsCopy_8u(psb, pdb, mStepLuma);                pdb -= mStepLuma + mStepLuma;                ippsCopy_8u(pst, pdt, mStepLuma);                pdt += mStepLuma + mStepLuma;            }        }*/    }}int ippVideoEncoderMPEG4::GetFrameWriteInfo(Ipp8u **pY, Ipp8u **pU, Ipp8u **pV, int *stepLuma, int *stepChroma){    if (!mIsInit)        return MP4_STS_ERR_NOTINIT;    *pY = mFrameC->pY;    *pU = mFrameC->pU;    *pV = mFrameC->pV;    *stepLuma = mStepLuma;    *stepChroma = mStepChroma;    return MP4_STS_NOERR;}void ippVideoEncoderMPEG4::PostFrameRC(){    int    bpfExpected, delay, quant, coding_type, bpfEncoded, qa;    bpfEncoded = mBitsEncodedFrame;    mBitsDesiredTotal += mBitsDesiredFrame;    coding_type = VOL.short_video_header ? VOP.picture_coding_type : VOP.vop_coding_type;    delay = (int)(mBitsDesiredTotal - mBitsEncodedTotal);    if (coding_type == MP4_VOP_TYPE_I) {        bpfExpected = (mBitsDesiredFrame << 2) + (delay >> 1);        mp4_ClipL(bpfExpected, mBitsDesiredFrame * 7 >> 3);    } else if (coding_type == MP4_VOP_TYPE_B) {        bpfExpected = (mBitsDesiredFrame / 3) + (delay >> 2);        mp4_Clip(bpfExpected, mBitsDesiredFrame / 4, mBitsDesiredFrame * 3 >> 2);    } else { // P- and S(GMC)-VOP        bpfExpected = mBitsDesiredFrame + (delay >> 1);        mp4_Clip(bpfExpected, mBitsDesiredFrame >> 1, mBitsDesiredFrame << 1);    }    quant = (coding_type == MP4_VOP_TYPE_I) ? mQuantIVOP : (coding_type == MP4_VOP_TYPE_B) ? mQuantBVOP : mQuantPVOP;    mRCqs += quant;    mRCqh ++; if (mRCqh >= RCBS) mRCqh = 0;    if (mRCbf) {        mRCqs -= mRCqb[mRCqh];        qa = (mRCqs + RCBS/2) / RCBS;    } else {        if (mRCqh == RCBS-1)            mRCbf = 1;        qa = (mRCqs + ((mRCqh + 1) >> 1)) / (mRCqh + 1);    }    mRCqb[mRCqh] = (Ipp8u)quant;    if (mp4_Abs(bpfEncoded - bpfExpected) > (bpfExpected >> 4)) {        if (bpfEncoded > bpfExpected) {            quant ++;            //if (bpfEncoded > 4 * bpfExpected)            //    quant ++;            int cq = IPP_MIN(31, qa + 4);            mp4_ClipR(quant, cq);        } else if (bpfEncoded < bpfExpected) {            quant --;            //if (bpfEncoded * 4 < bpfExpected)            //    quant --;            int cq = IPP_MAX(2, qa - 4);            mp4_ClipL(quant, cq);        }    }    if (VOL.short_video_header && quant < 3)        quant = 3;    if (coding_type == MP4_VOP_TYPE_B) {        //if (quant <= mQuantPVOP + 1) {        //   quant = mQuantPVOP + 2;        //   mp4_ClipR(quant, 31);        //}        quant = mQuantPVOP * 3 >> 1;        mp4_Clip(quant, 4, 31);        mQuantBVOP = quant;    } else {        mQuantIVOP = mQuantPVOP = quant;    }}void ippVideoEncoderMPEG4::InitMBRC(){    int bb, bpf;    bb = (int)(mBitsDesiredTotal - mBitsEncodedTotal);    if (VOP.vop_coding_type == MP4_VOP_TYPE_I) {        bpf = mBitsDesiredFrame * 6;        bpf += mIVOPdist < 30 ? (bb * 2 / mIVOPdist) : (bb >> 4);        mp4_Clip(bpf, mBitsDesiredFrame, mBitRate >> 1);    } else {        bpf = mBitsDesiredFrame;        bpf += mIVOPdist < 30 ? (bb * 2 / mIVOPdist) : (bb >> 4);        mp4_Clip(bpf, mBitsDesiredFrame >> 1, mBitRate >> 2);    }    mMBRC.bpuAvg = (bpf + (mNumMacroBlockPerVOP >> 1)) / mNumMacroBlockPerVOP;    mMBRC.bpsAvg = mMBRC.bpsEnc = 0;    mMBRC.sQuant = VOP.vop_quant;    //cBS.GetPos(&mMBRC.sBitPtr, &mMBRC.sBitOff);    mMBRC.sBitPtr = cBS.GetPtr();  mMBRC.sBitOff = 0;    mBitsDesiredTotal += mBitsDesiredFrame;}void ippVideoEncoderMPEG4::UpdateMBRC(int *dquant){    int    bpuEnc, bpuExp, delay, quant=0;    bpuEnc = mp4_GetNumBits(mMBRC.sBitPtr, mMBRC.sBitOff, cBS.mPtr, cBS.mBitOff);    cBS.GetPos(&mMBRC.sBitPtr, &mMBRC.sBitOff);    mMBRC.bpsAvg += mMBRC.bpuAvg;    mMBRC.bpsEnc += bpuEnc;    delay = mMBRC.bpsAvg - mMBRC.bpsEnc;    bpuExp = mMBRC.bpuAvg + (delay >> 1);    mp4_Clip(bpuExp, mMBRC.bpuAvg >> 1, mMBRC.bpuAvg << 1);    if (mp4_Abs(bpuEnc - bpuExp) > (bpuExp >> 4)) {        quant = mMBRC.sQuant;        if (bpuEnc > bpuExp) {            if (VOP.vop_coding_type != MP4_VOP_TYPE_B) {                quant ++;                mp4_ClipR(quant, 31);            } else {                if (quant + 2 <= 31)                    quant += 2;            }        } else if (bpuEnc < bpuExp) {            if (VOP.vop_coding_type != MP4_VOP_TYPE_B) {                quant --;                mp4_ClipL(quant, 2);            } else {                if (quant - 2 >= 2)                    quant -= 2;            }        }        if (VOL.short_video_header)            mp4_ClipL(quant, 3);        *dquant = quant - mMBRC.sQuant;        mMBRC.sQuant = quant;    } else        *dquant = 0;}void ippVideoEncoderMPEG4::CloseMBRC(){    VOP.vop_quant = (mQuantSum + (mNumMacroBlockPerVOP >> 1)) / mNumMacroBlockPerVOP;    if (VOP.vop_coding_type == MP4_VOP_TYPE_I)        mQuantIVOP = VOP.vop_quant;    else if (VOP.vop_coding_type != MP4_VOP_TYPE_B) {        mQuantPVOP = VOP.vop_quant;    } else {        mQuantBVOP = VOP.vop_quant;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -