<div dir="ltr">Pushed to Release_3.5</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 5, 2021 at 3:29 PM Niranjan Bala <<a href="mailto:niranjan@multicorewareinc.com">niranjan@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">From 50d1b4a2ad5e3c817b60141b6371d3dd59c89e9c Mon Sep 17 00:00:00 2001<br>From: Niranjan <<a href="mailto:niranjan@multicorewareinc.com" target="_blank">niranjan@multicorewareinc.com</a>><br>Date: Mon, 1 Feb 2021 14:24:19 +0530<br>Subject: [PATCH] Modify Window offsets relative to slice-types for<br> --scenecut-aware-qp<br><br>---<br> source/common/param.cpp        | 75 ++++++++++++++++++++++------------<br> source/encoder/ratecontrol.cpp | 36 ++++++++--------<br> source/encoder/ratecontrol.h   |  6 +--<br> 3 files changed, 71 insertions(+), 46 deletions(-)<br><br>diff --git a/source/common/param.cpp b/source/common/param.cpp<br>index 8a6a974f1..8695ad686 100755<br>--- a/source/common/param.cpp<br>+++ b/source/common/param.cpp<br>@@ -1355,41 +1355,62 @@ int x265_param_parse(x265_param* p, const char* name, const char* value)<br> <br>             if (p->bEnableSceneCutAwareQp == FORWARD)<br>             {<br>-                sscanf(value, "%d,%lf,%lf", &window1, &refQpDelta1, &nonRefQpDelta1);<br>-                if (window1 > 0)<br>-                    p->fwdScenecutWindow = window1;<br>-                if (refQpDelta1 > 0)<br>-                    p->fwdRefQpDelta = refQpDelta1;<br>-                if (nonRefQpDelta1 > 0)<br>-                    p->fwdNonRefQpDelta = nonRefQpDelta1;<br>+                if (3 == sscanf(value, "%d,%lf,%lf", &window1, &refQpDelta1, &nonRefQpDelta1))<br>+                {<br>+                    if (window1 > 0)<br>+                        p->fwdScenecutWindow = window1;<br>+                    if (refQpDelta1 > 0)<br>+                        p->fwdRefQpDelta = refQpDelta1;<br>+                    if (nonRefQpDelta1 > 0)<br>+                        p->fwdNonRefQpDelta = nonRefQpDelta1;<br>+                }<br>+                else<br>+                {<br>+                    x265_log(NULL, X265_LOG_ERROR, "Specify all the necessary offsets for masking-strength \n");<br>+                    bError = true;<br>+                }<br>             }<br>             else if (p->bEnableSceneCutAwareQp == BACKWARD)<br>             {<br>-                sscanf(value, "%d,%lf,%lf", &window1, &refQpDelta1, &nonRefQpDelta1);<br>-                if (window1 > 0)<br>-                    p->bwdScenecutWindow = window1;<br>-                if (refQpDelta1 > 0)<br>-                    p->bwdRefQpDelta = refQpDelta1;<br>-                if (nonRefQpDelta1 > 0)<br>-                    p->bwdNonRefQpDelta = nonRefQpDelta1;<br>+                if (3 == sscanf(value, "%d,%lf,%lf", &window1, &refQpDelta1, &nonRefQpDelta1))<br>+                {<br>+                    if (window1 > 0)<br>+                        p->bwdScenecutWindow = window1;<br>+                    if (refQpDelta1 > 0)<br>+                        p->bwdRefQpDelta = refQpDelta1;<br>+                    if (nonRefQpDelta1 > 0)<br>+                        p->bwdNonRefQpDelta = nonRefQpDelta1;<br>+                }<br>+                else<br>+                {<br>+                    x265_log(NULL, X265_LOG_ERROR, "Specify all the necessary offsets for masking-strength \n");<br>+                    bError = true;<br>+                }<br>             }<br>             else if (p->bEnableSceneCutAwareQp == BI_DIRECTIONAL)<br>             {<br>                 int window2;<br>                 double refQpDelta2, nonRefQpDelta2;<br>-                sscanf(value, "%d,%lf,%lf,%d,%lf,%lf", &window1, &refQpDelta1, &nonRefQpDelta1, &window2, &refQpDelta2, &nonRefQpDelta2);<br>-                if (window1 > 0)<br>-                    p->fwdScenecutWindow = window1;<br>-                if (refQpDelta1 > 0)<br>-                    p->fwdRefQpDelta = refQpDelta1;<br>-                if (nonRefQpDelta1 > 0)<br>-                    p->fwdNonRefQpDelta = nonRefQpDelta1;<br>-                if (window2 > 0)<br>-                    p->bwdScenecutWindow = window2;<br>-                if (refQpDelta2 > 0)<br>-                    p->bwdRefQpDelta = refQpDelta2;<br>-                if (nonRefQpDelta2 > 0)<br>-                    p->bwdNonRefQpDelta = nonRefQpDelta2;<br>+                if (6 == sscanf(value, "%d,%lf,%lf,%d,%lf,%lf", &window1, &refQpDelta1, &nonRefQpDelta1, &window2, &refQpDelta2, &nonRefQpDelta2))<br>+                {<br>+                    if (window1 > 0)<br>+                        p->fwdScenecutWindow = window1;<br>+                    if (refQpDelta1 > 0)<br>+                        p->fwdRefQpDelta = refQpDelta1;<br>+                    if (nonRefQpDelta1 > 0)<br>+                        p->fwdNonRefQpDelta = nonRefQpDelta1;<br>+                    if (window2 > 0)<br>+                        p->bwdScenecutWindow = window2;<br>+                    if (refQpDelta2 > 0)<br>+                        p->bwdRefQpDelta = refQpDelta2;<br>+                    if (nonRefQpDelta2 > 0)<br>+                        p->bwdNonRefQpDelta = nonRefQpDelta2;<br>+                }<br>+                else<br>+                {<br>+                    x265_log(NULL, X265_LOG_ERROR, "Specify all the necessary offsets for masking-strength \n");<br>+                    bError = true;<br>+                }<br>             }<br>         }<br>         OPT("field") p->bField = atobool( value );<br>diff --git a/source/encoder/ratecontrol.cpp b/source/encoder/ratecontrol.cpp<br>index 1b46c0148..a4756de39 100644<br>--- a/source/encoder/ratecontrol.cpp<br>+++ b/source/encoder/ratecontrol.cpp<br>@@ -3193,9 +3193,8 @@ double RateControl::forwardMasking(Frame* curFrame, double q)<br>     double fwdRefQpDelta = double(m_param->fwdRefQpDelta);<br>     double fwdNonRefQpDelta = double(m_param->fwdNonRefQpDelta);<br>     double sliceTypeDelta = SLICE_TYPE_DELTA * fwdRefQpDelta;<br>-    double window2Delta = WINDOW2_DELTA * fwdRefQpDelta;<br>-    double window3Delta = WINDOW3_DELTA * fwdRefQpDelta;<br> <br>+    //Check whether the current frame is within the forward window<br>     if (curFrame->m_poc > lastScenecut && curFrame->m_poc <= (lastScenecut + int(maxWindowSize)))<br>         curFrame->m_isInsideWindow = FORWARD_WINDOW;<br>     if (curFrame->m_isInsideWindow == FORWARD_WINDOW)<br>@@ -3209,11 +3208,13 @@ double RateControl::forwardMasking(Frame* curFrame, double q)<br>             if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut + int(maxWindowSize))<br>                 && curFrame->m_poc >= lastIFrame))<br>             {<br>-                qp += fwdRefQpDelta - sliceTypeDelta;<br>-                if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>-                    qp -= window2Delta;<br>+                //Add offsets corresponding to the window in which the P-frame occurs<br>+                if (curFrame->m_poc <= (lastScenecut + int(windowSize)))<br>+                    qp += WINDOW1_DELTA * (fwdRefQpDelta - sliceTypeDelta);<br>+                else if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>+                    qp += WINDOW2_DELTA * (fwdRefQpDelta - sliceTypeDelta);<br>                 else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))<br>-                    qp -= window3Delta;<br>+                    qp += WINDOW3_DELTA * (fwdRefQpDelta - sliceTypeDelta);<br>             }<br>         }<br>         else if (curFrame->m_lowres.sliceType == X265_TYPE_BREF)<br>@@ -3221,11 +3222,13 @@ double RateControl::forwardMasking(Frame* curFrame, double q)<br>             if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut + int(maxWindowSize))<br>                 && curFrame->m_poc >= lastIFrame))<br>             {<br>-                qp += fwdRefQpDelta;<br>-                if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>-                    qp -= window2Delta;<br>+                //Add offsets corresponding to the window in which the B-frame occurs<br>+                if (curFrame->m_poc <= (lastScenecut + int(windowSize)))<br>+                    qp += WINDOW1_DELTA * fwdRefQpDelta;<br>+                else if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>+                    qp += WINDOW2_DELTA * fwdRefQpDelta;<br>                 else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))<br>-                    qp -= window3Delta;<br>+                    qp += WINDOW3_DELTA * fwdRefQpDelta;<br>             }<br>         }<br>         else if (curFrame->m_lowres.sliceType == X265_TYPE_B)<br>@@ -3233,11 +3236,13 @@ double RateControl::forwardMasking(Frame* curFrame, double q)<br>             if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut + int(maxWindowSize))<br>                 && curFrame->m_poc >= lastIFrame))<br>             {<br>-                qp += fwdNonRefQpDelta;<br>-                if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>-                    qp -= window2Delta;<br>+                //Add offsets corresponding to the window in which the b-frame occurs<br>+                if (curFrame->m_poc <= (lastScenecut + int(windowSize)))<br>+                    qp += WINDOW1_DELTA * fwdNonRefQpDelta;<br>+                else if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))<br>+                    qp += WINDOW2_DELTA * fwdNonRefQpDelta;<br>                 else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))<br>-                    qp -= window3Delta;<br>+                    qp += WINDOW3_DELTA * fwdNonRefQpDelta;<br>             }<br>         }<br>     }<br>@@ -3248,14 +3253,13 @@ double RateControl::backwardMasking(Frame* curFrame, double q)<br> {<br>     double qp = x265_qScale2qp(q);<br>     double fwdRefQpDelta = double(m_param->fwdRefQpDelta);<br>-    double window3Delta = WINDOW3_DELTA * fwdRefQpDelta;<br>     double bwdRefQpDelta = double(m_param->bwdRefQpDelta);<br>     double bwdNonRefQpDelta = double(m_param->bwdNonRefQpDelta);<br> <br>     if (curFrame->m_isInsideWindow == BACKWARD_WINDOW)<br>     {<br>         if (bwdRefQpDelta < 0)<br>-            bwdRefQpDelta = fwdRefQpDelta - window3Delta;<br>+            bwdRefQpDelta = WINDOW3_DELTA * fwdRefQpDelta;<br>         double sliceTypeDelta = SLICE_TYPE_DELTA * bwdRefQpDelta;<br>         if (bwdNonRefQpDelta < 0)<br>             bwdNonRefQpDelta = bwdRefQpDelta + sliceTypeDelta;<br>diff --git a/source/encoder/ratecontrol.h b/source/encoder/ratecontrol.h<br>index 148269b6f..996465eeb 100644<br>--- a/source/encoder/ratecontrol.h<br>+++ b/source/encoder/ratecontrol.h<br>@@ -47,9 +47,9 @@ struct SPS;<br> #define CLIP_DURATION(f) x265_clip3(MIN_FRAME_DURATION, MAX_FRAME_DURATION, f)<br> <br> /*Scenecut Aware QP*/<br>-#define WINDOW1_DELTA           0   /* The offset for the frames coming in the window-1*/<br>-#define WINDOW2_DELTA           0.3 /* The offset for the frames coming in the window-2*/<br>-#define WINDOW3_DELTA           0.6 /* The offset for the frames coming in the window-3*/<br>+#define WINDOW1_DELTA           1.0 /* The offset for the frames coming in the window-1*/<br>+#define WINDOW2_DELTA           0.7 /* The offset for the frames coming in the window-2*/<br>+#define WINDOW3_DELTA           0.4 /* The offset for the frames coming in the window-3*/<br> <br> struct Predictor<br> {<br>-- <br>2.18.0.windows.1<br><br><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif"><br></font></div><div dir="ltr"><font color="#0c343d" face="verdana, sans-serif">Thanks & Regards</font><div><font color="#0c343d" face="verdana, sans-serif"><b>Niranjan Kumar B</b></font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Video Codec Engineer </font></div><div><font size="1" color="#0c343d" face="verdana, sans-serif">Media & AI Analytics</font></div><div><font face="trebuchet ms, sans-serif" color="#0c343d">+91 958 511 1449</font></div><div><a href="https://multicorewareinc.com/" style="color:rgb(17,85,204)" target="_blank"><img src="https://docs.google.com/uc?export=download&id=1kc3RJu9M8bnIf6Xa5rUw2d-eEVUsPBE5&revid=0B7tw9XJBmynaemR1VUpQUi9DVytRVW5SVkRwVTFjb1hBMUcwPQ"></a></div></div></div></div></div></div></div></div>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org" target="_blank">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font face="georgia, serif">Regards,</font><div><b><font face="georgia, serif">Aruna Matheswaran,</font></b></div><div><font face="georgia, serif">Video Codec Engineer,</font></div><div><font face="georgia, serif">Media & AI analytics BU,</font></div><div><span><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><span style="border:none;display:inline-block;overflow:hidden;width:153px;height:58px"><img src="https://lh5.googleusercontent.com/gjX5cPNIZgwUrhfqkTwQUZWztIKmmo0qs3kbwvkS5H-bDVE2ftte9pMTVnFLSjOcjYWLtfc6_OGpxW4vraLg2r5QAIf1Q3MpldFDgWtzK_gXi8ptw5B3joIbsGL6mxj-JRdjHzT5" width="96" height="36" style="margin-left: 0px; margin-top: 0px;"></span></span></span><font face="georgia, serif"><br></font></div><div><span><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><span style="border:none;display:inline-block;overflow:hidden;width:153px;height:58px"><img src="https://lh5.googleusercontent.com/gjX5cPNIZgwUrhfqkTwQUZWztIKmmo0qs3kbwvkS5H-bDVE2ftte9pMTVnFLSjOcjYWLtfc6_OGpxW4vraLg2r5QAIf1Q3MpldFDgWtzK_gXi8ptw5B3joIbsGL6mxj-JRdjHzT5" style="margin-left: 0px; margin-top: 0px;"></span></span></span><font face="georgia, serif"><br></font></div><div><font face="georgia, serif"><br></font></div></div></div></div></div></div></div></div></div>