[x264-devel] Restricting the number of bits in a macroblock
Andrew Jackson
alj at twintechnologies.co.uk
Fri Jan 14 09:59:49 CET 2011
Jason
Thank you for your prompt reply.
>> 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).
I'll experiment with these and let you know: if I come up with any code
I'll send it in for consideration as a patch.
> Which decoder is this?
Unfortunately, I am not at liberty to say (being bound by an NDA) but it
is a hardware decoder not a software decoder.
Andrew
More information about the x264-devel
mailing list