[x265] [PATCH] cuTree: integrated CuTree into RateControl and Added b-references into RC
Aarthi Priya Thirumalai
aarthi at multicorewareinc.com
Mon Dec 2 19:35:27 CET 2013
On Mon, Dec 2, 2013 at 5:54 PM, Gopu Govindaswamy <gopu at multicorewareinc.com
> wrote:
> # HG changeset patch
> # User Gopu Govindaswamy <gopu at multicorewareinc.com>
> # Date 1385986798 -19800
> # Node ID 8617e8ab6fafd5dea42e63f135f6df02761d5dd6
> # Parent a0f2c87c5f0a27a2f7e6e96af675efc419988d6e
> cuTree: integrated CuTree into RateControl and Added b-references into RC
>
> diff -r a0f2c87c5f0a -r 8617e8ab6faf source/common/common.cpp
> --- a/source/common/common.cpp Mon Dec 02 12:53:59 2013 +0530
> +++ b/source/common/common.cpp Mon Dec 02 17:49:58 2013 +0530
> @@ -398,6 +398,7 @@
> {
> //currently the default
> param->rc.aqMode = X265_AQ_NONE;
> + param->rc.cuTree = 0;
> }
> else if (!strcmp(tune, "ssim"))
> {
> diff -r a0f2c87c5f0a -r 8617e8ab6faf source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cpp Mon Dec 02 12:53:59 2013 +0530
> +++ b/source/encoder/ratecontrol.cpp Mon Dec 02 17:49:58 2013 +0530
> @@ -118,6 +118,7 @@
> if (cfg->param.rc.aqMode)
> {
> pic->m_lowres.qpAqOffset[block_xy] = qp_adj;
> + pic->m_lowres.qpOffset[block_xy] = qp_adj;
> pic->m_lowres.invQscaleFactor[block_xy] =
> x265_exp2fix8(qp_adj);
> block_xy++;
> }
> @@ -141,6 +142,14 @@
> this->cfg = _cfg;
> ncu = (int)((cfg->param.sourceHeight * cfg->param.sourceWidth) /
> pow((int)16, 2.0));
>
> + if (cfg->param.rc.cuTree)
> + {
> + qCompress = 1;
> + cfg->param.rc.pbFactor = 1;
> + }
> + else
> + qCompress = cfg->param.rc.qCompress;
> +
> // validate for cfg->param.rc, maybe it is need to add a function
> like x265_parameters_valiate()
> cfg->param.rc.rfConstant = Clip3((double)-QP_BD_OFFSET, (double)51,
> cfg->param.rc.rfConstant);
> if (cfg->param.rc.rateControlMode == X265_RC_CRF)
> @@ -149,8 +158,8 @@
> cfg->param.rc.bitrate = 0;
>
> double baseCplx = ncu * (cfg->param.bframes ? 120 : 80);
> - double mbtree_offset = 0; // added later
> - rateFactorConstant = pow(baseCplx, 1 - cfg->param.rc.qCompress) /
> + double mbtree_offset = cfg->param.rc.cuTree ? (1.0 -
> cfg->param.rc.qCompress) * 13.5 : 0;
> + rateFactorConstant = pow(baseCplx, 1 - qCompress) /
> qp2qScale(cfg->param.rc.rfConstant + mbtree_offset +
> QP_BD_OFFSET);
> }
>
> @@ -248,7 +257,7 @@
> accumPNorm = .01;
> accumPQp = (ABR_INIT_QP_MIN)*accumPNorm;
> /* estimated ratio that produces a reasonable QP for the first
> I-frame */
> - cplxrSum = .01 * pow(7.0e5, cfg->param.rc.qCompress) * pow(ncu,
> 0.5);
> + cplxrSum = .01 * pow(7.0e5, qCompress) * pow(ncu, 0.5);
> wantedBitsWindow = bitrate * frameDuration;
> }
> else if (cfg->param.rc.rateControlMode == X265_RC_CRF)
> @@ -257,7 +266,7 @@
> accumPNorm = .01;
> accumPQp = ABR_INIT_QP * accumPNorm;
> /* estimated ratio that produces a reasonable QP for the first
> I-frame */
> - cplxrSum = .01 * pow(7.0e5, cfg->param.rc.qCompress) * pow(ncu,
> 0.5);
> + cplxrSum = .01 * pow(7.0e5, qCompress) * pow(ncu, 0.5);
> wantedBitsWindow = bitrate * frameDuration;
> }
>
> @@ -351,9 +360,9 @@
> double q0 = prevRefSlice->getSliceQp();
> double q1 = nextRefSlice->getSliceQp();
>
> - if (prevRefSlice->getSliceType() == B_SLICE &&
> prevRefSlice->isReferenced())
> + if (prevRefSlice->getSliceType() == X265_TYPE_BREF &&
> prevRefSlice->isReferenced())
> q0 -= pbOffset / 2;
> - if (nextRefSlice->getSliceType() == B_SLICE &&
> nextRefSlice->isReferenced())
> + if (nextRefSlice->getSliceType() == X265_TYPE_BREF &&
> nextRefSlice->isReferenced())
>
sliceType = X265_TYPE_BREF = > its already referenced, no need for the &&
condition check for isReferenced()
> q1 -= pbOffset / 2;
> if (i0 && i1)
> q = (q0 + q1) / 2 + ipOffset;
> @@ -453,7 +462,7 @@
> q = Clip3(lqmin, lqmax, q);
> }
> }
> - else if (cfg->param.rc.rateControlMode == X265_RC_CRF &&
> cfg->param.rc.qCompress != 1)
> + else if (cfg->param.rc.rateControlMode == X265_RC_CRF &&
> qCompress != 1)
> {
> q = qp2qScale(ABR_INIT_QP) / fabs(cfg->param.rc.ipFactor);
> }
> @@ -565,7 +574,15 @@
> {
> double q;
>
> - q = pow(rce->blurredComplexity, 1 - cfg->param.rc.qCompress);
> + if (cfg->param.rc.cuTree)
> + {
> + double scale =
> curSlice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale();
> + double units =
> curSlice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick();
> + double timescale = units / scale;
> + q = pow(BASE_FRAME_DURATION / CLIP_DURATION(2 * timescale), 1 -
> cfg->param.rc.qCompress);
> + }
> + else
> + q = pow(rce->blurredComplexity, 1 - cfg->param.rc.qCompress);
>
> // avoid NaN's in the rc_eq
> if (rce->texBits + rce->mvBits == 0)
> diff -r a0f2c87c5f0a -r 8617e8ab6faf source/encoder/ratecontrol.h
> --- a/source/encoder/ratecontrol.h Mon Dec 02 12:53:59 2013 +0530
> +++ b/source/encoder/ratecontrol.h Mon Dec 02 17:49:58 2013 +0530
> @@ -115,6 +115,7 @@
> int64_t totalBits; /* totalbits used for already encoded
> frames */
> double lastRceq;
> int framesDone; /* framesDone keeps track of # of frames
> passed through RateCotrol already */
> + double qCompress;
> RateControl(TEncCfg * _cfg);
>
> // to be called for each frame to process RateControl and set QP
> diff -r a0f2c87c5f0a -r 8617e8ab6faf source/encoder/slicetype.cpp
> --- a/source/encoder/slicetype.cpp Mon Dec 02 12:53:59 2013 +0530
> +++ b/source/encoder/slicetype.cpp Mon Dec 02 17:49:58 2013 +0530
> @@ -1366,7 +1366,7 @@
> }
>
> cuTreeFinish(Frames[lastnonb], averageDuration, lastnonb);
> - if (cfg->param.bBPyramid && bframes > 1 /* &&
> !h->param.rc.i_vbv_buffer_size */)
> + if (cfg->param.bBPyramid && bframes > 1 &&
> !cfg->param.rc.vbvBufferSize)
> cuTreeFinish(Frames[lastnonb + (bframes + 1) / 2],
> averageDuration, 0);
> }
>
> @@ -1464,7 +1464,7 @@
> }
> }
>
> - if(/*h->param.rc.i_vbv_buffer_size &&*/ cfg->param.logLevel &&
> referenced)
> + if(cfg->param.rc.vbvBufferSize && cfg->param.logLevel && referenced)
> cuTreeFinish(Frames[b], averageDuration, b == p1 ? b - p0 : 0);
>
> }
> @@ -1481,7 +1481,8 @@
> * concepts are very similar. */
>
> int cuCount = widthInCU * heightInCU;
> - double strength = 5.0f * (1.0f - cfg->param.rc.qCompress);
> + double strength = 5.0 * (1.0 - cfg->param.rc.qCompress);
> +
> for (int cuIndex = 0; cuIndex < cuCount; cuIndex++)
> {
> int intracost = (Frame->intraCost[cuIndex] *
> Frame->invQscaleFactor[cuIndex] + 128) >> 8;
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20131203/a3e1dcc3/attachment.html>
More information about the x265-devel
mailing list