[x265] [PATCH] Enable --scenecut-aware-qp with --crf in pass 2

Niranjan Bala niranjan at multicorewareinc.com
Tue Jul 13 14:00:05 UTC 2021


>From c833d87574e219aeb85409ec8897bc1047dd73fc Mon Sep 17 00:00:00 2001
From: Niranjan <niranjan at multicorewareinc.com>
Date: Thu, 25 Mar 2021 12:07:30 +0530
Subject: [PATCH] 1)Enable --scenecut-aware-qp with --crf in pass 2
2)Increased
 qpDelta limit to 20 3)Fix: Access violation when aqMode=0 + qgSize=8

---
 source/common/lowres.cpp       |  2 +-
 source/common/param.cpp        | 16 ++++++++--------
 source/encoder/ratecontrol.cpp | 10 ++++++++++
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/source/common/lowres.cpp b/source/common/lowres.cpp
index 578981d64..334640ec9 100644
--- a/source/common/lowres.cpp
+++ b/source/common/lowres.cpp
@@ -73,7 +73,7 @@ bool Lowres::create(x265_param* param, PicYuv *origPic,
uint32_t qgSize)

     size_t planesize = lumaStride * (lines + 2 * origPic->m_lumaMarginY);
     size_t padoffset = lumaStride * origPic->m_lumaMarginY +
origPic->m_lumaMarginX;
-    if (!!param->rc.aqMode || !!param->rc.hevcAq || !!param->bAQMotion)
+    if (!!param->rc.aqMode || !!param->rc.hevcAq || !!param->bAQMotion ||
!!param->bEnableWeightedPred || !!param->bEnableWeightedBiPred)
     {
         CHECKED_MALLOC_ZERO(qpAqOffset, double, cuCountFullRes);
         CHECKED_MALLOC_ZERO(invQscaleFactor, int, cuCountFullRes);
diff --git a/source/common/param.cpp b/source/common/param.cpp
index fb74d759b..2800c45f7 100755
--- a/source/common/param.cpp
+++ b/source/common/param.cpp
@@ -1858,17 +1858,17 @@ int x265_check_params(x265_param* param)
             "Invalid masking direction. Value must be between 0 and
3(inclusive)");
             CHECK(param->fwdScenecutWindow < 0 || param->fwdScenecutWindow
> 1000,
             "Invalid forward scenecut Window duration. Value must be
between 0 and 1000(inclusive)");
-            CHECK(param->fwdRefQpDelta < 0 || param->fwdRefQpDelta > 10,
-            "Invalid fwdRefQpDelta value. Value must be between 0 and 10
(inclusive)");
-            CHECK(param->fwdNonRefQpDelta < 0 || param->fwdNonRefQpDelta >
10,
-            "Invalid fwdNonRefQpDelta value. Value must be between 0 and
10 (inclusive)");
+            CHECK(param->fwdRefQpDelta < 0 || param->fwdRefQpDelta > 20,
+            "Invalid fwdRefQpDelta value. Value must be between 0 and 20
(inclusive)");
+            CHECK(param->fwdNonRefQpDelta < 0 || param->fwdNonRefQpDelta >
20,
+            "Invalid fwdNonRefQpDelta value. Value must be between 0 and
20 (inclusive)");

             CHECK(param->bwdScenecutWindow < 0 || param->bwdScenecutWindow
> 1000,
                 "Invalid backward scenecut Window duration. Value must be
between 0 and 1000(inclusive)");
-            CHECK(param->bwdRefQpDelta < -1 || param->bwdRefQpDelta > 10,
-                "Invalid bwdRefQpDelta value. Value must be between 0 and
10 (inclusive)");
-            CHECK(param->bwdNonRefQpDelta < -1 || param->bwdNonRefQpDelta
> 10,
-                "Invalid bwdNonRefQpDelta value. Value must be between 0
and 10 (inclusive)");
+            CHECK(param->bwdRefQpDelta < -1 || param->bwdRefQpDelta > 20,
+                "Invalid bwdRefQpDelta value. Value must be between 0 and
20 (inclusive)");
+            CHECK(param->bwdNonRefQpDelta < -1 || param->bwdNonRefQpDelta
> 20,
+                "Invalid bwdNonRefQpDelta value. Value must be between 0
and 20 (inclusive)");
         }
     }
     if (param->bEnableHME)
diff --git a/source/encoder/ratecontrol.cpp b/source/encoder/ratecontrol.cpp
index a4756de39..9c7b6132b 100644
--- a/source/encoder/ratecontrol.cpp
+++ b/source/encoder/ratecontrol.cpp
@@ -1394,6 +1394,16 @@ int RateControl::rateControlStart(Frame* curFrame,
RateControlEntry* rce, Encode
     if (!m_isAbr && m_2pass && m_param->rc.rateControlMode == X265_RC_CRF)
     {
         rce->qpPrev = x265_qScale2qp(rce->qScale);
+        if (m_param->bEnableSceneCutAwareQp)
+        {
+            double lqmin = m_lmin[m_sliceType];
+            double lqmax = m_lmax[m_sliceType];
+            if (m_param->bEnableSceneCutAwareQp & FORWARD)
+                rce->newQScale = forwardMasking(curFrame, rce->newQScale);
+            if (m_param->bEnableSceneCutAwareQp & BACKWARD)
+                rce->newQScale = backwardMasking(curFrame, rce->newQScale);
+            rce->newQScale = x265_clip3(lqmin, lqmax, rce->newQScale);
+        }
         rce->qScale = rce->newQScale;
         rce->qpaRc = curEncData.m_avgQpRc = curEncData.m_avgQpAq =
x265_qScale2qp(rce->newQScale);
         m_qp = int(rce->qpaRc + 0.5);
-- 
2.18.0.windows.1


-- 

Thanks & Regards
*Niranjan Kumar B*
Video Codec Engineer
Media & AI Analytics
+91 958 511 1449
<https://multicorewareinc.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20210713/33a4acca/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265.diff
Type: application/octet-stream
Size: 4502 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20210713/33a4acca/attachment.obj>


More information about the x265-devel mailing list