Diary Of An x264 Developer

05/01/2008 (5:16 pm)

Inter RD refine bugs

I think I’ve found two of these in one week now.

For those who don’t know, on inter blocks in P-frames, subme 7 works by a process called “qpel RD”; that is, it does an ordinary subpixel refinement of the motion vectors except instead of the usual fast metric (SAD or SATD), it does a full rate-distortion comparison on each qpel position using a hexagonal search. Of course, to increase speed, it uses a SATD threshold above which it won’t bother with the whole RD process. The reason for this is obvious when you see the numbers; a full-macroblock SATD takes about 450 clocks, while a full-macroblock RD takes about 10,000 clocks. So even if SATD allowed us to avoid doing an RD 1/20th of the time, it would be worth it; the real numbers are much higher than that, of course.

Now, onto the bugs. The first one was in CAVLC, where in an 8x8dct inter block the numbers for the numbers of non-zero coefficients in each DCT block were not being calculated, resulting in incorrect calculations of bit cost. This wasn’t a problem for CABAC, because CABAC only needs to know whether a block is all-zero or not all-zero; while CAVLC needs to know exactly how many non-zero coefficients there are. This was resolved as part of my overhaul of the nnz code.

The second bug I just ran into today, where I found that when RD was done on 8×16 and 16×8 blocks, for simplicity’s sake, the RD function encoded two 8×8 blocks separately and then summed the resulting scores. This isn’t a problem per se, but the 8×8 RD function went on to check what type of 8×8 block it was: this could be an 8×8, 2 8x4s, 2 4x8s, or 4 4×4 blocks. An 8×16 or 16×8 block can’t have such subblocks, while an 8×8 block can. This again isn’t a problem… but when a 16×8 or 8×16 block type is chosen, it doesn’t reset the subpartition types used for the 8×8 search… so if the 8×8 search chose a sub-8×8 block type, the 8×8 block encode now thinks that we have a sub-8×8 block type even if we cannot possibly have one. The solution was pretty simple.

Leave a Reply