[x265] [PATCH 3 of 3] cuDeltaQP: consider only bits to decide better QP in RD refinement

kavitha at multicorewareinc.com kavitha at multicorewareinc.com
Thu Dec 22 10:59:20 CET 2016


# HG changeset patch
# User Kavitha Sampath <kavitha at multicorewareinc.com>
# Date 1482316798 -19800
#      Wed Dec 21 16:09:58 2016 +0530
# Node ID 8a4a09eda95550835b76241ea15bf3444dc105d5
# Parent  f1b91c4f65a3a5069d326d422134080a5484d540
cuDeltaQP: consider only bits to decide better QP in RD refinement

Also update test commandlines to support opt-cu-delta-qp option

diff -r f1b91c4f65a3 -r 8a4a09eda955 source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp	Sun Dec 18 16:19:40 2016 +0530
+++ b/source/encoder/analysis.cpp	Wed Dec 21 16:09:58 2016 +0530
@@ -86,6 +86,7 @@
     for (uint32_t i = 1; i <= maxDQPDepth; i++)
         costArrSize += (1 << (i * 2));
     cacheCost = X265_MALLOC(uint64_t, costArrSize);
+    m_bestCUBits = X265_MALLOC(uint32_t, costArrSize);
 
     int csp = m_param->internalCsp;
     uint32_t cuSize = g_maxCUSize;
@@ -126,6 +127,7 @@
         }
     }
     X265_FREE(cacheCost);
+    X265_FREE(m_bestCUBits);
 }
 
 Mode& Analysis::compressCTU(CUData& ctu, Frame& frame, const CUGeom& cuGeom, const Entropy& initialContext)
@@ -299,7 +301,7 @@
 
         int cuIdx = (cuGeom.childOffset - 1) / 3;
         bestCUCost = origCUCost = cacheCost[cuIdx];
-
+        uint32_t bestCUBits = m_bestCUBits[cuIdx];
         int direction = m_param->bOptCUDeltaQP ? 1 : 2;
 
         for (int dir = direction; dir >= -direction; dir -= (direction * 2))
@@ -320,7 +322,27 @@
                 recodeCU(parentCTU, cuGeom, modCUQP, qp);
                 cuCost = md.bestMode->rdCost;
 
-                COPY2_IF_LT(bestCUCost, cuCost, bestCUQP, modCUQP);
+                if (m_param->bOptCUDeltaQP)
+                {
+                    bool cpyBest = false;
+                    if (cuCost > bestCUCost)
+                    {
+                        if (md.bestMode->totalBits < bestCUBits)
+                            cpyBest = true;
+                    }
+                    else
+                        cpyBest = true;
+
+                    if (cpyBest)
+                    {
+                        bestCUQP = modCUQP;
+                        bestCUCost = cuCost;
+                        bestCUBits = md.bestMode->totalBits;
+                    }
+                }
+                else
+                    COPY2_IF_LT(bestCUCost, cuCost, bestCUQP, modCUQP);
+
                 if (cuCost < cuPrevCost)
                     failure = 0;
                 else
@@ -448,10 +470,11 @@
         checkBestMode(*splitPred, depth);
     }
 
-    if (m_param->bEnableRdRefine && depth <= m_slice->m_pps->maxCuDQPDepth)
+    if ((m_param->bEnableRdRefine || m_param->bOptCUDeltaQP) && depth <= m_slice->m_pps->maxCuDQPDepth)
     {
         int cuIdx = (cuGeom.childOffset - 1) / 3;
         cacheCost[cuIdx] = md.bestMode->rdCost;
+        m_bestCUBits[cuIdx] = md.bestMode->totalBits;
     }
 
     /* Save Intra CUs TU depth only when analysis mode is OFF */
@@ -1875,10 +1898,11 @@
     if (mightSplit && !skipRecursion)
         checkBestMode(md.pred[PRED_SPLIT], depth);
 
