[x265-commits] [x265] common: tune-ssim sets aqmode as AUTO_VARIANCE (2). Gives...

Deepthi Nandakumar deepthi at multicorewareinc.com
Mon Jan 6 17:31:58 CET 2014


details:   http://hg.videolan.org/x265/rev/c561cd778ef5
branches:  
changeset: 5786:c561cd778ef5
user:      Deepthi Nandakumar <deepthi at multicorewareinc.com>
date:      Mon Dec 30 16:06:13 2013 +0530
description:
common: tune-ssim sets aqmode as AUTO_VARIANCE (2). Gives higher ssim.
Subject: [x265] rc: bug fix to improve quality for the first I frame.

details:   http://hg.videolan.org/x265/rev/c86f18d7eb2a
branches:  
changeset: 5787:c86f18d7eb2a
user:      Aarthi Thirumalai
date:      Mon Dec 30 16:24:21 2013 +0530
description:
rc: bug fix to improve quality for the first I frame.
Subject: [x265] Moving macro to header

details:   http://hg.videolan.org/x265/rev/f5427379b40d
branches:  
changeset: 5788:f5427379b40d
user:      Shazeb Nawaz Khan <shazeb at multicorewareinc.com>
date:      Mon Dec 30 17:51:24 2013 +0530
description:
Moving macro to header
Subject: [x265] Importing x264 weight analysis to encoder

details:   http://hg.videolan.org/x265/rev/affdfa4b5537
branches:  
changeset: 5789:affdfa4b5537
user:      Shazeb Nawaz Khan <shazeb at multicorewareinc.com>
date:      Mon Dec 30 17:53:03 2013 +0530
description:
Importing x264 weight analysis to encoder
Subject: [x265] Integrating new weight analysis in encoder

details:   http://hg.videolan.org/x265/rev/dcae0b69d9b3
branches:  
changeset: 5790:dcae0b69d9b3
user:      Shazeb Nawaz Khan <shazeb at multicorewareinc.com>
date:      Mon Dec 30 17:54:29 2013 +0530
description:
Integrating new weight analysis in encoder
Subject: [x265] Backed out changeset: revert to HM-based weightP

details:   http://hg.videolan.org/x265/rev/8137881d4cad
branches:  
changeset: 5791:8137881d4cad
user:      Deepthi Nandakumar <deepthi at multicorewareinc.com>
date:      Thu Jan 02 16:18:35 2014 +0530
description:
Backed out changeset: revert to HM-based weightP
Subject: [x265] y4m: use loop to skip frames, avoid 32bit size wrap problems

details:   http://hg.videolan.org/x265/rev/f96c85f03b77
branches:  
changeset: 5792:f96c85f03b77
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 03 12:22:38 2014 -0600
description:
y4m: use loop to skip frames, avoid 32bit size wrap problems
Subject: [x265] fix every execute output different bitstream when SAO enabled

details:   http://hg.videolan.org/x265/rev/99f28c405b5c
branches:  
changeset: 5793:99f28c405b5c
user:      Min Chen <chenm003 at 163.com>
date:      Mon Jan 06 13:41:18 2014 +0800
description:
fix every execute output different bitstream when SAO enabled

diffstat:

 source/common/common.cpp            |    2 +-
 source/encoder/CMakeLists.txt       |    3 +-
 source/encoder/frameencoder.cpp     |    6 +-
 source/encoder/ratecontrol.cpp      |   37 +-
 source/encoder/slicetype.cpp        |    8 -
 source/encoder/slicetype.h          |    8 +
 source/encoder/weightPrediction.cpp |  386 ++++++++++++++++++++++++++++++++++++
 source/encoder/weightPrediction.h   |   92 ++++++++
 source/input/y4m.cpp                |   15 +-
 9 files changed, 518 insertions(+), 39 deletions(-)

diffs (truncated from 646 to 300 lines):

