[x265] [PATCH 3/3]SBRC: Tune ratefactor for simple/complex frames based on segment average
Kirithika Kalirathnam
kirithika at multicorewareinc.com
Tue Mar 3 06:14:38 UTC 2026
From fd5e47885c1b17c7504a2e231bd8f4054b630f75 Mon Sep 17 00:00:00 2001
From: Kirithika <kirithika at multicorewareinc.com>
Date: Tue, 29 Jul 2025 10:28:50 +0530
Subject: [PATCH] SBRC: Tune ratefactor for simple/complex frames based on
segment average
---
source/encoder/ratecontrol.cpp | 12 ++++++------
source/encoder/ratecontrol.h | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/source/encoder/ratecontrol.cpp b/source/encoder/ratecontrol.cpp
index 3de97c278..2e264e5ff 100644
--- a/source/encoder/ratecontrol.cpp
+++ b/source/encoder/ratecontrol.cpp
@@ -2038,7 +2038,7 @@ double RateControl::rateEstimateQscale(Frame* curFrame, RateControlEntry *rce)
if (m_param->bEnableSBRC)
{
- qScale = tuneQscaleForSBRC(curFrame, qScale, rce);
+ qScale = tuneQscaleForSBRC(curFrame, qScale);
rce->qpNoVbv = x265_qScale2qp(qScale);
}
@@ -2264,8 +2264,10 @@ double RateControl::rateEstimateQscale(Frame* curFrame, RateControlEntry *rce)
if (m_param->bEnableSBRC)
{
double rfConstant = m_param->rc.rfConstant;
- if (m_currentSatd < m_movingSumComplexitySeg[rce->sliceType])
+ if (m_currentSatd < (0.7 *m_movingSumComplexitySeg[rce->sliceType]))
rfConstant += 2;
+ else if (m_currentSatd > (1.3 *m_movingSumComplexitySeg[rce->sliceType]))
+ rfConstant -= 1;
double ipOffset = (curFrame->m_lowres.bScenecut ? m_ipOffset : m_ipOffset / 2.0);
rfConstant = (rce->sliceType == I_SLICE ? rfConstant - ipOffset :
(rce->sliceType == B_SLICE ? rfConstant + m_pbOffset : rfConstant));
@@ -2364,7 +2366,7 @@ double RateControl::rateEstimateQscale(Frame* curFrame, RateControlEntry *rce)
m_lastQScaleFor[P_SLICE] = X265_MAX(minScenecutQscale, m_lastQScaleFor[P_SLICE]);
}
if (m_param->bEnableSBRC)
- q = tuneQscaleForSBRC(curFrame, q, rce);
+ q = tuneQscaleForSBRC(curFrame, q);
rce->qpNoVbv = x265_qScale2qp(q);
if (m_sliceType == P_SLICE)
@@ -2546,7 +2548,7 @@ double RateControl::predictSize(Predictor *p, double q, double var)
return (p->coeff * var + p->offset) / (q * p->count);
}
-double RateControl::tuneQscaleForSBRC(Frame* curFrame, double q, RateControlEntry* rce)
+double RateControl::tuneQscaleForSBRC(Frame* curFrame, double q)
{
int depth = 0;
int framesDoneInSeg = m_framesDone % m_param->keyframeMax;
@@ -2579,8 +2581,6 @@ double RateControl::tuneQscaleForSBRC(Frame* curFrame, double q, RateControlEntr
double allowedSize = m_vbvMaxRate * segDur;
double remDur = segDur - totalDuration;
double remainingBits = frameBitsTotal;
-
- int framesLeft = m_param->totalFrames - m_framesDone;
int isLastSegmentInaEncode = m_totalframesInSegment < m_param->keyframeMax;
remainingBits = lookaheadBits / lookaheadDur * remDur;
diff --git a/source/encoder/ratecontrol.h b/source/encoder/ratecontrol.h
index 244511e45..2e3672d58 100644
--- a/source/encoder/ratecontrol.h
+++ b/source/encoder/ratecontrol.h
@@ -178,7 +178,7 @@ public:
int m_qpConstant[3];
int m_lastNonBPictType;
int m_framesDone; /* # of frames passed through RateCotrol already */
- int m_iBits;
+ int64_t m_iBits;
double m_cplxrSum; /* sum of bits*qscale/rceq */
double m_wantedBitsWindow; /* target bitrate * window */
double m_accumPQp; /* for determining I-frame quant */
@@ -305,7 +305,7 @@ protected:
double rateEstimateQscale(Frame* pic, RateControlEntry *rce); // main logic for calculating QP based on ABR
double tuneAbrQScaleFromFeedback(double qScale);
double tuneQScaleForZone(RateControlEntry *rce, double qScale); // Tune qScale to adhere to zone budget
- double tuneQscaleForSBRC(Frame* curFrame, double q, RateControlEntry *rce); // Tune qScale to adhere to segment budget
+ double tuneQscaleForSBRC(Frame* curFrame, double q); // Tune qScale to adhere to segment budget
void accumPQpUpdate();
int getPredictorType(int lowresSliceType, int sliceType);
--
2.51.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20260303/adf11e9a/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch3-sbrc-improved.diff
Type: application/octet-stream
Size: 4353 bytes
Desc: patch3-sbrc-improved.diff
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20260303/adf11e9a/attachment-0001.obj>
More information about the x265-devel
mailing list