[x265] [PATCH 5 of 6] rc: initialize the 2 pass states in rc

Steve Borho steve at borho.org
Mon Jun 16 06:19:31 CEST 2014


On Sun, Jun 15, 2014 at 1:50 PM,  <aarthi at multicorewareinc.com> wrote:
> # HG changeset patch
> # User Aarthi Thirumalai<aarthi at multicorewareinc.com>
> # Date 1402858153 -19800
> #      Mon Jun 16 00:19:13 2014 +0530
> # Node ID 819acc0204a2d3e454d9492ae81f80fc04e2b99f
> # Parent  9e0a1f70169df85350507de83c27eeae172e7547
> rc: initialize the 2 pass states in rc
>
> diff -r 9e0a1f70169d -r 819acc0204a2 source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cpp        Mon Jun 16 00:15:08 2014 +0530
> +++ b/source/encoder/encoder.cpp        Mon Jun 16 00:19:13 2014 +0530
> @@ -185,7 +185,8 @@
>              }
>          }
>      }
> -    m_rateControl->init(&m_frameEncoder[0].m_sps);
> +    if (m_rateControl->init(&m_frameEncoder[0].m_sps) == -1)
> +        m_aborted = true;
>      m_lookahead->init();
>      m_encodeStartTime = x265_mdate();
>  }
> diff -r 9e0a1f70169d -r 819acc0204a2 source/encoder/ratecontrol.cpp
> --- a/source/encoder/ratecontrol.cpp    Mon Jun 16 00:15:08 2014 +0530
> +++ b/source/encoder/ratecontrol.cpp    Mon Jun 16 00:19:13 2014 +0530
> @@ -27,6 +27,7 @@
>  #include "encoder.h"
>  #include "slicetype.h"
>  #include "ratecontrol.h"
> +#include "param.h"
>  #include "TLibCommon/SEI.h"
>
>  #define BR_SHIFT  6
> @@ -81,6 +82,17 @@
>      *n /= b;
>      *d /= b;
>  }
> +
> +inline char *strcatFilename(char *input, char *suffix)
> +{
> +    char *output = X265_MALLOC(char, strlen(input) + strlen(suffix) + 1);
> +    if (!output)
> +        return NULL;
> +    strcpy(output, input);
> +    strcat(output, suffix);
> +    return output;
> +}
> +

bah, I'm hoping this isn't necessary in the end

>  }  // end anonymous namespace
>  /* Compute variance to derive AC energy of each block */
>  static inline uint32_t acEnergyVar(TComPic *pic, uint64_t sum_ssd, int shift, int i)
> @@ -283,7 +295,8 @@
>              m_rateFactorMaxDecrement = m_param->rc.rfConstant - m_param->rc.rfConstantMin;
>      }
>
> -    m_isAbr = m_param->rc.rateControlMode != X265_RC_CQP; // later add 2pass option
> +    m_isAbr = m_param->rc.rateControlMode != X265_RC_CQP && !m_param->rc.statRead;
> +    m_2pass =  m_param->rc.rateControlMode == X265_RC_ABR && m_param->rc.statRead;

this is interesting (a question mostly), The second pass must be a
form of ABR? I suppose this makes sense

>      m_bitrate = m_param->rc.bitrate * 1000;
>      m_frameDuration = (double)m_param->fpsDenom / m_param->fpsNum;
>      m_qp = m_param->rc.qp;
> @@ -332,7 +345,7 @@
>          m_param->rc.vbvMaxBitrate = 0;
>      }
>      m_isVbv = m_param->rc.vbvMaxBitrate > 0 && m_param->rc.vbvBufferSize > 0;
> -    m_isCbr = m_param->rc.rateControlMode == X265_RC_ABR && m_isVbv && m_param->rc.vbvMaxBitrate == m_param->rc.bitrate;
> +    m_isCbr = m_param->rc.rateControlMode == X265_RC_ABR && m_isVbv && m_param->rc.vbvMaxBitrate <= m_param->rc.bitrate;
>      m_bframes = m_param->bframes;
>      m_bframeBits = 0;
>      m_leadingNoBSatd = 0;
> @@ -364,8 +377,57 @@
>      m_lstep = pow(2, m_param->rc.qpStep / 6.0);
>  }
>
> -void RateControl::init(TComSPS *sps)
> +int RateControl::init(TComSPS *sps)
>  {
> +    if (m_statFileOut)
> +    {
> +        /* Open output file */
> +        /* If input and output files are the same, output to a temp file
> +         * and move it to the real name only when it's complete */
> +        if (m_param->rc.statWrite)
> +        {
> +            char *p;
> +            m_statFileTmpname = strcatFilename(m_param->rc.pszStatOut, ".temp" );
> +
> +            m_statFileOut = fopen(m_statFileTmpname, "wb");
> +            if (m_statFileOut)
> +            {
> +                x265_log(m_param, X265_LOG_ERROR, "RateControl Init: can't open stats file\n");
> +                return -1;
> +            }
> +
> +            p = x265_param2string(m_param);
> +            if (p)
> +                fprintf(m_statFileOut, "#options: %s\n", p);
> +            X265_FREE(p);
> +            if (m_param->rc.cuTree && !m_param->rc.statRead )
> +            {
> +                m_cutreeStatFileTmpname = strcatFilename(m_param->rc.pszStatOut, ".cutree.temp" );
> +                m_cbtreeStatFileName = strcatFilename(m_param->rc.pszStatOut, ".mbtree");
> +                if (m_cutreeStatFileTmpname || !m_cbtreeStatFileName)
> +                    return -1;
> +
> +                m_cutreeStatFileOut = fopen(m_cutreeStatFileTmpname, "wb");
> +                if (m_cutreeStatFileOut)
> +                {
> +                    x265_log(m_param, X265_LOG_ERROR, "RateControl Init: can't open mbtree stats file\n");
> +                    return -1;

it's ok to make this a fatal error

> +                }
> +            }
> +        }
> +        if (m_param->rc.cuTree && (m_param->rc.statRead || m_param->rc.statWrite))
> +        {
> +            if (!m_param->rc.statRead)
> +            {
> +                m_cuTreeStats.srcdim[0] = m_param->sourceWidth;
> +                m_cuTreeStats.srcdim[1] = m_param->sourceHeight;
> +            }
> +        }
> +    }
> +
> +    if (m_2pass)
> +        return 0;
> +
>      if (m_isVbv)
>      {
>          double fps = (double)m_param->fpsNum / m_param->fpsDenom;
> @@ -425,6 +487,7 @@
>      }
>
>      m_predBfromP = m_pred[0];
> +    return 0;
>  }
>
>  void RateControl::initHRD(TComSPS *sps)
> diff -r 9e0a1f70169d -r 819acc0204a2 source/encoder/ratecontrol.h
> --- a/source/encoder/ratecontrol.h      Mon Jun 16 00:15:08 2014 +0530
> +++ b/source/encoder/ratecontrol.h      Mon Jun 16 00:19:13 2014 +0530
> @@ -170,7 +170,7 @@
>      int rowDiagonalVbvRateControl(TComPic* pic, uint32_t row, RateControlEntry* rce, double& qpVbv);
>
>      void hrdFullness(SEIBufferingPeriod* sei);
> -    void init(TComSPS* sps);
> +    int init(TComSPS* sps);

it's ok to return bool from internal functions

>      void initHRD(TComSPS* sps);
>
>  protected:
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel



-- 
Steve Borho


More information about the x265-devel mailing list