diff -r 964e5bc90ad2 -r 99f28c405b5c source/common/common.cpp
--- a/source/common/common.cpp	Fri Dec 27 23:07:06 2013 +0530
+++ b/source/common/common.cpp	Mon Jan 06 13:41:18 2014 +0800
@@ -404,7 +404,7 @@ int x265_param_default_preset(x265_param
         }
         else if (!strcmp(tune, "ssim"))
         {
-            /* Current Default: Do nothing */
+            param->rc.aqMode = X265_AQ_AUTO_VARIANCE;
         }
         else if (!strcmp(tune, "zero-latency"))
         {
diff -r 964e5bc90ad2 -r 99f28c405b5c source/encoder/CMakeLists.txt
--- a/source/encoder/CMakeLists.txt	Fri Dec 27 23:07:06 2013 +0530
+++ b/source/encoder/CMakeLists.txt	Mon Jan 06 13:41:18 2014 +0800
@@ -69,4 +69,5 @@ add_library(encoder OBJECT ../x265.h
     ratecontrol.cpp ratecontrol.h
     compress.cpp
     reference.cpp reference.h
-    encoder.cpp encoder.h)
+    encoder.cpp encoder.h
+    weightPrediction.cpp weightPrediction.h)
diff -r 964e5bc90ad2 -r 99f28c405b5c source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Dec 27 23:07:06 2013 +0530
+++ b/source/encoder/frameencoder.cpp	Mon Jan 06 13:41:18 2014 +0800
@@ -342,8 +342,6 @@ void FrameEncoder::setLambda(int qp, int
     m_rows[row].m_rdCost.setLambda(lambda);
     m_rows[row].m_rdCost.setCbDistortionWeight(cbWeight);
     m_rows[row].m_rdCost.setCrDistortionWeight(crWeight);
-    m_frameFilter.m_sao.lumaLambda = lambda;
-    m_frameFilter.m_sao.chromaLambda = chromaLambda;
 }
 
 void FrameEncoder::compressFrame()
@@ -377,6 +375,10 @@ void FrameEncoder::compressFrame()
     double crWeight = pow(2.0, (qp - g_chromaScale[qpc])); // takes into account of the chroma qp mapping and chroma qp Offset
     double chromaLambda = lambda / crWeight;
 
+    // NOTE: set SAO lambda every Frame
+    m_frameFilter.m_sao.lumaLambda = lambda;
+    m_frameFilter.m_sao.chromaLambda = chromaLambda;
+
     TComPicYuv *fenc = slice->getPic()->getPicYuvOrg();
     for (int i = 0; i < m_numRows; i++)
     {
diff -r 964e5bc90ad2 -r 99f28c405b5c source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Fri Dec 27 23:07:06 2013 +0530
+++ b/source/encoder/ratecontrol.cpp	Mon Jan 06 13:41:18 2014 +0800
@@ -495,30 +495,29 @@ double RateControl::rateEstimateQscale(R
             q = qp2qScale(accumPQp / accumPNorm);
             q /= fabs(cfg->param.rc.ipFactor);
         }
-        else if (framesDone > 0)
+
+        if (cfg->param.rc.rateControlMode != X265_RC_CRF)
         {
-            if (cfg->param.rc.rateControlMode != X265_RC_CRF)
+            double lqmin = 0, lqmax = 0;
+            if (totalBits == 0)
             {
-                double lqmin = 0, lqmax = 0;
-                if (totalBits == 0)
-                {
-                    lqmin = qp2qScale(ABR_INIT_QP_MIN) / lstep;
-                    lqmax = qp2qScale(ABR_INIT_QP_MAX) * lstep;
-                }
-                else
-                {
-                    lqmin = lastQScaleFor[sliceType] / lstep;
-                    lqmax = lastQScaleFor[sliceType] * lstep;
-                }
+                lqmin = qp2qScale(ABR_INIT_QP_MIN) / lstep;
+                lqmax = qp2qScale(ABR_INIT_QP_MAX) * lstep;
+            }
+            else
+            {
+                lqmin = lastQScaleFor[sliceType] / lstep;
+                lqmax = lastQScaleFor[sliceType] * lstep;
+            }
 
-                if (overflow > 1.1 && framesDone > 3)
-                    lqmax *= lstep;
-                else if (overflow < 0.9)
-                    lqmin /= lstep;
+            if (overflow > 1.1 && framesDone > 3)
+                lqmax *= lstep;
+            else if (overflow < 0.9)
+                lqmin /= lstep;
 
-                q = Clip3(lqmin, lqmax, q);
-            }
+            q = Clip3(lqmin, lqmax, q);
         }