-    if (m_param->bEnableRdRefine && depth <= m_slice->m_pps->maxCuDQPDepth)
+    if ((m_param->bEnableRdRefine || m_param->bOptCUDeltaQP) && depth <= m_slice->m_pps->maxCuDQPDepth)
     {
         int cuIdx = (cuGeom.childOffset - 1) / 3;
         cacheCost[cuIdx] = md.bestMode->rdCost;
+        m_bestCUBits[cuIdx] = md.bestMode->totalBits;
     }
 
        /* determine which motion references the parent CU should search */
diff -r f1b91c4f65a3 -r 8a4a09eda955 source/encoder/analysis.h
--- a/source/encoder/analysis.h	Sun Dec 18 16:19:40 2016 +0530
+++ b/source/encoder/analysis.h	Wed Dec 21 16:09:58 2016 +0530
@@ -129,6 +129,7 @@
 
     uint32_t             m_splitRefIdx[4];
     uint64_t*            cacheCost;
+    uint32_t*            m_bestCUBits;
 
     /* refine RD based on QP for rd-levels 5 and 6 */
     void qprdRefine(const CUData& parentCTU, const CUGeom& cuGeom, int32_t qp, int32_t lqp);
diff -r f1b91c4f65a3 -r 8a4a09eda955 source/test/regression-tests.txt
--- a/source/test/regression-tests.txt	Sun Dec 18 16:19:40 2016 +0530
+++ b/source/test/regression-tests.txt	Wed Dec 21 16:09:58 2016 +0530
@@ -71,6 +71,7 @@
 News-4k.y4m,--preset superfast --lookahead-slices 6 --aq-mode 0
 News-4k.y4m,--preset superfast --slices 4 --aq-mode 0 
 News-4k.y4m,--preset medium --tune ssim --no-sao --qg-size 16
+News-4k.y4m,--preset slower --opt-cu-delta-qp
 News-4k.y4m,--preset veryslow --no-rskip
 News-4k.y4m,--preset veryslow --pme --crf 40
 OldTownCross_1920x1080_50_10bit_422.yuv,--preset superfast --weightp
@@ -100,6 +101,7 @@
 city_4cif_60fps.y4m,--preset superfast --rdpenalty 1 --tu-intra-depth 2
 city_4cif_60fps.y4m,--preset medium --crf 4 --cu-lossless --sao-non-deblock
 city_4cif_60fps.y4m,--preset slower --scaling-list default
+city_4cif_60fps.y4m,--preset veryslow --opt-cu-delta-qp
 city_4cif_60fps.y4m,--preset veryslow --rdpenalty 2 --sao-non-deblock --no-b-intra --limit-refs 0
 ducks_take_off_420_720p50.y4m,--preset ultrafast --constrained-intra --rd 1
 ducks_take_off_444_720p50.y4m,--preset superfast --weightp --limit-refs 2
diff -r f1b91c4f65a3 -r 8a4a09eda955 source/test/smoke-tests.txt
--- a/source/test/smoke-tests.txt	Sun Dec 18 16:19:40 2016 +0530
+++ b/source/test/smoke-tests.txt	Wed Dec 21 16:09:58 2016 +0530
@@ -13,7 +13,7 @@
 old_town_cross_444_720p50.y4m,--preset=fast --keyint 20 --min-cu-size 16
 old_town_cross_444_720p50.y4m,--preset=slow --sao-non-deblock --pmode --qg-size 32
 RaceHorses_416x240_30_10bit.yuv,--preset=veryfast --max-tu-size 8
-RaceHorses_416x240_30_10bit.yuv,--preset=slower --bitrate 500 -F4 --rdoq-level 1
+RaceHorses_416x240_30_10bit.yuv,--preset=slower --bitrate 500 -F4 --rdoq-level 1 --opt-cu-delta-qp
 CrowdRun_1920x1080_50_10bit_444.yuv,--preset=ultrafast --constrained-intra --min-keyint 5 --keyint 10
 CrowdRun_1920x1080_50_10bit_444.yuv,--preset=medium --max-tu-size 16 --tu-inter-depth 2 --limit-tu 3
 DucksAndLegs_1920x1080_60_10bit_422.yuv,--preset=veryfast --min-cu 16


More information about the x265-devel mailing list