<div dir="ltr">From f6c1b86d99ab3a0dd57204f930e526a07e28fed7 Mon Sep 17 00:00:00 2001<br>From: Praveen Karadugattu <<a href="mailto:praveenkumar@multicorewareinc.com">praveenkumar@multicorewareinc.com</a>><br>Date: Sun, 20 Jun 2021 21:20:50 +0530<br>Subject: [PATCH] Disable fall-back on traditional scenecut algorithm with<br> --hist-scenecut<br><br>---<br> doc/reST/cli.rst                 |  9 +++++++--<br> source/CMakeLists.txt            |  2 +-<br> source/common/param.cpp          |  8 +++++++-<br> source/encoder/encoder.cpp       | 17 ++++++++++++-----<br> source/encoder/slicetype.cpp     | 15 ++++++++++-----<br> source/test/regression-tests.txt |  1 +<br> source/x265.h                    |  4 ++++<br> source/x265cli.h                 |  1 +<br> 8 files changed, 43 insertions(+), 14 deletions(-)<br><br>diff --git a/doc/reST/cli.rst b/doc/reST/cli.rst<br>index 4154221af..280b734b3 100755<br>--- a/doc/reST/cli.rst<br>+++ b/doc/reST/cli.rst<br>@@ -1470,7 +1470,8 @@ Slice decision options<br> .. option:: --hist-scenecut, --no-hist-scenecut<br> <br>       Indicates that scenecuts need to be detected using luma edge and chroma histograms.<br>-  :option:`--hist-scenecut` enables scenecut detection using the histograms and disables the default scene cut algorithm.<br>+      :option:`--hist-scenecut` enables scenecut detection using the histograms.<br>+   It also uses the intra and inter cost info to arrive at a scenecut decision from the default scenecut method.<br>        :option:`--no-hist-scenecut` disables histogram based scenecut algorithm.<br>    <br> .. option:: --hist-threshold <0.0..1.0><br>@@ -1480,7 +1481,11 @@ Slice decision options<br>     greater than 0.2 against the previous frame as scenecut. <br>    Increasing the threshold reduces the number of scenecuts detected.<br>   Default 0.03.<br>-        <br>+<br>+.. option:: --disable-traditional-scenecut<br>+<br>+  Indicates that the usage of traditional scenecut detection using intra and inter cost should be disabled when :option:`--hist-scenecut` is used.<br>+<br> .. option:: --radl <integer><br>    <br>     Number of RADL pictures allowed infront of IDR. Requires closed gop interval.<br>diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt<br>index b4e57b592..f4a9cb793 100755<br>--- a/source/CMakeLists.txt<br>+++ b/source/CMakeLists.txt<br>@@ -29,7 +29,7 @@ option(NATIVE_BUILD "Target the build CPU" OFF)<br> option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)<br> mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br> # X265_BUILD must be incremented each time the public API is changed<br>-set(X265_BUILD 200)<br>+set(X265_BUILD 201)<br> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265.def.in">x265.def.in</a>"<br>                "${PROJECT_BINARY_DIR}/x265.def")<br> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265_config.h.in">x265_config.h.in</a>"<br>diff --git a/source/common/param.cpp b/source/common/param.cpp<br>index 8a27aaef3..3b84415c3 100755<br>--- a/source/common/param.cpp<br>+++ b/source/common/param.cpp<br>@@ -172,6 +172,7 @@ void x265_param_default(x265_param* param)<br>     param->scenecutThreshold = 40; /* Magic number pulled in from x264 */<br>     param->edgeTransitionThreshold = 0.03;<br>     param->bHistBasedSceneCut = 0;<br>+    param->bDisableTradScdInHscd = 0;<br>     param->lookaheadSlices = 8;<br>     param->lookaheadThreads = 0;<br>     param->scenecutBias = 5.0;<br>@@ -598,6 +599,7 @@ int x265_param_default_preset(x265_param* param, const char* preset, const char*<br>             param->lookaheadDepth = 0;<br>             param->scenecutThreshold = 0;<br>             param->bHistBasedSceneCut = 0;<br>+            param->bDisableTradScdInHscd = 0;<br>             param->rc.cuTree = 0;<br>             param->frameNumThreads = 1;<br>         }<br>@@ -953,6 +955,7 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br>            bError = false;<br>            p->scenecutThreshold = atoi(value);<br>            p->bHistBasedSceneCut = 0;<br>+           p->bDisableTradScdInHscd = 0;<br>        }<br>     }<br>     OPT("temporal-layers") p->bEnableTemporalSubLayers = atobool(value);<br>@@ -1234,6 +1237,7 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br>             }<br>         }<br>         OPT("hist-threshold") p->edgeTransitionThreshold = atof(value);<br>+        OPT("disable-traditional-scenecut") p->bDisableTradScdInHscd = atobool(value);<br>         OPT("rskip-edge-threshold") p->edgeVarThreshold = atoi(value)/100.0f;<br>         OPT("lookahead-threads") p->lookaheadThreads = atoi(value);<br>         OPT("opt-cu-delta-qp") p->bOptCUDeltaQP = atobool(value);<br>@@ -2151,7 +2155,8 @@ char *x265_param2string(x265_param* p, int padx, int pady)<br>     s += sprintf(s, " rc-lookahead=%d", p->lookaheadDepth);<br>     s += sprintf(s, " lookahead-slices=%d", p->lookaheadSlices);<br>     s += sprintf(s, " scenecut=%d", p->scenecutThreshold);<br>-    s += sprintf(s, " hist-scenecut=%d", p->bHistBasedSceneCut);<br>+    BOOL(p->bHistBasedSceneCut, "hist-scenecut");<br>+    BOOL(p->bDisableTradScdInHscd, "disable-traditional-scenecut");<br>     s += sprintf(s, " radl=%d", p->radl);<br>     BOOL(p->bEnableHRDConcatFlag, "splice");<br>     BOOL(p->bIntraRefresh, "intra-refresh");<br>@@ -2467,6 +2472,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>     dst->lookaheadThreads = src->lookaheadThreads;<br>     dst->scenecutThreshold = src->scenecutThreshold;<br>     dst->bHistBasedSceneCut = src->bHistBasedSceneCut;<br>+    dst->bDisableTradScdInHscd = src->bDisableTradScdInHscd;<br>     dst->bIntraRefresh = src->bIntraRefresh;<br>     dst->maxCUSize = src->maxCUSize;<br>     dst->minCUSize = src->minCUSize;<br>diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>index c1e1cb46d..dfb872889 100644<br>--- a/source/encoder/encoder.cpp<br>+++ b/source/encoder/encoder.cpp<br>@@ -3680,6 +3680,7 @@ void Encoder::configure(x265_param *p)<br>         p->keyframeMax = INT_MAX;<br>         p->scenecutThreshold = 0;<br>         p->bHistBasedSceneCut = 0;<br>+        p->bDisableTradScdInHscd = 0;<br>     }<br>     else if (p->keyframeMax <= 1)<br>     {<br>@@ -3694,6 +3695,7 @@ void Encoder::configure(x265_param *p)<br>         p->bframes = 0;<br>         p->scenecutThreshold = 0;<br>         p->bHistBasedSceneCut = 0;<br>+        p->bDisableTradScdInHscd = 0;<br>         p->bFrameAdaptive = 0;<br>         p->rc.cuTree = 0;<br>         p->bEnableWeightedPred = 0;<br>@@ -4421,12 +4423,17 @@ void Encoder::configure(x265_param *p)<br>             m_param->searchRange = m_param->hmeRange[2];<br>     }<br> <br>-   if (p->bHistBasedSceneCut && !p->edgeTransitionThreshold)<br>-   {<br>-       p->edgeTransitionThreshold = 0.03;<br>-       x265_log(p, X265_LOG_WARNING, "using  default threshold %.2lf for scene cut detection\n", p->edgeTransitionThreshold);<br>-   }<br>+    if (p->bHistBasedSceneCut && !p->edgeTransitionThreshold)<br>+    {<br>+        p->edgeTransitionThreshold = 0.03;<br>+        x265_log(p, X265_LOG_WARNING, "using  default threshold %.2lf for scene cut detection.\n", p->edgeTransitionThreshold);<br>+    }<br> <br>+    if (!p->bHistBasedSceneCut && p->bDisableTradScdInHscd)<br>+    {<br>+        p->bDisableTradScdInHscd = 0;<br>+        x265_log(p, X265_LOG_WARNING, "option --disable-traditional-scenecut requires --hist-scenecut to be enabled.\n");<br>+    }<br> }<br> <br> void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x265_picture* picIn, int paramBytes)<br>diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp<br>index 0adb0d0db..ace3b5469 100644<br>--- a/source/encoder/slicetype.cpp<br>+++ b/source/encoder/slicetype.cpp<br>@@ -2014,7 +2014,7 @@ void Lookahead::slicetypeAnalyse(Lowres **frames, bool bKeyframe)<br>     bool isScenecut = false;<br> <br>     /* Temporal computations for scenecut detection */<br>-    if (m_param->bHistBasedSceneCut)<br>+    if (m_param->bHistBasedSceneCut && !m_param->bDisableTradScdInHscd)<br>     {<br>         for (int i = numFrames - 1; i > 0; i--)<br>         {<br>@@ -2047,8 +2047,10 @@ void Lookahead::slicetypeAnalyse(Lowres **frames, bool bKeyframe)<br>     }<br> <br>     /* When scenecut threshold is set, use scenecut detection for I frame placements */<br>-    if (!m_param->bHistBasedSceneCut || (m_param->bHistBasedSceneCut && frames[1]->bScenecut))<br>+    if (!m_param->bHistBasedSceneCut || (m_param->bHistBasedSceneCut && !m_param->bDisableTradScdInHscd && frames[1]->bScenecut))<br>         isScenecut = scenecut(frames, 0, 1, true, origNumFrames);<br>+    else if (m_param->bHistBasedSceneCut && frames[1]->bScenecut)<br>+        isScenecut = true;<br> <br>     if (isScenecut && (m_param->bHistBasedSceneCut || m_param->scenecutThreshold))<br>     {<br>@@ -2061,14 +2063,17 @@ void Lookahead::slicetypeAnalyse(Lowres **frames, bool bKeyframe)<br>         m_extendGopBoundary = false;<br>         for (int i = m_param->bframes + 1; i < origNumFrames; i += m_param->bframes + 1)<br>         {<br>-            if (!m_param->bHistBasedSceneCut || (m_param->bHistBasedSceneCut && frames[i + 1]->bScenecut))<br>+            if (!m_param->bHistBasedSceneCut || (m_param->bHistBasedSceneCut && !m_param->bDisableTradScdInHscd && frames[i + 1]->bScenecut))<br>                 scenecut(frames, i, i + 1, true, origNumFrames);<br> <br>             for (int j = i + 1; j <= X265_MIN(i + m_param->bframes + 1, origNumFrames); j++)<br>             {<br>-                if (frames[j]->bScenecut && scenecutInternal(frames, j - 1, j, true))<br>+                if (frames[j]->bScenecut)<br>                 {<br>-                    m_extendGopBoundary = true;<br>+                    if (!m_param->bDisableTradScdInHscd)<br>+                        m_extendGopBoundary = scenecutInternal(frames, j - 1, j, true);<br>+                    else<br>+                        m_extendGopBoundary = true;<br>                     break;<br>                 }<br>             }<br>diff --git a/source/test/regression-tests.txt b/source/test/regression-tests.txt<br>index 971c854df..828157cab 100644<br>--- a/source/test/regression-tests.txt<br>+++ b/source/test/regression-tests.txt<br>@@ -160,6 +160,7 @@ Traffic_4096x2048_30p.y4m, --preset medium --frame-dup --dup-threshold 60 --hrd<br> Kimono1_1920x1080_24_400.yuv,--preset superfast --qp 28 --zones 0,139,q=32<br> sintel_trailer_2k_1920x1080_24.yuv, --preset medium --hist-scenecut --hist-threshold 0.02 --frame-dup --dup-threshold 60 --hrd --bitrate 10000 --vbv-bufsize 15000 --vbv-maxrate 12000<br> sintel_trailer_2k_1920x1080_24.yuv, --preset medium --hist-scenecut --hist-threshold 0.02<br>+sintel_trailer_2k_1920x1080_24.yuv, --preset medium --hist-scenecut --hist-threshold 0.02 --disable-traditional-scenecut<br> sintel_trailer_2k_1920x1080_24.yuv, --preset ultrafast --hist-scenecut --hist-threshold 0.02<br> crowd_run_1920x1080_50.yuv, --preset faster --ctu 32 --rskip 2 --rskip-edge-threshold 5<br> crowd_run_1920x1080_50.yuv, --preset fast --ctu 64 --rskip 2 --rskip-edge-threshold 5 --aq-mode 4<br>diff --git a/source/x265.h b/source/x265.h<br>index 324f3163f..3a65fdda6 100644<br>--- a/source/x265.h<br>+++ b/source/x265.h<br>@@ -1963,6 +1963,10 @@ typedef struct x265_param<br>     /* Flag indicating whether the encoder should emit an End of Sequence<br>      * NAL at the end of every Coded Video Sequence. Default false */<br>     int      bEnableEndOfSequence;<br>+<br>+    /* Flag to turn off traditional scenecut detection in histogram based scenecut detection so that<br>+     * only spatial properties are used for scenecut detection. Default false */<br>+    int      bDisableTradScdInHscd;<br> } x265_param;<br> <br> /* x265_param_alloc:<br>diff --git a/source/x265cli.h b/source/x265cli.h<br>index 46a2b68ae..86136fbfb 100644<br>--- a/source/x265cli.h<br>+++ b/source/x265cli.h<br>@@ -144,6 +144,7 @@ static const struct option long_options[] =<br>     { "hist-scenecut",        no_argument, NULL, 0},<br>     { "no-hist-scenecut",     no_argument, NULL, 0},<br>     { "hist-threshold", required_argument, NULL, 0},<br>+    { "disable-traditional-scenecut", no_argument, NULL, 0},<br>     { "fades",                no_argument, NULL, 0 },<br>     { "no-fades",             no_argument, NULL, 0 },<br>     { "scenecut-aware-qp", required_argument, NULL, 0 },<br>-- <br>2.24.0.windows.2<br><br><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><font color="#073763">Regards, <br><b>Pooja Venkatesan</b>, <br>Video Codec Engineer, <br>Media & AI analytics BU</font><br><font size="1"><img src="https://docs.google.com/uc?export=download&id=1d95Qlxmd7GpR09YzmNH0gdIVV6O9kvWD&revid=0B0mq5CBCJeT-Uk04LzZtMkJob0dUMTFsTjlkSzlQQkhFaTIwPQ" width="143" height="20" style="margin-right: 0px;"></font><br></div></div></div></div>