+
         else if (cfg->param.rc.rateControlMode == X265_RC_CRF && qCompress != 1)
         {
             q = qp2qScale(ABR_INIT_QP) / fabs(cfg->param.rc.ipFactor);
diff -r 964e5bc90ad2 -r 99f28c405b5c source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Fri Dec 27 23:07:06 2013 +0530
+++ b/source/encoder/slicetype.cpp	Mon Jan 06 13:41:18 2014 +0800
@@ -46,14 +46,6 @@
 
 using namespace x265;
 
-#define SET_WEIGHT(w, b, s, d, o) \
-    { \
-        (w).inputWeight = (s); \
-        (w).log2WeightDenom = (d); \
-        (w).inputOffset = (o); \
-        (w).bPresentFlag = b; \
-    }
-
 static inline int16_t median(int16_t a, int16_t b, int16_t c)
 {
     int16_t t = (a - b) & ((a - b) >> 31);
diff -r 964e5bc90ad2 -r 99f28c405b5c source/encoder/slicetype.h
--- a/source/encoder/slicetype.h	Fri Dec 27 23:07:06 2013 +0530
+++ b/source/encoder/slicetype.h	Mon Jan 06 13:41:18 2014 +0800
@@ -35,6 +35,14 @@ struct Lowres;
 class TComPic;
 class TEncCfg;
 
+#define SET_WEIGHT(w, b, s, d, o) \
+    { \
+        (w).inputWeight = (s); \
+        (w).log2WeightDenom = (d); \
+        (w).inputOffset = (o); \
+        (w).bPresentFlag = b; \
+    }
+
 struct LookaheadRow
 {
     Lock                lock;
diff -r 964e5bc90ad2 -r 99f28c405b5c source/encoder/weightPrediction.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/encoder/weightPrediction.cpp	Mon Jan 06 13:41:18 2014 +0800
@@ -0,0 +1,386 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Author: Shazeb Nawaz Khan <shazeb at multicorewareinc.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at multicorewareinc.com.
+ *****************************************************************************/
+
+#include "TLibCommon/TComPic.h"
+#include "lowres.h"
+#include "mv.h"
+#include "slicetype.h"
+#include "weightPrediction.h"
+
+using namespace x265;
+
+void WeightPrediction::mcChroma()
+{
+    intptr_t strd = 8;
+
+    strd = m_refStride;
+    int pixoff = 0;
+    int cu = 0;
+    pixel *temp;
+    int partEnum = CHROMA_8x8;
+
+    for (int y = 0; y < frmHeight; y += blockSize, pixoff = y * m_refStride)
+    {
+        for (int x = 0; x < frmWidth; x += blockSize, pixoff += blockSize, cu++)
+        {
+            if (m_mvCost[cu] < m_intraCost[cu])
+            {
+                MV mv(mvs[cu]);
+                int refOffset = (mv.x >> (3 - m_csp444)) + (mv.y >> (3 - m_csp444)) * (int)m_refStride;
+                temp = mcbuf + refOffset + pixoff;
+
+                int xFrac = mv.x & 0x7;
+                int yFrac = mv.y & 0x7;
+
+                if ((yFrac | xFrac) == 0)
+                {
+                    primitives.chroma[m_csp].copy_pp[partEnum](buf + pixoff, m_refStride, temp, strd);
+                }
+                else if (yFrac == 0)
+                {
+                    primitives.chroma[m_csp].filter_hpp[partEnum](temp, strd, buf + pixoff, m_refStride, xFrac);
+                }
+                else if (xFrac == 0)
+                {
+                    primitives.chroma[m_csp].filter_vpp[partEnum](temp, strd, buf + pixoff, m_refStride, yFrac);
+                }
+                else
+                {
+                    uint32_t cxWidth = blockSize;
+                    uint32_t cxHeight = blockSize;
+                    int16_t *immedVal = (int16_t*)X265_MALLOC(int16_t, 64 * (64 + NTAPS_LUMA - 1));
+                    int extStride = cxWidth;
+                    int filterSize = NTAPS_CHROMA;
+                    int halfFilterSize = (filterSize >> 1);
+
+                    primitives.chroma[m_csp].filter_hps[partEnum](temp, strd, immedVal, extStride, xFrac, 1);
+                    primitives.chroma_vsp(immedVal + (halfFilterSize - 1) * extStride, extStride, buf + pixoff, m_refStride, cxWidth, cxHeight, yFrac);
+
+                    X265_FREE(immedVal);
+                }
+            }
+            else
+            {
+                primitives.chroma[m_csp].copy_pp[partEnum](buf + pixoff, m_refStride, mcbuf + pixoff, m_refStride);
+            }
+        }
+    }
+
+    mcbuf = buf;
+}
+
+uint32_t WeightPrediction::weightCost(pixel *cur, pixel *ref, wpScalingParam *w)
+{
+    int stride = m_refStride;
+    pixel *temp = (pixel*)X265_MALLOC(pixel, frmWidth * frmHeight);
+    bool nonBorderCU;
+
+    if (w)
+    {
+        int offset = w->inputOffset << (X265_DEPTH - 8);
+        int scale = w->inputWeight;
+        int denom = w->log2WeightDenom;
+        int correction = IF_INTERNAL_PREC - X265_DEPTH;
+
+        // Adding (IF_INTERNAL_PREC - X265_DEPTH) to cancel effect of pixel to short conversion inside the primitive
+        primitives.weight_pp(ref, temp, m_refStride, m_dstStride, frmWidth, frmHeight,
+                             scale, (1 << (denom - 1 + correction)), denom + correction, offset);
+        ref = temp;
+        stride = m_dstStride;
+    }
+
+    int32_t cost = 0;
+    int pixoff = 0;
+    int mb = 0;
+    int count = 0;
+    for (int y = 0; y < frmHeight; y += 8, pixoff = y * m_refStride)
+    {
+        for (int x = 0; x < frmWidth; x += 8, mb++, pixoff += 8)
+        {
+            nonBorderCU = (x > 0) && (x < frmWidth - 8 - 1) && (y > 0) && (y < frmHeight - 8 - 1);
+            if (nonBorderCU)
+            {
+                if (mvs)
+                {
+                    if (m_mvCost[mb] < m_intraCost[mb])
+                    {
+                        int satd = primitives.satd[LUMA_8x8](ref + (stride * y) + x, stride, cur + pixoff, m_refStride);
+                        cost += satd;
+                        count++;
+                    }
+                }
+                else
+                {
+                    int satd = primitives.satd[LUMA_8x8](ref + (stride * y) + x, stride, cur + pixoff, m_refStride);
+                    cost += satd;
+                }
+            }
+        }
+    }
+
+    X265_FREE(temp);
+    x265_emms();
+    return cost;
+}
+
+void WeightPrediction::weightAnalyseEnc()
+{
+    wpScalingParam w, *fw;
+    Lowres *fenc, *ref;
+
+    fenc = &slice->getPic()->m_lowres;
+    int numPredDir = slice->isInterP() ? 1 : 2;
+    int curPoc, refPoc, difPoc;
+    curPoc = slice->getPOC();
+    int check;
+    int fullCheck = 0;
+    int lumaDenom = 0;
+    int numWeighted = 0;                     // number of weighted references for each slice must be less than 8 as per HEVC standard
+    int width[3], height[3];
+    // Rounding the width, height to 16
+    width[0]  = ((slice->getPic()->getPicYuvOrg()->getWidth() + 8) >> 4) << 4;
+    height[0] = ((slice->getPic()->getPicYuvOrg()->getHeight() + 8) >> 4) << 4;
+    width[2] = width[1] = width[0] >> 1;


More information about the x265-commits mailing list