[x265] [PATCH] Deprecate SBRC functionality and retain only the command line

Kirithika Kalirathnam kirithika at multicorewareinc.com
Thu Dec 29 16:26:06 UTC 2022


>From 4ead3c6b4dd0e92493f2764a84e5809722177a50 Mon Sep 17 00:00:00 2001
From: Kirithika <kirithika at multicorewareinc.com>
Date: Wed, 21 Dec 2022 14:51:05 +0530
Subject: [PATCH] Deprecate SBRC functionality and retain only the command
line

---
 source/common/common.h       |  2 -
 source/common/frame.cpp      |  3 +-
 source/common/frame.h        |  4 --
 source/common/lowres.cpp     |  4 --
 source/common/lowres.h       |  3 --
 source/common/param.cpp      | 12 +++---
 source/encoder/slicetype.cpp | 71 ------------------------------------
 source/x265.h                |  6 +--
 source/x265cli.cpp           |  2 +-
 9 files changed, 10 insertions(+), 97 deletions(-)

diff --git a/source/common/common.h b/source/common/common.h
index 7212f3496..37c19ae72 100644
--- a/source/common/common.h
+++ b/source/common/common.h
@@ -130,7 +130,6 @@ typedef uint64_t sum2_t;
 typedef uint64_t pixel4;
 typedef int64_t  ssum2_t;
 #define SHIFT_TO_BITPLANE 9
-#define BRIGHTNESS_THRESHOLD 120 // The threshold above which a pixel is
bright
 #else
 typedef uint8_t  pixel;
 typedef uint16_t sum_t;
@@ -138,7 +137,6 @@ typedef uint32_t sum2_t;
 typedef uint32_t pixel4;
 typedef int32_t  ssum2_t; // Signed sum
 #define SHIFT_TO_BITPLANE 7
-#define BRIGHTNESS_THRESHOLD 30 // The threshold above which a pixel is
bright
 #endif // if HIGH_BIT_DEPTH

 #if X265_DEPTH < 10
diff --git a/source/common/frame.cpp b/source/common/frame.cpp
index 768d69f34..ae3773e83 100644
--- a/source/common/frame.cpp
+++ b/source/common/frame.cpp
@@ -63,7 +63,6 @@ Frame::Frame()
     m_thetaPic = NULL;
     m_edgeBitPlane = NULL;
     m_edgeBitPic = NULL;
-    m_frameSegment = 0;
     m_isInsideWindow = 0;

     // mcstf
@@ -133,7 +132,7 @@ bool Frame::create(x265_param *param, float*
quantOffsets)
         CHECKED_MALLOC_ZERO(m_classifyCount, uint32_t, size);
     }

-    if (param->rc.aqMode == X265_AQ_EDGE || param->rc.frameSegment ||
(param->rc.zonefileCount && param->rc.aqMode != 0))
+    if (param->rc.aqMode == X265_AQ_EDGE || (param->rc.zonefileCount &&
param->rc.aqMode != 0))
     {
         uint32_t numCuInWidth = (param->sourceWidth + param->maxCUSize -
1) / param->maxCUSize;
         uint32_t numCuInHeight = (param->sourceHeight + param->maxCUSize -
1) / param->maxCUSize;
diff --git a/source/common/frame.h b/source/common/frame.h
index fcd0031bc..9a3a3a4f9 100644
--- a/source/common/frame.h
+++ b/source/common/frame.h
@@ -154,10 +154,6 @@ public:
     pixel*                 m_edgeBitPlane;
     pixel*                 m_edgeBitPic;

-    /* segment for each frame */
-    int                    m_frameSegment;
-
-
     int                    m_isInsideWindow;

     /*Frame's temporal layer info*/
diff --git a/source/common/lowres.cpp b/source/common/lowres.cpp
index 97ed7b0cd..857414e91 100644
--- a/source/common/lowres.cpp
+++ b/source/common/lowres.cpp
@@ -212,9 +212,6 @@ bool Lowres::create(x265_param* param, PicYuv *origPic,
uint32_t qgSize)
         }
     }

