[x265-commits] [x265] slicetype: do not assume frames[] array has been initialized

Steve Borho steve at borho.org
Tue Apr 1 22:24:20 CEST 2014


details:   http://hg.videolan.org/x265/rev/7ce180ca05b3
branches:  
changeset: 6637:7ce180ca05b3
user:      Steve Borho <steve at borho.org>
date:      Mon Mar 31 18:19:24 2014 -0500
description:
slicetype: do not assume frames[] array has been initialized

slicetypeAnalyse() may not have been called, so use picture list[] instead
Subject: [x265] asm: fix build error caused by usage of 64-bit dependent register in Win32 versions

details:   http://hg.videolan.org/x265/rev/dd189fd26f47
branches:  
changeset: 6638:dd189fd26f47
user:      Nabajit Deka
date:      Tue Apr 01 15:45:44 2014 +0530
description:
asm: fix build error caused by usage of 64-bit dependent register in Win32 versions
Subject: [x265] slicetype: nits

details:   http://hg.videolan.org/x265/rev/6edc3ed24643
branches:  
changeset: 6639:6edc3ed24643
user:      Steve Borho <steve at borho.org>
date:      Mon Mar 31 21:02:09 2014 -0500
description:
slicetype: nits
Subject: [x265] frameencoder: lower log level of restart indicators

details:   http://hg.videolan.org/x265/rev/f8aa296d60c3
branches:  
changeset: 6640:f8aa296d60c3
user:      Steve Borho <steve at borho.org>
date:      Tue Apr 01 14:00:52 2014 -0500
description:
frameencoder: lower log level of restart indicators
Subject: [x265] weightb: add CLI options for explicit weightb [CHANGES OUTPUTS]

details:   http://hg.videolan.org/x265/rev/0206822d9fea
branches:  
changeset: 6641:0206822d9fea
user:      Kavitha Sampath <kavitha at multicorewareinc.com>
date:      Tue Apr 01 23:28:32 2014 +0530
description:
weightb: add CLI options for explicit weightb [CHANGES OUTPUTS]

weightB will be disabled by default for this release. This patch fixes the hash
mistakes and other fetaure bugs (the reasons it had been disabled)

HEVC only signals a single denom for all references so the L1 reference must use
the same denom as the L0 reference or no weight at all. A more exhaustive
search might be added later for slower presets. Also, the lookahead will need to
be modified to model weightB behavior so it can be more effective.

This patch changes how the unweighted references are coded, so even weightP
outputs change slightly.
Subject: [x265] Merge with default (feature freeze for 0.9)

details:   http://hg.videolan.org/x265/rev/1fc0fda2b08b
branches:  stable
changeset: 6642:1fc0fda2b08b
user:      Steve Borho <steve at borho.org>
date:      Tue Apr 01 15:22:01 2014 -0500
description:
Merge with default (feature freeze for 0.9)

diffstat:

 doc/reST/cli.rst                               |  13 ++++++++-
 source/Lib/TLibCommon/TComSlice.h              |   4 +-
 source/Lib/TLibCommon/TComWeightPrediction.cpp |  28 ++++++++----------
 source/common/param.cpp                        |   5 ++-
 source/common/x86/pixel-a.asm                  |   4 +-
 source/encoder/encoder.cpp                     |  27 +++++++++++++++++-
 source/encoder/encoder.h                       |   2 +
 source/encoder/frameencoder.cpp                |  14 +++++----
 source/encoder/ratecontrol.cpp                 |   4 +-
 source/encoder/slicetype.cpp                   |  11 ++++---
 source/encoder/weightPrediction.cpp            |  39 ++++++++++++++------------
 source/x265.cpp                                |   3 ++
 source/x265.h                                  |   5 +--
 13 files changed, 103 insertions(+), 56 deletions(-)

diffs (truncated from 533 to 300 lines):

diff -r 5d607fd4531f -r 1fc0fda2b08b doc/reST/cli.rst
--- a/doc/reST/cli.rst	Mon Mar 31 17:45:16 2014 -0500
+++ b/doc/reST/cli.rst	Tue Apr 01 15:22:01 2014 -0500
@@ -355,7 +355,18 @@ Temporal / motion search options
 
 .. option:: --weightp, -w, --no-weightp
 
