[x265] [PATCH] Fix: QP modification bug in Scenecut Aware Frame Quantizer Selection

Aruna Matheswaran aruna at multicorewareinc.com
Thu Jul 2 07:27:26 CEST 2020


Pushed to master.

On Wed, Jul 1, 2020 at 10:00 PM Niranjan Bala <niranjan at multicorewareinc.com>
wrote:

> From b782cbcc497dc002ce7aba1758a7fa82ed92f52a Mon Sep 17 00:00:00 2001
> From: Niranjan <niranjan at multicorewareinc.com>
> Date: Wed, 1 Jul 2020 20:53:57 +0530
> Subject: [PATCH] Fix: QP modification bug in Scenecut Aware Frame Quantizer
>  Selection
>
> ---
>  source/encoder/ratecontrol.cpp | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/source/encoder/ratecontrol.cpp
> b/source/encoder/ratecontrol.cpp
> index 0a3a5bfe7..33e5a35a1 100644
> --- a/source/encoder/ratecontrol.cpp
> +++ b/source/encoder/ratecontrol.cpp
> @@ -3152,12 +3152,13 @@ void RateControl::splitbUsed(char bused[],
> RateControlEntry *rce)
>
>  double RateControl::scenecutAwareQp(Frame* curFrame, double q)
>  {
> +    double qp = x265_qScale2qp(q);
>      uint32_t maxWindowSize = uint32_t((m_param->scenecutWindow / 1000.0)
> * (m_param->fpsNum / m_param->fpsDenom) + 0.5);
>      uint32_t windowSize = maxWindowSize / 3;
>      int lastScenecut = m_top->m_rateControl->m_lastScenecut;
>      int lastIFrame = m_top->m_rateControl->m_lastScenecutAwareIFrame;
> -    double maxQpDelta = x265_qp2qScale(double(m_param->maxQpDelta));
> -    double iSliceDelta = x265_qp2qScale(double(I_SLICE_DELTA));
> +    double maxQpDelta = double(m_param->maxQpDelta);
> +    double iSliceDelta = double(I_SLICE_DELTA);
>      double sliceTypeDelta = SLICE_TYPE_DELTA * maxQpDelta;
>      double window2Delta = WINDOW2_DELTA * maxQpDelta;
>      double window3Delta = WINDOW3_DELTA * maxQpDelta;
> @@ -3173,11 +3174,11 @@ double RateControl::scenecutAwareQp(Frame*
> curFrame, double q)
>          if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut +
> int(maxWindowSize))
>              && curFrame->m_poc > lastIFrame))
>          {
> -            q += maxQpDelta - sliceTypeDelta;
> +            qp += maxQpDelta - sliceTypeDelta;
>              if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) &&
> ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))
> -                q -= window2Delta;
> +                qp -= window2Delta;
>              else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))
> -                q -= window3Delta;
> +                qp -= window3Delta;
>          }
>      }
>      else if (isFrameInsideWindow &&
> IS_X265_TYPE_B(curFrame->m_lowres.sliceType))
> @@ -3185,16 +3186,16 @@ double RateControl::scenecutAwareQp(Frame*
> curFrame, double q)
>          if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut +
> int(maxWindowSize))
>              && curFrame->m_poc > lastIFrame))
>          {
> -            q += maxQpDelta;
> +            qp += maxQpDelta;
>              if (curFrame->m_lowres.sliceType == X265_TYPE_B)
> -                q += sliceTypeDelta;
> +                qp += sliceTypeDelta;
>              if (((curFrame->m_poc) > (lastScenecut + int(windowSize))) &&
> ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))
> -                q -= window2Delta;
> +                qp -= window2Delta;
>              else if (curFrame->m_poc > lastScenecut + 2 * int(windowSize))
> -                q -= window3Delta;
> +                qp -= window3Delta;
>          }
>      }
>      if (IS_X265_TYPE_I(curFrame->m_lowres.sliceType) &&
> curFrame->m_lowres.bScenecut)
> -        q = q - iSliceDelta;
> -    return q;
> +        qp = qp - iSliceDelta;
> +    return  x265_qp2qScale(qp);
>  }
> --
> 2.18.0.windows.1
>
>
> Thanks & Regards
> *Niranjan Kumar B*
> Video Codec Engineer
> Media & AI Analytics
> +91 958 511 1449
> <https://multicorewareinc.com/>
>
>
> On Wed, Jul 1, 2020 at 9:58 PM Niranjan Bala <
> niranjan at multicorewareinc.com> wrote:
>
>> Please ignore the above patch and use the following one.
>>
>> Thanks & Regards
>> *Niranjan Kumar B*
>> Video Codec Engineer
>> Media & AI Analytics
>> +91 958 511 1449
>> <https://multicorewareinc.com/>
>>
>>
>> On Wed, Jul 1, 2020 at 1:10 PM Niranjan Bala <
>> niranjan at multicorewareinc.com> wrote:
>>
>>> # HG changeset patch
>>> # User Niranjan <niranjan at multicorewareinc.com>
>>> # Date 1593151129 -19800
>>> #      Fri Jun 26 11:28:49 2020 +0530
>>> # Node ID c8bab0857b4ac70e37c70fcde419cc7a2a77badf
>>> # Parent  ac951f9fef8a019822cac11ab42870b2443a017c
>>> Fix: QP modification bug in Scenecut Aware Frame Quantizer Selection
>>>
>>> diff --git a/source/encoder/ratecontrol.cpp
>>> b/source/encoder/ratecontrol.cpp
>>> --- a/source/encoder/ratecontrol.cpp
>>> +++ b/source/encoder/ratecontrol.cpp
>>> @@ -3152,12 +3152,13 @@
>>>
>>>  double RateControl::scenecutAwareQp(Frame* curFrame, double q)
>>>  {
>>> +    double qp = x265_qScale2qp(q);
>>>      uint32_t maxWindowSize = uint32_t((m_param->scenecutWindow /
>>> 1000.0) * (m_param->fpsNum / m_param->fpsDenom) + 0.5);
>>>      uint32_t windowSize = maxWindowSize / 3;
>>>      int lastScenecut = m_top->m_rateControl->m_lastScenecut;
>>>      int lastIFrame = m_top->m_rateControl->m_lastScenecutAwareIFrame;
>>> -    double maxQpDelta = x265_qp2qScale(double(m_param->maxQpDelta));
>>> -    double iSliceDelta = x265_qp2qScale(double(I_SLICE_DELTA));
>>> +    double maxQpDelta = double(m_param->maxQpDelta);
>>> +    double iSliceDelta = double(I_SLICE_DELTA);
>>>      double sliceTypeDelta = SLICE_TYPE_DELTA * maxQpDelta;
>>>      double window2Delta = WINDOW2_DELTA * maxQpDelta;
>>>      double window3Delta = WINDOW3_DELTA * maxQpDelta;
>>> @@ -3173,11 +3174,11 @@
>>>          if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut
>>> + int(maxWindowSize))
>>>              && curFrame->m_poc > lastIFrame))
>>>          {
>>> -            q += maxQpDelta - sliceTypeDelta;
>>> +            qp += maxQpDelta - sliceTypeDelta;
>>>              if (((curFrame->m_poc) > (lastScenecut + int(windowSize)))
>>> && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))
>>> -                q -= window2Delta;
>>> +                qp -= window2Delta;
>>>              else if (curFrame->m_poc > lastScenecut + 2 *
>>> int(windowSize))
>>> -                q -= window3Delta;
>>> +                qp -= window3Delta;
>>>          }
>>>      }
>>>      else if (isFrameInsideWindow &&
>>> IS_X265_TYPE_B(curFrame->m_lowres.sliceType))
>>> @@ -3185,16 +3186,16 @@
>>>          if (!(lastIFrame > lastScenecut && lastIFrame <= (lastScenecut
>>> + int(maxWindowSize))
>>>              && curFrame->m_poc > lastIFrame))
>>>          {
>>> -            q += maxQpDelta;
>>> +            qp += maxQpDelta;
>>>              if (curFrame->m_lowres.sliceType == X265_TYPE_B)
>>> -                q += sliceTypeDelta;
>>> +                qp += sliceTypeDelta;
>>>              if (((curFrame->m_poc) > (lastScenecut + int(windowSize)))
>>> && ((curFrame->m_poc) <= (lastScenecut + 2 * int(windowSize))))
>>> -                q -= window2Delta;
>>> +                qp -= window2Delta;
>>>              else if (curFrame->m_poc > lastScenecut + 2 *
>>> int(windowSize))
>>> -                q -= window3Delta;
>>> +                qp -= window3Delta;
>>>          }
>>>      }
>>>      if (IS_X265_TYPE_I(curFrame->m_lowres.sliceType) &&
>>> curFrame->m_lowres.bScenecut)
>>> -        q = q - iSliceDelta;
>>> -    return q;
>>> +        qp = qp - iSliceDelta;
>>> +    return  x265_qp2qScale(qp);
>>>  }
>>>
>>> Thanks & Regards
>>> *Niranjan Kumar B*
>>> Video Codec Engineer
>>> Media & AI Analytics
>>> +91 958 511 1449
>>> <https://multicorewareinc.com/>
>>>
>> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>


-- 
Regards,
*Aruna Matheswaran,*
Video Codec Engineer,
Media & AI analytics BU,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20200702/39cbd9b4/attachment.html>


More information about the x265-devel mailing list