[FFmpeg-devel] [PATCH] RoQ video encoder (take 4)

Eric Lasota riot
Thu Jun 14 05:31:28 CEST 2007

Michael Niedermayer wrote:
> this if() does seem unneeded
> btw, what is the purpose of the numCB4 == 256 special case above this if()?

The two codebook counts are stored as a 16-bit value, but the way Quake 
3 interprets it is as follows:

if (!roq_flags) {
    two = four = 256;
} else {
    two  = roq_flags>>8;
    if (!two) two = 256;
    four = roq_flags&0xff;

The problem with this is that if the result has, for example, 254 2x2 
entries and 256 4x4 entries, Quake 3 will interpret that as 254 2x2 
entries and ZERO 4x4 entries.  Third-party decoders typically check the 
chunk size to see if there are 4x4 entries or not, Quake 3 doesn't.  
Consequently, the only correct way to store 256 4x4 entries is with 256 
2x2 entries.

I used to have a sample video which proved this, but since a codebook 
mapping "bug" got fixed and stopped redundant 4x4 entries from being 
indexed, I can no longer produce that.  I put that code in there 
specifically for this workaround.

> i also think that it would be better to drop more than just the unused cbs
> but rather calculate the precisse rate distortion (bits*lambda+sse)
> difference which would result from droping a specific cb and drop it if
> the rate distortion decreases
> though this is just an idea for a future patch ...

Dropping a 2x2 codebook entry would also require rebuilding any affected 
4x4 entries, which would probably result in a large amount of the image 
needing to be re-indexed.  Indexing is about 2/3 of the encode time, and 
you'd need to do some portion of that for every codebook entry you want 
to evaluate.  I don't think it's viable without huge increases to 
encoding time.

Best way to do it would be to just figure out a way to estimate ideal 
codebook size, which will probably be difficult because smaller 
codebooks result in more codebook entries just being unused because 
they're not accurate enough.

Also, chroma bias looks better at 4 in my opinion. Take it or leave it.

By the way, another fun caveat:
Any chunk with more than 65536 bytes of data, not including the header, 
will cause Quake 3 to stop playback completely.
(cl_cin.c line 1276)

More information about the ffmpeg-devel mailing list