<div dir="ltr">From 27da9a553bc0fad5309b9bf946630d94a4e5c1d4 Mon Sep 17 00:00:00 2001<br>From: Kirithika <<a href="mailto:kirithika@multicorewareinc.com">kirithika@multicorewareinc.com</a>><br>Date: Mon, 12 Jun 2023 12:04:31 +0530<br>Subject: [PATCH] Fix SBRC to not reset  ABR at GOP beginning<br><br>---<br> source/encoder/ratecontrol.cpp | 20 ++++----------------<br> 1 file changed, 4 insertions(+), 16 deletions(-)<br><br>diff --git a/source/encoder/ratecontrol.cpp b/source/encoder/ratecontrol.cpp<br>index 42eaa673a..80f4ac3e9 100644<br>--- a/source/encoder/ratecontrol.cpp<br>+++ b/source/encoder/ratecontrol.cpp<br>@@ -2392,27 +2392,15 @@ void RateControl::rateControlUpdateStats(RateControlEntry* rce)<br>     }<br> }<br> <br>-<br>-void RateControl::checkAndResetCRF(RateControlEntry* rce)<br>-{<br>-    if(rce->poc % m_param->keyframeMax == 0)<br>-    {<br>-        init(*m_curSlice->m_sps);<br>-        m_shortTermCplxSum = rce->lastSatd / (CLIP_DURATION(m_frameDuration) / BASE_FRAME_DURATION);<br>-        m_shortTermCplxCount = 1;<br>-        rce->blurredComplexity = m_shortTermCplxSum / m_shortTermCplxCount;<br>-    }<br>-}<br>-<br> void RateControl::checkAndResetABR(RateControlEntry* rce, bool isFrameDone)<br> {<br>     double abrBuffer = 2 * m_rateTolerance * m_bitrate;<br> <br>     // Check if current Slice is a scene cut that follows low detailed/blank frames<br>-    if (rce->lastSatd > 4 * rce->movingAvgSum || rce->scenecut || rce->isFadeEnd || (m_param->bEnableSBRC && (rce->poc % m_param->keyframeMax == 0)))<br>+    if (rce->lastSatd > 4 * rce->movingAvgSum || rce->scenecut || rce->isFadeEnd)<br>     {<br>         if (!m_isAbrReset && rce->movingAvgSum > 0<br>-            && (m_isPatternPresent || !m_param->bframes ||(m_param->bEnableSBRC && (rce->poc % m_param->keyframeMax == 0))))<br>+            && (m_isPatternPresent || !m_param->bframes))<br>         {<br>             int pos = X265_MAX(m_sliderPos - m_param->frameNumThreads, 0);<br>             int64_t shrtTermWantedBits = (int64_t) (X265_MIN(pos, s_slidingWindowFrames) * m_bitrate * m_frameDuration);<br>@@ -2422,7 +2410,7 @@ void RateControl::checkAndResetABR(RateControlEntry* rce, bool isFrameDone)<br>                 shrtTermTotalBitsSum += m_encodedBitsWindow[i];<br>             double underflow = (shrtTermTotalBitsSum - shrtTermWantedBits) / abrBuffer;<br>             const double epsilon = 0.0001f;<br>-            if ((underflow < epsilon || rce->isFadeEnd || (m_param->bEnableSBRC && (rce->poc % m_param->keyframeMax == 0))) && !isFrameDone)<br>+            if ((underflow < epsilon || rce->isFadeEnd) && !isFrameDone)<br>             {<br>                 init(*m_curSlice->m_sps);<br>                 // Reduce tune complexity factor for scenes that follow blank frames<br>@@ -2508,7 +2496,7 @@ double RateControl::clipQscale(Frame* curFrame, RateControlEntry* rce, double q)<br>                 for (int j = 0; bufferFillCur >= 0 && iter ; j++)<br>                 {<br>                     int type = curFrame->m_lowres.plannedType[j];<br>-                    if (type == X265_TYPE_AUTO || totalDuration >= 1.0 || (m_param->bEnableSBRC && type == X265_TYPE_IDR))<br>+                    if (type == X265_TYPE_AUTO || totalDuration >= 1.0)<br>                         break;<br>                     totalDuration += m_frameDuration;<br>                     double wantedFrameSize = m_vbvMaxRate * m_frameDuration;<br>-- <br>2.28.0.windows.1<br><br><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><i>Thanks,</i><div><i>Kirithika</i></div></div></div></div></div>