<div dir="ltr">From 4ead3c6b4dd0e92493f2764a84e5809722177a50 Mon Sep 17 00:00:00 2001<br>From: Kirithika <<a href="mailto:kirithika@multicorewareinc.com">kirithika@multicorewareinc.com</a>><br>Date: Wed, 21 Dec 2022 14:51:05 +0530<br>Subject: [PATCH] Deprecate SBRC functionality and retain only the command line<br><br>---<br> source/common/common.h       |  2 -<br> source/common/frame.cpp      |  3 +-<br> source/common/frame.h        |  4 --<br> source/common/lowres.cpp     |  4 --<br> source/common/lowres.h       |  3 --<br> source/common/param.cpp      | 12 +++---<br> source/encoder/slicetype.cpp | 71 ------------------------------------<br> source/x265.h                |  6 +--<br> source/x265cli.cpp           |  2 +-<br> 9 files changed, 10 insertions(+), 97 deletions(-)<br><br>diff --git a/source/common/common.h b/source/common/common.h<br>index 7212f3496..37c19ae72 100644<br>--- a/source/common/common.h<br>+++ b/source/common/common.h<br>@@ -130,7 +130,6 @@ typedef uint64_t sum2_t;<br> typedef uint64_t pixel4;<br> typedef int64_t  ssum2_t;<br> #define SHIFT_TO_BITPLANE 9<br>-#define BRIGHTNESS_THRESHOLD 120 // The threshold above which a pixel is bright<br> #else<br> typedef uint8_t  pixel;<br> typedef uint16_t sum_t;<br>@@ -138,7 +137,6 @@ typedef uint32_t sum2_t;<br> typedef uint32_t pixel4;<br> typedef int32_t  ssum2_t; // Signed sum<br> #define SHIFT_TO_BITPLANE 7<br>-#define BRIGHTNESS_THRESHOLD 30 // The threshold above which a pixel is bright<br> #endif // if HIGH_BIT_DEPTH<br> <br> #if X265_DEPTH < 10<br>diff --git a/source/common/frame.cpp b/source/common/frame.cpp<br>index 768d69f34..ae3773e83 100644<br>--- a/source/common/frame.cpp<br>+++ b/source/common/frame.cpp<br>@@ -63,7 +63,6 @@ Frame::Frame()<br>     m_thetaPic = NULL;<br>     m_edgeBitPlane = NULL;<br>     m_edgeBitPic = NULL;<br>-    m_frameSegment = 0;<br>     m_isInsideWindow = 0;<br> <br>     // mcstf<br>@@ -133,7 +132,7 @@ bool Frame::create(x265_param *param, float* quantOffsets)<br>         CHECKED_MALLOC_ZERO(m_classifyCount, uint32_t, size);<br>     }<br> <br>-    if (param->rc.aqMode == X265_AQ_EDGE || param->rc.frameSegment || (param->rc.zonefileCount && param->rc.aqMode != 0))<br>+    if (param->rc.aqMode == X265_AQ_EDGE || (param->rc.zonefileCount && param->rc.aqMode != 0))<br>     {<br>         uint32_t numCuInWidth = (param->sourceWidth + param->maxCUSize - 1) / param->maxCUSize;<br>         uint32_t numCuInHeight = (param->sourceHeight + param->maxCUSize - 1) / param->maxCUSize;<br>diff --git a/source/common/frame.h b/source/common/frame.h<br>index fcd0031bc..9a3a3a4f9 100644<br>--- a/source/common/frame.h<br>+++ b/source/common/frame.h<br>@@ -154,10 +154,6 @@ public:<br>     pixel*                 m_edgeBitPlane;<br>     pixel*                 m_edgeBitPic;<br> <br>-    /* segment for each frame */<br>-    int                    m_frameSegment;<br>-<br>-<br>     int                    m_isInsideWindow;<br> <br>     /*Frame's temporal layer info*/<br>diff --git a/source/common/lowres.cpp b/source/common/lowres.cpp<br>index 97ed7b0cd..857414e91 100644<br>--- a/source/common/lowres.cpp<br>+++ b/source/common/lowres.cpp<br>@@ -212,9 +212,6 @@ bool Lowres::create(x265_param* param, PicYuv *origPic, uint32_t qgSize)<br>         }<br>     }<br> <br>-    if (param->rc.frameSegment)<br>-        lowresEdgePlane = X265_MALLOC(pixel, lumaStride * (lines + (origPic->m_lumaMarginY * 2)));<br>-<br>     if (param->bHistBasedSceneCut)<br>     {<br>         quarterSampleLowResWidth = widthFullRes / 4;<br>@@ -293,7 +290,6 @@ void Lowres::destroy(x265_param* param)<br>     X265_FREE(qpAqMotionOffset);<br>     if (param->bDynamicRefine || param->bEnableFades)<br>         X265_FREE(blockVariance);<br>-<br>     if (maxAQDepth > 0)<br>     {<br>         for (uint32_t d = 0; d < 4; d++)<br>diff --git a/source/common/lowres.h b/source/common/lowres.h<br>index c2ae270e3..c727f488a 100644<br>--- a/source/common/lowres.h<br>+++ b/source/common/lowres.h<br>@@ -48,9 +48,6 @@ struct ReferencePlanes<br>     pixel*   fpelLowerResPlane[3];<br>     pixel*   lowerResPlane[4];<br> <br>-    /* Edge Plane in Lowres */<br>-    pixel*   lowresEdgePlane;<br>-<br>     bool     isWeighted;<br>     bool     isLowres;<br>     bool     isHMELowres;<br>diff --git a/source/common/param.cpp b/source/common/param.cpp<br>index 74667b965..d6334f901 100755<br>--- a/source/common/param.cpp<br>+++ b/source/common/param.cpp<br>@@ -304,7 +304,6 @@ void x265_param_default(x265_param* param)<br>     param->rc.bEnableConstVbv = 0;<br>     param->bResetZoneConfig = 1;<br>     param->reconfigWindowSize = 0;<br>-    param->rc.frameSegment = 0;<br>     param->decoderVbvMaxRate = 0;<br>     param->bliveVBV2pass = 0;<br> <br>@@ -397,6 +396,7 @@ void x265_param_default(x265_param* param)<br> #endif<br>     /* Film grain characteristics model filename */<br>     param->filmGrain = NULL;<br>+    param->bEnableSBRC = 0;<br> }<br> <br> int x265_param_default_preset(x265_param* param, const char* preset, const char* tune)<br>@@ -1424,7 +1424,6 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br>         OPT("multi-pass-opt-analysis") p->analysisMultiPassRefine = atobool(value);<br>         OPT("multi-pass-opt-distortion") p->analysisMultiPassDistortion = atobool(value);<br>         OPT("aq-motion") p->bAQMotion = atobool(value);<br>-        OPT("sbrc") p->rc.frameSegment = atobool(value);<br>         OPT("dynamic-rd") p->dynamicRd = atof(value);<br>         OPT("analysis-reuse-level")<br>         {<br>@@ -1574,6 +1573,7 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br>         /* Film grain characterstics model filename */<br>         OPT("film-grain") p->filmGrain = (char* )value;<br>         OPT("mcstf") p->bEnableTemporalFilter = atobool(value);<br>+        OPT("sbrc") p->bEnableSBRC = atobool(value);<br>         else<br>             return X265_PARAM_BAD_NAME;<br>     }<br>@@ -2123,11 +2123,9 @@ void x265_print_params(x265_param* param)<br>              param->maxNumReferences, (param->limitReferences & X265_REF_LIMIT_CU) ? "on" : "off",<br>              (param->limitReferences & X265_REF_LIMIT_DEPTH) ? "on" : "off");<br> <br>-    if (param->rc.aqMode && !param->rc.frameSegment)<br>+    if (param->rc.aqMode)<br>         x265_log(param, X265_LOG_INFO, "AQ: mode / str / qg-size / cu-tree  : %d / %0.1f / %d / %d\n", param->rc.aqMode,<br>                  param->rc.aqStrength, param->rc.qgSize, param->rc.cuTree);<br>-    else if (param->rc.frameSegment)<br>-        x265_log(param, X265_LOG_INFO, "AQ: mode / str / qg-size / cu-tree  : auto / %0.1f / %d / %d\n", param->rc.aqStrength, param->rc.qgSize, param->rc.cuTree);<br> <br>     if (param->bLossless)<br>         x265_log(param, X265_LOG_INFO, "Rate Control                        : Lossless\n");<br>@@ -2438,7 +2436,6 @@ char *x265_param2string(x265_param* p, int padx, int pady)<br>     s += sprintf(s, " scenecut-bias=%.2f", p->scenecutBias);<br>     BOOL(p->bOptCUDeltaQP, "opt-cu-delta-qp");<br>     BOOL(p->bAQMotion, "aq-motion");<br>-    BOOL(p->rc.frameSegment, "sbrc");<br>     BOOL(p->bEmitHDR10SEI, "hdr10");<br>     BOOL(p->bHDR10Opt, "hdr10-opt");<br>     BOOL(p->bDhdr10opt, "dhdr10-opt");<br>@@ -2476,6 +2473,7 @@ char *x265_param2string(x265_param* p, int padx, int pady)<br>     if (p->filmGrain)<br>         s += sprintf(s, " film-grain=%s", p->filmGrain); // Film grain characteristics model filename<br>     BOOL(p->bEnableTemporalFilter, "mcstf");<br>+    BOOL(p->bEnableSBRC, "sbrc");<br> #undef BOOL<br>     return buf;<br> }<br>@@ -2733,7 +2731,6 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>     dst->rc.bEnableConstVbv = src->rc.bEnableConstVbv;<br>     dst->rc.hevcAq = src->rc.hevcAq;<br>     dst->rc.qpAdaptationRange = src->rc.qpAdaptationRange;<br>-    dst->rc.frameSegment = src->rc.frameSegment;<br> <br>     dst->vui.aspectRatioIdc = src->vui.aspectRatioIdc;<br>     dst->vui.sarWidth = src->vui.sarWidth;<br>@@ -2857,6 +2854,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>     /* Film grain */<br>     if (src->filmGrain)<br>         dst->filmGrain = src->filmGrain;<br>+    dst->bEnableSBRC = src->bEnableSBRC;<br> }<br> <br> #ifdef SVT_HEVC<br>diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp<br>index ca5c5ae4a..453ca5b40 100644<br>--- a/source/encoder/slicetype.cpp<br>+++ b/source/encoder/slicetype.cpp<br>@@ -1427,44 +1427,6 @@ void Lookahead::getEstimatedPictureCost(Frame *curFrame)<br>     }<br> }<br> <br>-double computeBrightnessIntensity(pixel *inPlane, int width, int height, intptr_t stride)<br>-{<br>-    pixel* rowStart = inPlane;<br>-    double count = 0;<br>-<br>-    for (int i = 0; i < height; i++)<br>-    {<br>-        for (int j = 0; j < width; j++)<br>-        {<br>-            if (rowStart[j] > BRIGHTNESS_THRESHOLD)<br>-                count++;<br>-        }<br>-        rowStart += stride;<br>-    }<br>-<br>-    /* Returns the brightness percentage of the input plane */<br>-    return (count / (width * height)) * 100;<br>-}<br>-<br>-double computeEdgeIntensity(pixel *inPlane, int width, int height, intptr_t stride)<br>-{<br>-    pixel* rowStart = inPlane;<br>-    double count = 0;<br>-<br>-    for (int i = 0; i < height; i++)<br>-    {<br>-        for (int j = 0; j < width; j++)<br>-        {<br>-            if (rowStart[j] > 0)<br>-                count++;<br>-        }<br>-        rowStart += stride;<br>-    }<br>-<br>-    /* Returns the edge percentage of the input plane */<br>-    return (count / (width * height)) * 100;<br>-}<br>-<br> uint32_t LookaheadTLD::calcVariance(pixel* inpSrc, intptr_t stride, intptr_t blockOffset, uint32_t plane)<br> {<br>     pixel* src = inpSrc + blockOffset;<br>@@ -1750,34 +1712,6 @@ void LookaheadTLD::collectPictureStatistics(Frame *curFrame)<br>     curFrame->m_lowres.bHistScenecutAnalyzed = false;<br> }<br> <br>-void LookaheadTLD::calcFrameSegment(Frame *preFrame)<br>-{<br>-    int heightL = preFrame->m_lowres.lines;<br>-    int widthL = preFrame->m_lowres.width;<br>-    pixel *lumaPlane = preFrame->m_lowres.fpelPlane[0];<br>-    intptr_t stride = preFrame->m_lowres.lumaStride;<br>-    double brightnessIntensity = 0, edgeIntensity = 0;<br>-<br>-    /* Edge plane computation */<br>-    memset(preFrame->m_lowres.lowresEdgePlane, 0, stride * (heightL + (preFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));<br>-    pixel* lowresEdgePic = preFrame->m_lowres.lowresEdgePlane + preFrame->m_fencPic->m_lumaMarginY * stride + preFrame->m_fencPic->m_lumaMarginX;<br>-    computeEdge(lowresEdgePic, lumaPlane, NULL, stride, heightL, widthL, false);<br>-<br>-    /*Frame edge percentage computation */<br>-    edgeIntensity = computeEdgeIntensity(lowresEdgePic, widthL, heightL, stride);<br>-<br>-    /* Frame Brightness percentage computation */<br>-    brightnessIntensity = computeBrightnessIntensity(lumaPlane, widthL, heightL, stride);<br>-<br>-    /* AQ mode switch */<br>-    if (edgeIntensity < FRAME_EDGE_THRESHOLD)<br>-        preFrame->m_frameSegment = brightnessIntensity > FRAME_BRIGHTNESS_THRESHOLD ? X265_AQ_AUTO_VARIANCE : X265_AQ_AUTO_VARIANCE_BIASED;<br>-    else<br>-        preFrame->m_frameSegment = brightnessIntensity > FRAME_BRIGHTNESS_THRESHOLD ? X265_AQ_EDGE : X265_AQ_VARIANCE;<br>-<br>-    preFrame->m_param->rc.aqMode = preFrame->m_frameSegment;<br>-}<br>-<br> void PreLookaheadGroup::processTasks(int workerThreadID)<br> {<br>     if (workerThreadID < 0)<br>@@ -1792,11 +1726,6 @@ void PreLookaheadGroup::processTasks(int workerThreadID)<br>         ProfileScopeEvent(prelookahead);<br>         m_lock.release();<br>         preFrame->m_lowres.init(preFrame->m_fencPic, preFrame->m_poc);<br>-<br>-        /* SBRC */<br>-        if (preFrame->m_param->rc.frameSegment)<br>-            tld.calcFrameSegment(preFrame);<br>-<br>         if (m_lookahead.m_bAdaptiveQuant)<br>             tld.calcAdaptiveQuantFrame(preFrame, m_lookahead.m_param);<br> <br>diff --git a/source/x265.h b/source/x265.h<br>index 81df146e8..9f3abd9d9 100644<br>--- a/source/x265.h<br>+++ b/source/x265.h<br>@@ -1761,9 +1761,6 @@ typedef struct x265_param<br>         /* internally enable if tune grain is set */<br>         int      bEnableConstVbv;<br> <br>-        /* enable SBRC mode for each sequence */<br>-        int      frameSegment;<br>-<br>         /* if only the focused frames would be re-encode or not */<br>         int       bEncFocusedFramesOnly;<br> <br>@@ -2256,6 +2253,9 @@ typedef struct x265_param<br>     /*Motion compensated temporal filter*/<br>     int      bEnableTemporalFilter;<br>     double   temporalFilterStrength;<br>+<br>+    /*SBRC*/<br>+    int      bEnableSBRC;<br> } x265_param;<br> <br> /* x265_param_alloc:<br>diff --git a/source/x265cli.cpp b/source/x265cli.cpp<br>index 79e4c2d8e..4d10076c0 100755<br>--- a/source/x265cli.cpp<br>+++ b/source/x265cli.cpp<br>@@ -262,7 +262,7 @@ namespace X265_NS {<br>         H0("   --aq-strength <float>         Reduces blocking and blurring in flat and textured areas (0 to 3.0). Default %.2f\n", param->rc.aqStrength);<br>         H0("   --qp-adaptation-range <float> Delta QP range by QP adaptation based on a psycho-visual model (1.0 to 6.0). Default %.2f\n", param->rc.qpAdaptationRange);<br>         H0("   --[no-]aq-motion              Block level QP adaptation based on the relative motion between the block and the frame. Default %s\n", OPT(param->bAQMotion));<br>-        H1("   --[no-]sbrc                   Enables the segment based rate control, using its scene statistics. Default %s\n", OPT(param->rc.frameSegment));<br>+        H1("   --[no-]sbrc                   Enables the segment based rate control. Default %s\n", OPT(param->bEnableSBRC));<br>         H0("   --qg-size <int>               Specifies the size of the quantization group (64, 32, 16, 8). Default %d\n", param->rc.qgSize);<br>         H0("   --[no-]cutree                 Enable cutree for Adaptive Quantization. Default %s\n", OPT(param->rc.cuTree));<br>         H0("   --[no-]rc-grain               Enable ratecontrol mode to handle grains specifically. turned on with tune grain. Default %s\n", OPT(param->rc.bEnableGrain));<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>