[x264-devel] Re: QP related variables

Måns Rullgård mru at mru.ath.cx
Thu Jul 22 01:05:11 CEST 2004


Laurent Aimar <fenrir at via.ecp.fr> writes:

> On Wed, Jul 21, 2004, Måns Rullgård wrote:
>> Laurent Aimar <fenrir at via.ecp.fr> writes:
>> 
>> > On Thu, Jul 15, 2004, Måns Rullgård wrote:
>> >> I've been trying to figure out the meaning of the various QP related
>> >> variables used during encoding.  From what I can see the global QP
>> >> value is used for all MBs.  Is this the case, or have I overlooked
>> >> something?
>> >  Yes it's that case, a global qp per frame.
>> >
>> >>  I also noticed a TODO comment in encoder/analyse.c, line
>> >> 850.  What is this referring to?
>> >   Implementing a RC that change QP per MB ;)
>> >> 
>> >> QP adjustments should be done by the rate control, so I need to know
>> >> how to properly change the QP used for each MB.  Any hints there?
>> >  Yes, the best is just to pass it to x264_macroblock_analyse and to replace
>> >   h->mb.qp[h->mb.i_mb_xy] = x264_clip3( h->pps->i_pic_init_qp + h->sh.i_qp_delta + 0, 0, 51 );
>> > by
>> >   h->mb.qp[h->mb.i_mb_xy] = i_my_qp_for_this_mb;
>> >
>> > It should work but I never tested if the bitstream is correct.
>> What about all the other uses of
>  The only one you really need to change is h->mb.qp[h->mb.i_mb_xy].
> It will be the QP for the current MB.
>
>  All others "QP variables" are used to create the bitstream and will
> help saving a few bits.
>
>  When writing the bistream, only the delta with the last MB (saved by
> h->mb.i_last_qp) is written to the bitstream (h->mb.i_last_dqp is also
> used in CABAC mode to select a cabac context).

So they are all updated properly?  I was trying to follow the code,
but got lost somewhere.

>  Now for the first macroblock of a slice, h->mb.i_last_qp is
> initialized with h->pps->i_pic_init_qp + h->sh.i_qp_delta (and
> h->mb.i_last_dqp to 0).  (PPS is constant for the whole stream,
> while SH could be changed at each slice).
>
>  If you want to save a few bits and
>  - if you know the average QP for the whole stream then put it in
> h->pps->i_pic_init_qp.

That would require dual-pass encoding, or something similar, I suppose.

>  - if you know the first QP of the slice (before the slice header is
>  written), set
>  h->sh.i_qp_delta to i_first_qp - h->pps->i_pic_init_qp.

Easy enough.

>  Btw, one thing, there is a constraint for the QP variation within a
> slice, I'm not sure but I think it is : abs(qp - last_qp) <= 12

That should be no problem.

Thanks for the clarifications.

-- 
Måns Rullgård
mru at mru.ath.cx

-- 
This is the x264-devel mailing-list
If you are in trouble, please contact <postmaster at videolan.org>



More information about the x264-devel mailing list