[x265] [PATCH 3 of 6] vbv: Add row predictors, rc states for vbv
aarthi at multicorewareinc.com
aarthi at multicorewareinc.com
Fri Feb 21 07:08:38 CET 2014
# HG changeset patch
# User Aarthi Thirumalai
# Date 1392898673 -19800
# Thu Feb 20 17:47:53 2014 +0530
# Node ID 9517ea331f3e87f41c687db11de02cb95ded8756
# Parent cbfb5bc44d6b8b74dc299a1c31bcfaa71dde2865
vbv: Add row predictors, rc states for vbv.
diff -r cbfb5bc44d6b -r 9517ea331f3e source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Thu Feb 20 17:03:38 2014 +0530
+++ b/source/encoder/encoder.cpp Thu Feb 20 17:47:53 2014 +0530
@@ -218,6 +218,7 @@
FrameEncoder *encoder = &m_frameEncoder[encIdx];
double bits;
bits = encoder->m_rce.frameSizePlanned;
+ bits = X265_MAX(bits, m_rateControl->frameSizeEstimated);
rc->bufferFill -= bits;
rc->bufferFill = X265_MAX(rc->bufferFill, 0);
rc->bufferFill += encoder->m_rce.bufferRate;
diff -r cbfb5bc44d6b -r 9517ea331f3e source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp Thu Feb 20 17:03:38 2014 +0530
+++ b/source/encoder/ratecontrol.cpp Thu Feb 20 17:47:53 2014 +0530
@@ -243,11 +243,12 @@
lastNonBPictType = I_SLICE;
isAbrReset = false;
lastAbrResetPoc = -1;
+ frameSizeEstimated = 0;
// vbv initialization
cfg->param.rc.vbvBufferSize = Clip3(0, 2000000, cfg->param.rc.vbvBufferSize);
cfg->param.rc.vbvMaxBitrate = Clip3(0, 2000000, cfg->param.rc.vbvMaxBitrate);
cfg->param.rc.vbvBufferInit = Clip3(0.0, 2000000.0, cfg->param.rc.vbvBufferInit);
-
+ vbvMinRate = 0;
if (cfg->param.rc.vbvBufferSize)
{
if (cfg->param.rc.rateControlMode == X265_RC_CQP)
@@ -317,6 +318,13 @@
pred[i].decay = 0.5;
pred[i].offset = 0.0;
}
+ for (int i = 0; i < 4; i++)
+ {
+ rowPreds[i].coeff = 0.25;
+ rowPreds[i].count = 1.0;
+ rowPreds[i].decay = 0.5;
+ rowPreds[i].offset = 0.0;
+ }
predBfromP = pred[0];
bframes = cfg->param.bframes;
@@ -374,10 +382,12 @@
rce->bLastMiniGopBFrame = pic->m_lowres.bLastMiniGopBFrame;
rce->bufferRate = bufferRate;
rce->poc = curSlice->getPOC();
-
if (isVbv)
+ {
+ rowPred[0] = &rowPreds[sliceType];
+ rowPred[1] = &rowPreds[3];
updateVbvPlan(enc);
-
+ }
if (isAbr) //ABR,CRF
{
currentSatd = l->getEstimatedPictureCost(pic);
@@ -385,9 +395,10 @@
rce->lastSatd = currentSatd;
double q = qScale2qp(rateEstimateQscale(pic, rce));
qp = Clip3(MIN_QP, MAX_MAX_QP, (int)(q + 0.5));
- rce->qpaRc = q;
+ rce->qpaRc = pic->m_avgQpRc = q;
/* copy value of lastRceq into thread local rce struct *to be used in RateControlEnd() */
rce->qRceq = lastRceq;
+ rce->qpNoVbv = qpNoVbv;
accumPQpUpdate();
}
else //CQP
@@ -397,9 +408,12 @@
else
qp = qpConstant[sliceType];
}
-
if (sliceType != B_SLICE)
+ {
lastNonBPictType = sliceType;
+ leadingNoBSatd = currentSatd;
+ }
+ rce->leadingNoBSatd = leadingNoBSatd;
framesDone++;
/* set the final QP to slice structure */
curSlice->setSliceQp(qp);
@@ -461,10 +475,11 @@
q += pbOffset / 2;
else
q += pbOffset;
-
- rce->frameSizePlanned = predictSize(&predBfromP, qp2qScale(q), leadingNoBSatd);
-
- return qp2qScale(q);
+ qpNoVbv = q;
+ double qScale = qp2qScale(qpNoVbv);
+ rce->frameSizePlanned = predictSize(&predBfromP, qScale, (double)leadingNoBSatd);
+ frameSizeEstimated = rce->frameSizePlanned;
+ return qScale;
}
else
{
@@ -555,7 +570,7 @@
if (qCompress != 1 && framesDone == 0)
q = qp2qScale(ABR_INIT_QP) / fabs(cfg->param.rc.ipFactor);
}
-
+ qpNoVbv = qScale2qp(q);
double lmin1 = lmin[sliceType];
double lmax1 = lmax[sliceType];
q = Clip3(lmin1, lmax1, q);
@@ -840,7 +855,7 @@
if (rce->bLastMiniGopBFrame)
{
if (rce->bframes != 0)
- updatePredictor(&predBfromP, qp2qScale(rce->qpaRc), (double)rce->lastSatd, (double)bframeBits / rce->bframes);
+ updatePredictor(&predBfromP, qp2qScale(rce->qpaRc), (double)rce->leadingNoBSatd, (double)bframeBits / rce->bframes);
bframeBits = 0;
}
}
diff -r cbfb5bc44d6b -r 9517ea331f3e source/encoder/ratecontrol.h
--- a/source/encoder/ratecontrol.h Thu Feb 20 17:03:38 2014 +0530
+++ b/source/encoder/ratecontrol.h Thu Feb 20 17:47:53 2014 +0530
@@ -53,7 +53,7 @@
int mvBits;
int bframes;
int poc;
-
+ int64_t leadingNoBSatd;
bool bLastMiniGopBFrame;
double blurredComplexity;
double qpaRc;
@@ -61,8 +61,8 @@
double frameSizePlanned;
double bufferRate;
double movingAvgSum;
+ double qpNoVbv;
};
-
struct Predictor
{
double coeff;
@@ -94,9 +94,10 @@
bool isVbv;
Predictor pred[5];
Predictor predBfromP;
+ Predictor rowPreds[4];
+ Predictor *rowPred[2];
int bframes;
int bframeBits;
- double leadingNoBSatd;
bool isAbrReset;
int lastAbrResetPoc;
int64_t currentSatd;
@@ -106,6 +107,7 @@
double ipOffset;
double pbOffset;
int lastNonBPictType;
+ int64_t leadingNoBSatd;
double accumPQp; /* for determining I-frame quant */
double accumPNorm;
double lastQScaleFor[3]; /* last qscale for a specific pict type, used for max_diff & ipb factor stuff */
@@ -118,8 +120,9 @@
double lastRceq;
int framesDone; /* framesDone keeps track of # of frames passed through RateCotrol already */
double qCompress;
+ double qpNoVbv; /* QP for the current frame if 1-pass VBV was disabled. */
+ double frameSizeEstimated; /* hold synched frameSize, updated from cu level vbv rc */
RateControl(TEncCfg * _cfg);
-
// to be called for each frame to process RateControl and set QP
void rateControlStart(TComPic* pic, Lookahead *, RateControlEntry* rce, Encoder* enc);
void calcAdaptiveQuantFrame(TComPic *pic);
More information about the x265-devel
mailing list