Entropy coding of the MV prediction residuals uses the same basic architecture as for wavelet coefficient coding: unary VLC binarization, followed by adaptive arithmetic coding with multiple context models. For MV coding there are many different types of data, and these have their own context models.
There are 47 motion vector data contexts in total. They are:
0. YDC_BIN1_CTX - context for bin 1 of the luma DC values
1. YDC_BIN2plus_CTX - context for the remaining bins of the luma DC values
2. YDC_SIGN0_CTX - context for the sign of the luma DC values
3. UDC_BIN1_CTX - context for bin 1 of the U component DC values
4. UDC_BIN2plus_CTX - context for the remaining bins of the U component DC values
5. UDC_SIGN0_CTX - context for the sign of the U component DC values
6. VDC_BIN1_CTX - context for bin 1 of the V component DC values
7. VDC_BIN2plus_CTX - context for the remaining bins of the V component DC values
8. VDC_SIGN0_CTX - context for the sign of the V component DC values
9. REF1xBIN1_CTX - bin 1, reference 1 x values
10. REF1xBIN2_CTX - bin 2, reference 1 x values
11. REF1xBIN3_CTX - bin 3, reference 1 x values
12. REF1xBIN4_CTX - bin 4, reference 1 x values
13. REF1xBIN5plus_CTX - remaining bins, reference 1 x values
14. REF1x_SIGN0_CTX - sign, reference 1 x values, previous value 0
15. REF1x_SIGNP_CTX - sign, reference 1 x values, previous value positive
16. REF1x_SIGNN_CTX - sign, reference 1 x values, previous value negative
17. REF1yBIN1_CTX - bin 1, reference 1 y values
18. REF1yBIN2_CTX - bin 2, reference 1 y values
19. REF1yBIN3_CTX - bin 3, reference 1 y values
20. REF1yBIN4_CTX - bin 4, reference 1 y values
21. REF1yBIN5plus_CTX - remaining bins, reference 1 y values
22. REF1y_SIGN0_CTX - sign, reference 1 y values, previous value 0
23. REF1y_SIGNP_CTX - sign, reference 1 y values, previous value positive
24. REF1y_SIGNN_CTX - sign, reference 1 y values, previous value negative
25. REF2xBIN1_CTX - bin 1, reference 2 x values
26. REF2xBIN2_CTX - bin 2, reference 2 x values
27. REF2xBIN3_CTX - bin 3, reference 2 x values
28. REF2xBIN4_CTX - bin 4, reference 2 x values
29. REF2xBIN5plus_CTX - remaining bins, reference 2 x values
30. REF2x_SIGN0_CTX - sign, reference 2 x values, previous value 0
31. REF2x_SIGNP_CTX - sign, reference 2 x values, previous value positive
32. REF2x_SIGNN_CTX - sign, reference 2 x values, previous value negative
33. REF2yBIN1_CTX - bin 1, reference 2 y values
34. REF2yBIN2_CTX - bin 2, reference 2 y values
35. REF2yBIN3_CTX - bin 3, reference 2 y values
36. REF2yBIN4_CTX - bin 4, reference 2 y values
37. REF2yBIN5plus_CTX - remaining bins, reference 2 y values
38. REF2y_SIGN0_CTX - sign, reference 2 y values, previous value 0
39. REF2y_SIGNP_CTX - sign, reference 2 y values, previous value positive
40. REF2y_SIGNN_CTX - sign, reference 2 y values, previous value negative
41. PMODE_BIN1_CTX - bin 1, prediction mode value
42. PMODE_BIN2_CTX - bin 2, prediction mode value
43. PMODE_BIN3_CTX - bin 3, prediction mode value
44. MB_CMODE_CTX - context for MB common block mode
45. MBSPLIT_BIN1_CTX - bin 1, MB splitting mode values
46. MBSPLIT_BIN2_CTX - bin 2, MB splitting mode values
This may seem like a helluva lot of contexts, but is actually not that many for each motion vector data component. The contextualisation also exploits the boundedness of some of the data types to avoid coding the last bin in the binarisation. For example, the splitting mode residue is either 0, 1, or 2. 2 is binarized to be 0 0 1, but when the second zero has arrived the decoder knows that the residue is bigger than 1, and so must be two. So the VLC can be truncated to 0 0, which is coded with just two bins. The same applies to the prediction mode and the macroblock common mode data.