-    if (param->rc.frameSegment)
-        lowresEdgePlane = X265_MALLOC(pixel, lumaStride * (lines +
(origPic->m_lumaMarginY * 2)));
-
     if (param->bHistBasedSceneCut)
     {
         quarterSampleLowResWidth = widthFullRes / 4;
@@ -293,7 +290,6 @@ void Lowres::destroy(x265_param* param)
     X265_FREE(qpAqMotionOffset);
     if (param->bDynamicRefine || param->bEnableFades)
         X265_FREE(blockVariance);
-
     if (maxAQDepth > 0)
     {
         for (uint32_t d = 0; d < 4; d++)
diff --git a/source/common/lowres.h b/source/common/lowres.h
index c2ae270e3..c727f488a 100644
--- a/source/common/lowres.h
+++ b/source/common/lowres.h
@@ -48,9 +48,6 @@ struct ReferencePlanes
     pixel*   fpelLowerResPlane[3];
     pixel*   lowerResPlane[4];

-    /* Edge Plane in Lowres */
-    pixel*   lowresEdgePlane;
-
     bool     isWeighted;
     bool     isLowres;
     bool     isHMELowres;
diff --git a/source/common/param.cpp b/source/common/param.cpp
index 74667b965..d6334f901 100755
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -304,7 +304,6 @@ void x265_param_default(x265_param* param)
     param->rc.bEnableConstVbv = 0;
     param->bResetZoneConfig = 1;
     param->reconfigWindowSize = 0;
-    param->rc.frameSegment = 0;
     param->decoderVbvMaxRate = 0;
     param->bliveVBV2pass = 0;

@@ -397,6 +396,7 @@ void x265_param_default(x265_param* param)
 #endif
     /* Film grain characteristics model filename */
     param->filmGrain = NULL;
+    param->bEnableSBRC = 0;
 }

 int x265_param_default_preset(x265_param* param, const char* preset, const
char* tune)
@@ -1424,7 +1424,6 @@ int x265_param_parse(x265_param* p, const char* name,
const char* value)
         OPT("multi-pass-opt-analysis") p->analysisMultiPassRefine =
atobool(value);
         OPT("multi-pass-opt-distortion") p->analysisMultiPassDistortion =
atobool(value);
         OPT("aq-motion") p->bAQMotion = atobool(value);
-        OPT("sbrc") p->rc.frameSegment = atobool(value);
         OPT("dynamic-rd") p->dynamicRd = atof(value);
         OPT("analysis-reuse-level")
         {
@@ -1574,6 +1573,7 @@ int x265_param_parse(x265_param* p, const char* name,
const char* value)
         /* Film grain characterstics model filename */
         OPT("film-grain") p->filmGrain = (char* )value;
         OPT("mcstf") p->bEnableTemporalFilter = atobool(value);
+        OPT("sbrc") p->bEnableSBRC = atobool(value);
         else
             return X265_PARAM_BAD_NAME;
     }
@@ -2123,11 +2123,9 @@ void x265_print_params(x265_param* param)
              param->maxNumReferences, (param->limitReferences &
X265_REF_LIMIT_CU) ? "on" : "off",
              (param->limitReferences & X265_REF_LIMIT_DEPTH) ? "on" :
"off");

-    if (param->rc.aqMode && !param->rc.frameSegment)
+    if (param->rc.aqMode)
         x265_log(param, X265_LOG_INFO, "AQ: mode / str / qg-size / cu-tree
 : %d / %0.1f / %d / %d\n", param->rc.aqMode,
                  param->rc.aqStrength, param->rc.qgSize, param->rc.cuTree);
