An ABR-reset also resets m_bufferFillFinal, even with bStrictCbr

Issue #381 resolved
Robert Bengtsson-Ölund created an issue

Noticed a VBV discrepancy when encoding ABR with VBV, even tho I am using bStrictCbr and bEnableConstVbv. Sometimes, close to scene changes my own VBV analysis and the internal in libx265 starts to differ.

Tracked the cause down to RateControl::checkAndResetABR() It calls RateControl::init() which in turn reinitialize m_bufferFillFinal to m_bufferSize * m_param->rc.vbvBufferInit

I'm not confident enough with the code base to attempt fixing it myself without causing further problems.

This is with version 2.5 and 2.6.

Comments (7)

  1. Robert Bengtsson-Ölund reporter

    Small patch that seems to solve the issue. Might cause new issues that I can't foresee myself.

    --- vendor/multicoreware/x265/branches/x265-direkt/source/encoder/ratecontrol.cpp (original)
    +++ vendor/multicoreware/x265/branches/x265-direkt/source/encoder/ratecontrol.cpp Fri Dec  1 18:43:05 2017
    @@ -350,9 +350,13 @@
             if (m_param->vbvEndFrameAdjust > 1.)
                 m_param->vbvEndFrameAdjust = x265_clip3(0.0, 1.0, m_param->vbvEndFrameAdjust);
             m_param->rc.vbvBufferInit = x265_clip3(0.0, 1.0, X265_MAX(m_param->rc.vbvBufferInit, m_bufferRate / m_bufferSize));
    -        m_bufferFillFinal = m_bufferSize * m_param->rc.vbvBufferInit;
    -        m_bufferFillActual = m_bufferFillFinal;
    -        m_bufferExcess = 0;
    +
    +        if (!m_param->rc.bStrictCbr || m_bufferFillFinal == 0)
    +        {
    +            m_bufferFillFinal = m_bufferSize * m_param->rc.vbvBufferInit;
    +            m_bufferFillActual = m_bufferFillFinal;
    +            m_bufferExcess = 0;
    +        }
         }
    
         m_totalBits = 0;
    
  2. Aruna Matheswaran

    I'm able to reproduce this issue. strict-cbr is not intended to give consistent results between runs. This has to be dealt with const-vbv. I shall update with the fix patch. Thanks.

  3. Aruna Matheswaran

    A fix patch has been pushed for this issue - Changeset: 11958 (2e684b80d90f) rc: Fix inconsistency in --const-vbv (issue #381) Can you update whether this fixes your issue ? Thanks.

  4. Log in to comment