[x264-devel] Restricting the number of bits in a macroblock

Jason Garrett-Glaser jason at x264.com
Thu Jan 13 19:05:20 CET 2011


On Thu, Jan 13, 2011 at 9:20 AM, Andrew Jackson
<alj at twintechnologies.co.uk> wrote:
> Dear all,
>
> I wrote in September asking about whether or not x264 restricts the number
> of bits in a macro block.  Loren (Merritt) was kind enough to reply.
>
> After further digging and debugging I find that the decoder which I'm using
> throws out frames (until the next key frame) when it sees a macroblock with
> too many bits in it.  I don't want to use non-psy RDO so please could
> someone point me at the right area of x264 code that I should look at in
> order to enforce this restriction?

Enforcing this restriction is not too difficult.  You must simply save
the CABAC/CAVLC state before encoding an MB, and if the number of bits
is exceeded, re-encode as PCM (in the encode loop in encoder.c).  This
is already done for slice-max-size, but it doesn't copy the CABAC
state because you don't need to keep it when you're ending the slice.

This limiting you mention isn't done for CABAC because this involves
copying the entire CABAC state for every single macroblock to be
encoded, so it's wasteful.  It could be done nearly for free in CAVLC,
but it isn't done there either for consistency.

You could also just use a min QP and hope you can get away with it
(which you probably can).

Which decoder is this?

Jason


More information about the x264-devel mailing list