- else if (param->rc.frameSegment)
-        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);

     if (param->bLossless)
         x265_log(param, X265_LOG_INFO, "Rate Control
 : Lossless\n");
@@ -2438,7 +2436,6 @@ char *x265_param2string(x265_param* p, int padx, int
pady)
     s += sprintf(s, " scenecut-bias=%.2f", p->scenecutBias);
     BOOL(p->bOptCUDeltaQP, "opt-cu-delta-qp");
     BOOL(p->bAQMotion, "aq-motion");
-    BOOL(p->rc.frameSegment, "sbrc");
     BOOL(p->bEmitHDR10SEI, "hdr10");
     BOOL(p->bHDR10Opt, "hdr10-opt");
     BOOL(p->bDhdr10opt, "dhdr10-opt");
@@ -2476,6 +2473,7 @@ char *x265_param2string(x265_param* p, int padx, int
pady)
     if (p->filmGrain)
         s += sprintf(s, " film-grain=%s", p->filmGrain); // Film grain
characteristics model filename
     BOOL(p->bEnableTemporalFilter, "mcstf");
+    BOOL(p->bEnableSBRC, "sbrc");
 #undef BOOL
     return buf;
 }
@@ -2733,7 +2731,6 @@ void x265_copy_params(x265_param* dst, x265_param*
src)
     dst->rc.bEnableConstVbv = src->rc.bEnableConstVbv;
     dst->rc.hevcAq = src->rc.hevcAq;
     dst->rc.qpAdaptationRange = src->rc.qpAdaptationRange;
-    dst->rc.frameSegment = src->rc.frameSegment;

     dst->vui.aspectRatioIdc = src->vui.aspectRatioIdc;
     dst->vui.sarWidth = src->vui.sarWidth;
@@ -2857,6 +2854,7 @@ void x265_copy_params(x265_param* dst, x265_param*
src)
     /* Film grain */
     if (src->filmGrain)
         dst->filmGrain = src->filmGrain;
+    dst->bEnableSBRC = src->bEnableSBRC;
 }

 #ifdef SVT_HEVC
diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp
index ca5c5ae4a..453ca5b40 100644
--- a/source/encoder/slicetype.cpp
+++ b/source/encoder/slicetype.cpp
@@ -1427,44 +1427,6 @@ void Lookahead::getEstimatedPictureCost(Frame
*curFrame)
     }
 }

-double computeBrightnessIntensity(pixel *inPlane, int width, int height,
intptr_t stride)
-{
-    pixel* rowStart = inPlane;
-    double count = 0;
-
-    for (int i = 0; i < height; i++)
-    {
-        for (int j = 0; j < width; j++)
-        {
-            if (rowStart[j] > BRIGHTNESS_THRESHOLD)
-                count++;
-        }
-        rowStart += stride;
-    }
-
-    /* Returns the brightness percentage of the input plane */
-    return (count / (width * height)) * 100;
-}
-
-double computeEdgeIntensity(pixel *inPlane, int width, int height,
intptr_t stride)
-{
-    pixel* rowStart = inPlane;
-    double count = 0;
-
-    for (int i = 0; i < height; i++)
-    {
-        for (int j = 0; j < width; j++)
-        {
-            if (rowStart[j] > 0)
-                count++;
-        }
-        rowStart += stride;
-    }
-
-    /* Returns the edge percentage of the input plane */
-    return (count / (width * height)) * 100;
-}
-
 uint32_t LookaheadTLD::calcVariance(pixel* inpSrc, intptr_t stride,
intptr_t blockOffset, uint32_t plane)
 {
     pixel* src = inpSrc + blockOffset;
@@ -1750,34 +1712,6 @@ void LookaheadTLD::collectPictureStatistics(Frame
*curFrame)
     curFrame->m_lowres.bHistScenecutAnalyzed = false;
 }