-	Enable weighted prediction in P slices. Default enabled
+	Enable weighted prediction in P slices. This enables weighting
+	analysis in the lookahead, which influences slice decisions, and
+	enables weighting analysis in the main encoder which allows P
+	reference samples to have a weight function applied to them prior to
+	using them for motion compensation.  In video which has lighting
+	changes, it can give a large improvement in compression efficiency.
+	Default is enabled
+
+
+.. option:: --weightb, --no-weightb
+
+	Enable weighted prediction in B slices. Default disabled
 
 
 Spatial/intra options
diff -r 5d607fd4531f -r 1fc0fda2b08b source/Lib/TLibCommon/TComSlice.h
--- a/source/Lib/TLibCommon/TComSlice.h	Mon Mar 31 17:45:16 2014 -0500
+++ b/source/Lib/TLibCommon/TComSlice.h	Tue Apr 01 15:22:01 2014 -0500
@@ -1262,12 +1262,12 @@ typedef struct wpScalingParam
     int         w, o, offset, shift, round;
 
     /* makes a non-h265 weight (i.e. fix7), into an h265 weight */
-    void setFromWeightAndOffset(int weight, int _offset, int denom = 7)
+    void setFromWeightAndOffset(int weight, int _offset, int denom, bool bNormalize)
     {
         inputOffset = _offset;
         log2WeightDenom = denom;
         inputWeight = weight;
-        while (log2WeightDenom > 0 && (inputWeight > 127))
+        while (bNormalize && log2WeightDenom > 0 && (inputWeight > 127))
         {
             log2WeightDenom--;
             inputWeight >>= 1;
diff -r 5d607fd4531f -r 1fc0fda2b08b source/Lib/TLibCommon/TComWeightPrediction.cpp
--- a/source/Lib/TLibCommon/TComWeightPrediction.cpp	Mon Mar 31 17:45:16 2014 -0500
+++ b/source/Lib/TLibCommon/TComWeightPrediction.cpp	Tue Apr 01 15:22:01 2014 -0500
@@ -100,9 +100,9 @@ void TComWeightPrediction::addWeightBi(T
     {
         // Luma : --------------------------------------------
         int w0      = wp0[0].w;
-        int offset  = wp0[0].offset;
+        int offset  = wp0[0].o + wp1[0].o;
         int shiftNum = IF_INTERNAL_PREC - X265_DEPTH;
-        int shift   = wp0[0].shift + shiftNum;
+        int shift   = wp0[0].shift + shiftNum + 1;
         int round   = shift ? (1 << (shift - 1)) * bRound : 0;
         int w1      = wp1[0].w;
 
@@ -135,9 +135,9 @@ void TComWeightPrediction::addWeightBi(T
     {
         // Chroma U : --------------------------------------------
         int w0      = wp0[1].w;
-        int offset  = wp0[1].offset;
+        int offset  = wp0[1].o + wp1[1].o;
         int shiftNum = IF_INTERNAL_PREC - X265_DEPTH;
-        int shift   = wp0[1].shift + shiftNum;
+        int shift   = wp0[1].shift + shiftNum + 1;
         int round   = shift ? (1 << (shift - 1)) : 0;
         int w1      = wp1[1].w;
 
@@ -166,8 +166,8 @@ void TComWeightPrediction::addWeightBi(T
 
         // Chroma V : --------------------------------------------
         w0      = wp0[2].w;
-        offset  = wp0[2].offset;
-        shift   = wp0[2].shift + shiftNum;
+        offset  = wp0[2].o + wp1[2].o;;
+        shift   = wp0[2].shift + shiftNum + 1;
         round   = shift ? (1 << (shift - 1)) : 0;
         w1      = wp1[2].w;
 
@@ -223,9 +223,9 @@ void TComWeightPrediction::addWeightBi(S
     {
         // Luma : --------------------------------------------
         w0      = wp0[0].w;
-        offset  = wp0[0].offset;
+        offset  = wp0[0].o + wp1[0].o;
         shiftNum = IF_INTERNAL_PREC - X265_DEPTH;
-        shift   = wp0[0].shift + shiftNum;
+        shift   = wp0[0].shift + shiftNum + 1;
         round   = shift ? (1 << (shift - 1)) * bRound : 0;
         w1      = wp1[0].w;
 
@@ -258,9 +258,9 @@ void TComWeightPrediction::addWeightBi(S
     {
         // Chroma U : --------------------------------------------
         w0      = wp0[1].w;
-        offset  = wp0[1].offset;
+        offset  = wp0[1].o + wp1[1].o;
         shiftNum = IF_INTERNAL_PREC - X265_DEPTH;
-        shift   = wp0[1].shift + shiftNum;
+        shift   = wp0[1].shift + shiftNum + 1;
         round   = shift ? (1 << (shift - 1)) : 0;
         w1      = wp1[1].w;
 
@@ -289,8 +289,8 @@ void TComWeightPrediction::addWeightBi(S
 
         // Chroma V : --------------------------------------------
         w0      = wp0[2].w;
-        offset  = wp0[2].offset;
-        shift   = wp0[2].shift + shiftNum;
+        offset  = wp0[2].o + wp1[2].o;
+        shift   = wp0[2].shift + shiftNum + 1;
         round   = shift ? (1 << (shift - 1)) : 0;
         w1      = wp1[2].w;
 
@@ -539,10 +539,8 @@ void TComWeightPrediction::getWpScaling(
             wp0[yuv].o      = wp0[yuv].inputOffset * (1 << (X265_DEPTH - 8));
             wp1[yuv].w      = wp1[yuv].inputWeight;
             wp1[yuv].o      = wp1[yuv].inputOffset * (1 << (X265_DEPTH - 8));
-            wp0[yuv].offset = wp0[yuv].o + wp1[yuv].o;
-            wp0[yuv].shift  = wp0[yuv].log2WeightDenom + 1;
+            wp0[yuv].shift  = wp0[yuv].log2WeightDenom;
             wp0[yuv].round  = (1 << wp0[yuv].log2WeightDenom);
-            wp1[yuv].offset = wp0[yuv].offset;
             wp1[yuv].shift  = wp0[yuv].shift;
             wp1[yuv].round  = wp0[yuv].round;
         }
diff -r 5d607fd4531f -r 1fc0fda2b08b source/common/param.cpp
--- a/source/common/param.cpp	Mon Mar 31 17:45:16 2014 -0500
+++ b/source/common/param.cpp	Tue Apr 01 15:22:01 2014 -0500
@@ -583,6 +583,7 @@ int x265_param_parse(x265_param *p, cons
     }
     OPT("ref") p->maxNumReferences = atoi(value);
     OPT("weightp") p->bEnableWeightedPred = atobool(value);
+    OPT("weightb") p->bEnableWeightedBiPred = atobool(value);
     OPT("cbqpoffs") p->cbQpOffset = atoi(value);
     OPT("crqpoffs") p->crQpOffset = atoi(value);
     OPT("rd") p->rdLevel = atoi(value);
@@ -1080,7 +1081,8 @@ void x265_print_params(x265_param *param
         x265_log(param, X265_LOG_INFO, "RDpenalty                    : %d\n", param->rdPenalty);
     }
     x265_log(param, X265_LOG_INFO, "Lookahead / bframes / badapt        : %d / %d / %d\n", param->lookaheadDepth, param->bframes, param->bFrameAdaptive);
-    x265_log(param, X265_LOG_INFO, "b-pyramid / weightp / refs          : %d / %d / %d\n", param->bBPyramid, param->bEnableWeightedPred, param->maxNumReferences);
+    x265_log(param, X265_LOG_INFO, "b-pyramid / weightp / weightb / refs: %d / %d / %d / %d\n",
+             param->bBPyramid, param->bEnableWeightedPred, param->bEnableWeightedBiPred, param->maxNumReferences);
     switch (param->rc.rateControlMode)
     {
     case X265_RC_ABR:
@@ -1172,6 +1174,7 @@ char *x265_param2string(x265_param *p)
     s += sprintf(s, " b-adapt=%d", p->bFrameAdaptive);
     s += sprintf(s, " ref=%d", p->maxNumReferences);
     BOOL(p->bEnableWeightedPred, "weightp");
+    BOOL(p->bEnableWeightedBiPred, "weightb");
     s += sprintf(s, " bitrate=%d", p->rc.bitrate);
     s += sprintf(s, " qp=%d", p->rc.qp);
     s += sprintf(s, " aq-mode=%d", p->rc.aqMode);
diff -r 5d607fd4531f -r 1fc0fda2b08b source/common/x86/pixel-a.asm
--- a/source/common/x86/pixel-a.asm	Mon Mar 31 17:45:16 2014 -0500
+++ b/source/common/x86/pixel-a.asm	Tue Apr 01 15:22:01 2014 -0500
@@ -6445,8 +6445,8 @@ cglobal downShift_16, 7,7,3
     movd        m1, [r0]
     psrlw       m1, m0
     packuswb    m1, m1
-    movd        r6, m1
-    mov         [r2], r6b
+    movd        r3, m1
+    mov         [r2], r3b
 .end:
     RET
 
diff -r 5d607fd4531f -r 1fc0fda2b08b source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Mon Mar 31 17:45:16 2014 -0500
+++ b/source/encoder/encoder.cpp	Tue Apr 01 15:22:01 2014 -0500
@@ -60,6 +60,8 @@ Encoder::Encoder()
     m_curEncoder = 0;
     m_numLumaWPFrames = 0;
     m_numChromaWPFrames = 0;
+    m_numLumaWPBiFrames = 0;
+    m_numChromaWPBiFrames = 0;
     m_lookahead = NULL;
     m_frameEncoder = NULL;
     m_rateControl = NULL;
@@ -318,7 +320,8 @@ int Encoder::encode(bool flush, const x2
 
         // Encoder holds a reference count until collecting stats
         ATOMIC_INC(&pic->m_countRefEncoders);
-        if (param->rc.aqMode || param->bEnableWeightedPred)
+        bool bEnableWP = param->bEnableWeightedPred || param->bEnableWeightedBiPred;
+        if (param->rc.aqMode || bEnableWP)
             m_rateControl->calcAdaptiveQuantFrame(pic);
         m_lookahead->addPicture(pic, pic_in->sliceType);
     }
@@ -393,6 +396,22 @@ int Encoder::encode(bool flush, const x2
                 out->getSlice()->m_weightPredTable[0][0][2].bPresentFlag)
                 m_numChromaWPFrames++;
         }
+        else if (out->getSlice()->getSliceType() == B_SLICE)
+        {
+            bool bLuma = false, bChroma = false;
+            for (int l = 0; l < 2; l++)
+            {
+                if (out->getSlice()->m_weightPredTable[l][0][0].bPresentFlag)
+                    bLuma = true;
+                if (out->getSlice()->m_weightPredTable[l][0][1].bPresentFlag ||
+                    out->getSlice()->m_weightPredTable[l][0][2].bPresentFlag)
+                    bChroma = true;
+            }
+            if (bLuma)
+                m_numLumaWPBiFrames++;
+            if (bChroma)
+                m_numChromaWPBiFrames++;
+        }
 
         /* calculate the size of the access unit, excluding:
          *  - any AnnexB contributions (start_code_prefix, zero_byte, etc.,)
@@ -670,6 +689,12 @@ void Encoder::printSummary()
                      (float)100.0 * m_numLumaWPFrames / m_analyzeP.m_numPics,
                      (float)100.0 * m_numChromaWPFrames / m_analyzeP.m_numPics);
         }
+        if (param->bEnableWeightedBiPred && m_analyzeB.m_numPics)
+        {
+            x265_log(param, X265_LOG_INFO, "Weighted B-Frames: Y:%.1f%% UV:%.1f%%\n",
+                     (float)100.0 * m_numLumaWPBiFrames / m_analyzeB.m_numPics,
+                     (float)100.0 * m_numChromaWPBiFrames / m_analyzeB.m_numPics);
+        }
         int pWithB = 0;
         for (int i = 0; i <= param->bframes; i++)
             pWithB += m_lookahead->histogram[i];
diff -r 5d607fd4531f -r 1fc0fda2b08b source/encoder/encoder.h
--- a/source/encoder/encoder.h	Mon Mar 31 17:45:16 2014 -0500
+++ b/source/encoder/encoder.h	Tue Apr 01 15:22:01 2014 -0500
@@ -105,6 +105,8 @@ private:
     // weighted prediction
     int                m_numLumaWPFrames;    // number of P frames with weighted luma reference
     int                m_numChromaWPFrames;  // number of P frames with weighted chroma reference
+    int                m_numLumaWPBiFrames;  // number of B frames with weighted luma reference
+    int                m_numChromaWPBiFrames;// number of B frames with weighted chroma reference
 
 public:
 
diff -r 5d607fd4531f -r 1fc0fda2b08b source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Mon Mar 31 17:45:16 2014 -0500
+++ b/source/encoder/frameencoder.cpp	Tue Apr 01 15:22:01 2014 -0500
@@ -439,8 +439,8 @@ void FrameEncoder::compressFrame()
     //  Weighted Prediction parameters estimation.
     //------------------------------------------------------------------------------
     bool bUseWeightP = slice->getSliceType() == P_SLICE && slice->getPPS()->getUseWP();
-    bool bUseweightB = slice->getSliceType() == B_SLICE && slice->getPPS()->getWPBiPred();
-    if (bUseWeightP || bUseweightB)
+    bool bUseWeightB = slice->getSliceType() == B_SLICE && slice->getPPS()->getWPBiPred();
+    if (bUseWeightP || bUseWeightB)
     {
         assert(slice->getPPS()->getUseWP());
         weightAnalyse(*slice, *m_cfg->param);
@@ -453,7 +453,7 @@ void FrameEncoder::compressFrame()
         for (int ref = 0; ref < slice->getNumRefIdx(l); ref++)
         {
             wpScalingParam *w = NULL;
-            if (bUseWeightP && slice->m_weightPredTable[l][ref][0].bPresentFlag)
+            if ((bUseWeightP || bUseWeightB) && slice->m_weightPredTable[l][ref][0].bPresentFlag)
                 w = slice->m_weightPredTable[l][ref];
             m_mref[l][ref].init(slice->getRefPic(l, ref)->getPicYuvRec(), w);
         }
@@ -935,6 +935,8 @@ void FrameEncoder::compressCTURows()
         m_rows[i].m_busy = false;
     }
 
+    bool bUseWeightP = slice->getPPS()->getUseWP() && slice->getSliceType() == P_SLICE;
+    bool bUseWeightB = slice->getPPS()->getWPBiPred() && slice->getSliceType() == B_SLICE;
     int range = m_cfg->param->searchRange; /* fpel search */
     range    += 1;                        /* diamond search range check lag */
     range    += 2;                        /* subpel refine */
@@ -967,7 +969,7 @@ void FrameEncoder::compressCTURows()
                     while ((reconRowCount != m_numRows) && (reconRowCount < row + refLagRows))
                         reconRowCount = refpic->m_reconRowCount.waitForChange(reconRowCount);
 
-                    if (slice->getPPS()->getUseWP() && slice->getSliceType() == P_SLICE && m_mref[l][ref].isWeighted)
+                    if ((bUseWeightP || bUseWeightB) && m_mref[l][ref].isWeighted)
                     {
                         m_mref[l][ref].applyWeight(row + refLagRows, m_numRows);
                     }
@@ -1004,7 +1006,7 @@ void FrameEncoder::compressCTURows()
                         while ((reconRowCount != m_numRows) && (reconRowCount < i + refLagRows))
                             reconRowCount = refpic->m_reconRowCount.waitForChange(reconRowCount);
 
-                        if (slice->getPPS()->getUseWP() && slice->getSliceType() == P_SLICE && m_mref[l][ref].isWeighted)
+                        if ((bUseWeightP || bUseWeightB) && m_mref[l][ref].isWeighted)
                         {
                             m_mref[list][ref].applyWeight(i + refLagRows, m_numRows);
                         }
@@ -1117,7 +1119,7 @@ void FrameEncoder::processRowEncoder(int
 
                 if (reEncode < 0)
                 {
-                    x265_log(m_cfg->param, X265_LOG_INFO, "POC %d row %d - encode restart required for VBV, to %.2f from %.2f\n",
+                    x265_log(m_cfg->param, X265_LOG_DEBUG, "POC %d row %d - encode restart required for VBV, to %.2f from %.2f\n",
                             m_pic->getPOC(), row, qpBase, cu->m_baseQp);
 
                     // prevent the WaveFront::findJob() method from providing new jobs
diff -r 5d607fd4531f -r 1fc0fda2b08b source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Mon Mar 31 17:45:16 2014 -0500


More information about the x265-commits mailing list