-void LookaheadTLD::calcFrameSegment(Frame *preFrame)
-{
-    int heightL = preFrame->m_lowres.lines;
-    int widthL = preFrame->m_lowres.width;
-    pixel *lumaPlane = preFrame->m_lowres.fpelPlane[0];
-    intptr_t stride = preFrame->m_lowres.lumaStride;
-    double brightnessIntensity = 0, edgeIntensity = 0;
-
-    /* Edge plane computation */
-    memset(preFrame->m_lowres.lowresEdgePlane, 0, stride * (heightL +
(preFrame->m_fencPic->m_lumaMarginY * 2)) * sizeof(pixel));
-    pixel* lowresEdgePic = preFrame->m_lowres.lowresEdgePlane +
preFrame->m_fencPic->m_lumaMarginY * stride +
preFrame->m_fencPic->m_lumaMarginX;
-    computeEdge(lowresEdgePic, lumaPlane, NULL, stride, heightL, widthL,
false);
-
-    /*Frame edge percentage computation */
-    edgeIntensity = computeEdgeIntensity(lowresEdgePic, widthL, heightL,
stride);
-
-    /* Frame Brightness percentage computation */
-    brightnessIntensity = computeBrightnessIntensity(lumaPlane, widthL,
heightL, stride);
-
-    /* AQ mode switch */
-    if (edgeIntensity < FRAME_EDGE_THRESHOLD)
-        preFrame->m_frameSegment = brightnessIntensity >
FRAME_BRIGHTNESS_THRESHOLD ? X265_AQ_AUTO_VARIANCE :
X265_AQ_AUTO_VARIANCE_BIASED;
-    else
-        preFrame->m_frameSegment = brightnessIntensity >
FRAME_BRIGHTNESS_THRESHOLD ? X265_AQ_EDGE : X265_AQ_VARIANCE;
-
-    preFrame->m_param->rc.aqMode = preFrame->m_frameSegment;
-}
-
 void PreLookaheadGroup::processTasks(int workerThreadID)
 {
     if (workerThreadID < 0)
@@ -1792,11 +1726,6 @@ void PreLookaheadGroup::processTasks(int
workerThreadID)
         ProfileScopeEvent(prelookahead);
         m_lock.release();
         preFrame->m_lowres.init(preFrame->m_fencPic, preFrame->m_poc);
-
-        /* SBRC */
-        if (preFrame->m_param->rc.frameSegment)
-            tld.calcFrameSegment(preFrame);
-
         if (m_lookahead.m_bAdaptiveQuant)
             tld.calcAdaptiveQuantFrame(preFrame, m_lookahead.m_param);

diff --git a/source/x265.h b/source/x265.h
index 81df146e8..9f3abd9d9 100644
--- a/source/x265.h
+++ b/source/x265.h
@@ -1761,9 +1761,6 @@ typedef struct x265_param
         /* internally enable if tune grain is set */
         int      bEnableConstVbv;

-        /* enable SBRC mode for each sequence */
-        int      frameSegment;
-
         /* if only the focused frames would be re-encode or not */
         int       bEncFocusedFramesOnly;

@@ -2256,6 +2253,9 @@ typedef struct x265_param
     /*Motion compensated temporal filter*/
     int      bEnableTemporalFilter;
     double   temporalFilterStrength;
+
+    /*SBRC*/
+    int      bEnableSBRC;
 } x265_param;

 /* x265_param_alloc:
diff --git a/source/x265cli.cpp b/source/x265cli.cpp
index 79e4c2d8e..4d10076c0 100755
--- a/source/x265cli.cpp
+++ b/source/x265cli.cpp
@@ -262,7 +262,7 @@ namespace X265_NS {
         H0("   --aq-strength <float>         Reduces blocking and blurring
in flat and textured areas (0 to 3.0). Default %.2f\n",
param->rc.aqStrength);
         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);
         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));
-        H1("   --[no-]sbrc                   Enables the segment based
rate control, using its scene statistics. Default %s\n",
OPT(param->rc.frameSegment));
+        H1("   --[no-]sbrc                   Enables the segment based
rate control. Default %s\n", OPT(param->bEnableSBRC));
         H0("   --qg-size <int>               Specifies the size of the
quantization group (64, 32, 16, 8). Default %d\n", param->rc.qgSize);
         H0("   --[no-]cutree                 Enable cutree for Adaptive
Quantization. Default %s\n", OPT(param->rc.cuTree));
         H0("   --[no-]rc-grain               Enable ratecontrol mode to
handle grains specifically. turned on with tune grain. Default %s\n",
OPT(param->rc.bEnableGrain));
-- 
2.28.0.windows.1

*Thanks,*
*Kirithika*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20221229/6bd24ad2/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch1.diff
Type: application/octet-stream
Size: 13212 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20221229/6bd24ad2/attachment-0001.obj>


More information about the x265-devel mailing list