<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multimedia.cx/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=QxvP4q</id>
	<title>MultimediaWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multimedia.cx/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=QxvP4q"/>
	<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php/Special:Contributions/QxvP4q"/>
	<updated>2026-04-08T09:19:11Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.5</generator>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=On2_VP5&amp;diff=7664</id>
		<title>On2 VP5</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=On2_VP5&amp;diff=7664"/>
		<updated>2007-04-11T14:46:57Z</updated>

		<summary type="html">&lt;p&gt;QxvP4q: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCC: VP50&lt;br /&gt;
* Company: [[On2]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/VP5/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Format ==&lt;br /&gt;
&lt;br /&gt;
The aim here is to open this standard with a full description of the bitstream format and decoding process.  Contributors from On2 especially encouraged here, but it is anticipated that this section will be completed through reverse engineering.&lt;br /&gt;
&lt;br /&gt;
Please do not submit any copyrighted text or code here.&lt;br /&gt;
&lt;br /&gt;
=== Introduction ===&lt;br /&gt;
&lt;br /&gt;
VP5 uses unidirectional (&amp;quot;P-frame&amp;quot;) and intra-frame (within the current frame) prediction. Entropy coding is performed using range coding and an 8x8 iDCT is used.  The format supports dynamic adjustment of encoded video resolution.&lt;br /&gt;
&lt;br /&gt;
=== Macroblock types ===&lt;br /&gt;
&lt;br /&gt;
Each video frame is composed of an array of 16x16 macroblocks, just like [[MPEG-2]], [[MPEG-4]] parts 2 and 10.  Each [[MB]] (macroblock) takes one of the following modes (&amp;quot;[[MV]]&amp;quot; means &amp;quot;motion vector&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_intra&amp;quot;&amp;gt;INTRA (1)&amp;lt;/span&amp;gt;: Intra [[MB]]&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_inter_novec_pf&amp;quot;&amp;gt;INTER_NOVEC_PF (0)&amp;lt;/span&amp;gt;: Inter [[MB]], null [[MV]], previous frame reference&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_inter_delta_pf&amp;quot;&amp;gt;INTER_DELTA_PF (2)&amp;lt;/span&amp;gt;: Inter [[MB]], differential [[MV]], previous frame reference&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_inter_4v&amp;quot;&amp;gt;INTER_4V (7)&amp;lt;/span&amp;gt;: Inter [[MB]], four [[MV]]s, previous frame reference&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_inter_v1_pf&amp;quot;&amp;gt;INTER_V1_PF (3)&amp;lt;/span&amp;gt;: Inter [[MB]], [[MV]] 1, previous frame reference&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_inter_v2_pf&amp;quot;&amp;gt;INTER_V2_PF (4)&amp;lt;/span&amp;gt;: Inter [[MB]], [[MV]] 2, previous frame reference&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_inter_novec_gf&amp;quot;&amp;gt;INTER_NOVEC_GF (5)&amp;lt;/span&amp;gt;: Inter [[MB]], null [[MV]], golden frame reference&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_inter_delta_gf&amp;quot;&amp;gt;INTER_DELTA_GF (6)&amp;lt;/span&amp;gt;: Inter [[MB]], differential [[MV]], golden frame reference&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_inter_v1_gf&amp;quot;&amp;gt;INTER_V1_GF (8)&amp;lt;/span&amp;gt;: Inter [[MB]], [[MV]] 1, golden frame reference&lt;br /&gt;
* &amp;lt;span id=&amp;quot;mb_inter_v2_gf&amp;quot;&amp;gt;INTER_V2_GF (9)&amp;lt;/span&amp;gt;: Inter [[MB]], [[MV]] 2, golden frame reference&lt;br /&gt;
&lt;br /&gt;
=== Frame Header ===&lt;br /&gt;
&lt;br /&gt;
Range coding commences at the very begining of this frame header.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Syntax !! Number of bits !! Probability || Semantics&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span id=&amp;quot;frame_mode&amp;quot;&amp;gt;frame_mode&amp;lt;/span&amp;gt; || 1 || 128 || 0 signifies an intra frame&lt;br /&gt;
|-&lt;br /&gt;
| value0 || 1 || 128 || unused&lt;br /&gt;
|-&lt;br /&gt;
| qp || 6 || 128 || Quantization parameter valid range 0..63&lt;br /&gt;
|-&lt;br /&gt;
| if ([[#frame_mode|frame_mode]] == 0) { || || || 0 signifies intra frame&lt;br /&gt;
|-&lt;br /&gt;
| version_minor || 8 || 128 || should be 0&lt;br /&gt;
|-&lt;br /&gt;
| version_major || 5 || 128 || should be 5&lt;br /&gt;
|-&lt;br /&gt;
| value3 || 2 || 128 || unknown&lt;br /&gt;
|-&lt;br /&gt;
| interlace || 1 || 128 || true (1) means interlace will be used&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span id=&amp;quot;dim_y&amp;quot;&amp;gt;dim_y&amp;lt;/span&amp;gt; || 8 || 128 || Macroblock height of video &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;span id=&amp;quot;dim_x&amp;quot;&amp;gt;dim_x&amp;lt;/span&amp;gt; || 8 || 128 || Macroblock width of video &lt;br /&gt;
|-&lt;br /&gt;
| render_y || 8 || 128 || Displayed macroblock height of video &lt;br /&gt;
|-&lt;br /&gt;
| render_x || 8 || 128 || Displayed macroblock width of video&lt;br /&gt;
|-&lt;br /&gt;
| value4 || 2 || 128 || unknown&lt;br /&gt;
|-&lt;br /&gt;
| } || || ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If dim_x or dim_y have values different from the previous intra frame, then the resolution of the encoded image has changed.&lt;br /&gt;
&lt;br /&gt;
=== Model for macroblock type parsing ===&lt;br /&gt;
&lt;br /&gt;
This section allows to calculate a model used to parse macroblock type. This model is stored in the mb_type_model[3][10][10] table. To calculate this model, an intermediate table (mb_types_stats[3][10][2]) is extracted from the input stream. The macroblock type model is useful only for non-key frames (ie. frames which can contain macroblock type other than intra). So this procedure is not used for intra frame, which instead reset the value of mb_types_stats to the content of [[#def_mb_types_stats|def_mb_types_stats]].&lt;br /&gt;
&lt;br /&gt;
So first here is how the input stream must be parsed:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Syntax !! Number of bits !! Probability || Semantics&lt;br /&gt;
|-&lt;br /&gt;
| for (ctx=0; ctx&amp;lt;3; ctx  ) {&lt;br /&gt;
|-&lt;br /&gt;
| if (flag1) { || 1 || 174 ||&lt;br /&gt;
|-&lt;br /&gt;
| index || 4 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| mb_types_stats[ctx] = [[#pre_def_mb_type_stats|pre_def_mb_type_stats]][index][ctx]&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| if (flag2) { || 1 || 254 ||&lt;br /&gt;
|-&lt;br /&gt;
| for (type=0; type&amp;lt;10; type  ) {&lt;br /&gt;
|-&lt;br /&gt;
| for(i=0; i&amp;lt;2; i  ) {&lt;br /&gt;
|-&lt;br /&gt;
| if (flag3) { || 1 || 205 ||&lt;br /&gt;
|-&lt;br /&gt;
| sign || 1 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| if (flag4) { || 1 || 171 ||&lt;br /&gt;
|-&lt;br /&gt;
| if (flag5) { || 1 || 199 ||&lt;br /&gt;
|-&lt;br /&gt;
| delta || 7 || 128 || quater of delta...&lt;br /&gt;
|-&lt;br /&gt;
| } else if (flag6) { || 1 || 140 ||&lt;br /&gt;
|-&lt;br /&gt;
| delta = 12&lt;br /&gt;
|-&lt;br /&gt;
| } else if (flag7) { || 1 || 125 ||&lt;br /&gt;
|-&lt;br /&gt;
| delta = 16&lt;br /&gt;
|-&lt;br /&gt;
| } else if (flag8) { || 1 || 104 ||&lt;br /&gt;
|-&lt;br /&gt;
| delta = 20&lt;br /&gt;
|-&lt;br /&gt;
| } else {&lt;br /&gt;
|-&lt;br /&gt;
| delta = 24&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| } else {&lt;br /&gt;
|-&lt;br /&gt;
| if (flag9) { || 1 || 83 ||&lt;br /&gt;
|-&lt;br /&gt;
| delta = 4&lt;br /&gt;
|-&lt;br /&gt;
| } else {&lt;br /&gt;
|-&lt;br /&gt;
| delta = 8&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| if (sign) {&lt;br /&gt;
|-&lt;br /&gt;
| delta = -delta&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| mb_types_stats[ctx][type][i]  = delta&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;span id=&amp;quot;mb_type_model&amp;quot;&amp;gt;mb_type_model&amp;lt;/span&amp;gt; is derived from mb_types_stats. The first index of mb_type_model is the number of predictors (0, 1 or 2). The second index is the type of the previous macroblock. A probablity is associated to each value of the third index as follow:&lt;br /&gt;
&lt;br /&gt;
* 0 : probability for [[MB]] type to be the same as previous [[MB]] type&lt;br /&gt;
* 1 : probability for [[MB]] type to be in {[[#mb_inter_novec_pf|INTER_NOVEC_PF]], [[#mb_inter_delta_pf|INTER_DELTA_PF]], [[#mb_inter_v1_pf|INTER_V1_PF]], [[#mb_inter_v2_pf|INTER_V2_PF]]}&lt;br /&gt;
* 2 : probability for [[MB]] type to be in {[[#mb_inter_novec_pf|INTER_NOVEC_PF]], [[#mb_inter_delta_pf|INTER_DELTA_PF]]} knowing it's in {[[#mb_inter_novec_pf|INTER_NOVEC_PF]], [[#mb_inter_delta_pf|INTER_DELTA_PF]], [[#mb_inter_v1_pf|INTER_V1_PF]], [[#mb_inter_v2_pf|INTER_V2_PF]]}&lt;br /&gt;
* 3 : probability for [[MB]] type to be in {[[#mb_intra|INTRA]], [[#mb_inter_4v|INTER_4V]]} knowing it's in {[[#mb_intra|INTRA]], [[#mb_inter_novec_gf|INTER_NOVEC_GF]], [[#mb_inter_delta_gf|INTER_DELTA_GF]], [[#mb_inter_4v|INTER_4V]], [[#mb_inter_v1_gf|INTER_V1_GF]], [[#mb_inter_v2_gf|INTER_V2_GF]]}&lt;br /&gt;
* 4 : probability for [[MB]] type to be in {[[#mb_inter_novec_pf|INTER_NOVEC_PF]]} knowing it's in {[[#mb_inter_novec_pf|INTER_NOVEC_PF]], [[#mb_inter_delta_pf|INTER_DELTA_PF]]}&lt;br /&gt;
* 5 : probability for [[MB]] type to be in {[[#mb_inter_v1_pf|INTER_V1_PF]]} knowing it's in {[[#mb_inter_v1_pf|INTER_V1_PF]], [[#mb_inter_v2_pf|INTER_V2_PF]]}&lt;br /&gt;
* 6 : probability for [[MB]] type to be in {[[#mb_intra|INTRA]]} knowing it's in {[[#mb_intra|INTRA]], [[#mb_inter_4v|INTER_4V]]}&lt;br /&gt;
* 7 : probability for [[MB]] type to be in {[[#mb_inter_novec_gf|INTER_NOVEC_GF]], [[#mb_inter_delta_gf|INTER_DELTA_GF]]} knowing it's in {[[#mb_inter_novec_gf|INTER_NOVEC_GF]], [[#mb_inter_delta_gf|INTER_DELTA_GF]], [[#mb_inter_v1_gf|INTER_V1_GF]], [[#mb_inter_v2_gf|INTER_V2_GF]]}&lt;br /&gt;
* 8 : probability for [[MB]] type to be in {[[#mb_inter_novec_gf|INTER_NOVEC_GF]]} knowing it's in {[[#mb_inter_novec_gf|INTER_NOVEC_GF]], [[#mb_inter_delta_gf|INTER_DELTA_GF]]}&lt;br /&gt;
* 9 : probability for [[MB]] type to be in {[[#mb_inter_v1_gf|INTER_V1_GF]]} knowing it's in {[[#mb_inter_v1_gf|INTER_V1_GF]], [[#mb_inter_v2_gf|INTER_V2_GF]]}&lt;br /&gt;
&lt;br /&gt;
mb_type_model[ctx][type][0] is calculated with the following formula:&lt;br /&gt;
  255 - (255 * mb_types_stats[ctx][type][0]) / (1   mb_types_stats[ctx][type][0]   mb_types_stats[ctx][type][1])&lt;br /&gt;
&lt;br /&gt;
All the other probabilities are conditional probabilities noted P(A|B) and are calculated with:&lt;br /&gt;
  1   255 * P(A) / (1 P(B))&lt;br /&gt;
&lt;br /&gt;
For each macroblock type, it's probability is noted P(A) and calculated with:&lt;br /&gt;
  100 * mb_types_stats[ctx][type][1]&lt;br /&gt;
with one exception: when calculating mb_type_model[ctx][type][i], P(type) is 0.&lt;br /&gt;
&lt;br /&gt;
=== Models for macroblock type parsing ===&lt;br /&gt;
&lt;br /&gt;
This header contains various models used to parse motion vectors. It is only present in non-key frames. For key frames, all those modeles are filled with 0x80 instead, except vector_model_pdi[comp][0] which is filled with 0x55.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Syntax !! Number of bits !! Probability || Semantics&lt;br /&gt;
|-&lt;br /&gt;
| for (comp=0; comp&amp;lt;2; comp  ) {&lt;br /&gt;
|-&lt;br /&gt;
| if (flag1) { || 1 || [[#vmc_pct|vmc_pct]][comp][0] ||&lt;br /&gt;
|-&lt;br /&gt;
| vector_model_dct[comp] || 7 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| if (flag2) { || 1 || [[#vmc_pct|vmc_pct]][comp][1] ||&lt;br /&gt;
|-&lt;br /&gt;
| vector_model_sig[comp] || 7 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| if (flag3) { || 1 || [[#vmc_pct|vmc_pct]][comp][2] ||&lt;br /&gt;
|-&lt;br /&gt;
| vector_model_pdi[comp][0] || 7 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| if (flag4) { || 1 || [[#vmc_pct|vmc_pct]][comp][3] ||&lt;br /&gt;
|-&lt;br /&gt;
| vector_model_pdi[comp][1] || 7 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| for (comp=0; comp&amp;lt;2; comp  ) {&lt;br /&gt;
|-&lt;br /&gt;
| for (node=0; node&amp;lt;7; node  ) {&lt;br /&gt;
|-&lt;br /&gt;
| if (flag5) { || 1 || [[#vmc_pct|vmc_pct]][comp][4 node] ||&lt;br /&gt;
|-&lt;br /&gt;
| vector_model_pdv[comp][node] || 7 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All the value in thoses models must be multiplied by 2. Those models can't contain a 0 value, so every 0 must then be replaced by a 1.&lt;br /&gt;
&lt;br /&gt;
=== Models for DCT coefficient parsing ===&lt;br /&gt;
&lt;br /&gt;
This header contains various models used to parse DCT coefficient. Theses parsing are using a default_probability table which is initially filled with 0x80. The value read from the bitstream must be multiplied by 2. If the value is 0, it must be replaced by 1.&lt;br /&gt;
The last two models are derived from the first two.&lt;br /&gt;
&lt;br /&gt;
==== DC coefficient model ====&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Syntax !! Number of bits !! Probability || Semantics&lt;br /&gt;
|-&lt;br /&gt;
| for (pt=0; pt&amp;lt;2; pt  ) {&lt;br /&gt;
|-&lt;br /&gt;
| for (node=0; node&amp;lt;11; node  ) {&lt;br /&gt;
|-&lt;br /&gt;
| if (flag1) { || 1 || [[#dccv_pct|dccv_pct]][pt][node] ||&lt;br /&gt;
|-&lt;br /&gt;
| coeff_model_dccv[pt][node] = default_probability[node] || 7 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| } else if ([[#frame_mode|frame_mode]] == 0) {&lt;br /&gt;
|-&lt;br /&gt;
| coeff_model_dccv[pt][node] = default_probability[node]&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== AC coefficient model ====&lt;br /&gt;
&lt;br /&gt;
The value read from the bitstream must be multiplied by 2. If the value is 0, it must be replaced by 1.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Syntax !! Number of bits !! Probability || Semantics&lt;br /&gt;
|-&lt;br /&gt;
| for (ct=0; ct&amp;lt;3; ct  ) {&lt;br /&gt;
|-&lt;br /&gt;
| for (pt=0; pt&amp;lt;2; pt  ) {&lt;br /&gt;
|-&lt;br /&gt;
| for (cg=0; cg&amp;lt;6; cg  ) {&lt;br /&gt;
|-&lt;br /&gt;
| for (node=0; node&amp;lt;11; node  ) {&lt;br /&gt;
|-&lt;br /&gt;
| if (flag1) { || 1 || [[#ract_pct|ract_pct]][ct][pt][cg][node] ||&lt;br /&gt;
|-&lt;br /&gt;
| coeff_model_ract[pt][ct][cg][node] = default_probability[node] || 7 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| } else if ([[#frame_mode|frame_mode]] == 0) {&lt;br /&gt;
|-&lt;br /&gt;
| coeff_model_ract[pt][ct][cg][node] = default_probability[node]&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== DC coefficient coding type model ====&lt;br /&gt;
&lt;br /&gt;
Every value in this model is calculated with the folowing formula:&lt;br /&gt;
&lt;br /&gt;
  coeff_model_dcct[pt][ctx][node] = ceil((coeff_model_dccv[pt][node] * [[#dccv_lc|dccv_lc]][node][ctx][0]) / 256)&lt;br /&gt;
                                      [[#dccv_lc|dccv_lc]][node][ctx][1];&lt;br /&gt;
&lt;br /&gt;
All the values in this model must be clipped between 1 and 254.&lt;br /&gt;
&lt;br /&gt;
==== AC coefficient coding type  model ====&lt;br /&gt;
&lt;br /&gt;
Every value in this model is calculated with the folowing formula:&lt;br /&gt;
&lt;br /&gt;
  coeff_model_act[pt][ct][cg][ctx][node] = ceil((coeff_model_ract[pt][ct][cg][node] * [[#ract_lc|ract_lc]][ct][cg][node][ctx][0]) / 256)&lt;br /&gt;
                                             [[#ract_lc|ract_lc]][ct][cg][node][ctx][1];&lt;br /&gt;
&lt;br /&gt;
All the values in this model must be clipped between 1 and 254.&lt;br /&gt;
&lt;br /&gt;
=== Macroblocks ===&lt;br /&gt;
&lt;br /&gt;
Here starts the main macroblocks parsing loop. Macroblocks are coded from left to right and from top to bottom of the final picture.&lt;br /&gt;
&lt;br /&gt;
==== MB type ====&lt;br /&gt;
&lt;br /&gt;
For non-key frames, [[MB]] parsing begin with the decoding of the type of the [[MB]].&lt;br /&gt;
&lt;br /&gt;
First we need to get the ctx value from [[#vector_predictor|vector_predictor]] with frame_type set to FRAME_PREVIOUS. Then we select the proper model which is [[#mb_type_model|mb_type_model]][ctx][prev_type] (prev_type is the type of the [[MB]] which was parsed just before this one).&lt;br /&gt;
The [[MB]] type parsing itself is done according to the selected mb_type_model which defines a binary tree of probabilities. This tree is described right below. In this tree, each [x] means get 1 bit in the input stream using mb_type_model[x] as probability for this bit. If bit is 0, go to the top branch, if it's 1, go to the bottom branch. The leaf indicate the final type of this MB.&lt;br /&gt;
&lt;br /&gt;
                                         -- [[#mb_inter_novec_pf|INTER_NOVEC_PF]]&lt;br /&gt;
                                        |&lt;br /&gt;
                               -- [4] -- &lt;br /&gt;
                              |         |&lt;br /&gt;
                              |          -- [[#mb_inter_delta_pf|INTER_DELTA_PF]]&lt;br /&gt;
                              |&lt;br /&gt;
                     -- [2] -- &lt;br /&gt;
                    |         |&lt;br /&gt;
                    |         |          -- [[#mb_inter_v1_pf|INTER_V1_PF]]&lt;br /&gt;
                    |         |         |&lt;br /&gt;
                    |          -- [5] -- &lt;br /&gt;
                    |                   |&lt;br /&gt;
                    |                    -- [[#mb_inter_v2_pf|INTER_V2_PF]]&lt;br /&gt;
                    |&lt;br /&gt;
           -- [1] -- &lt;br /&gt;
          |         |&lt;br /&gt;
          |         |                    -- [[#mb_intra|INTRA]]&lt;br /&gt;
          |         |                   |&lt;br /&gt;
          |         |          -- [6] -- &lt;br /&gt;
          |         |         |         |&lt;br /&gt;
          |         |         |          -- [[#mb_inter_4v|INTER_4V]]&lt;br /&gt;
          |         |         |&lt;br /&gt;
          |          -- [3] -- &lt;br /&gt;
          |                   |&lt;br /&gt;
          |                   |                    -- [[#mb_inter_novec_gf|INTER_NOVEC_GF]]&lt;br /&gt;
          |                   |                   |&lt;br /&gt;
          |                   |          -- [8] -- &lt;br /&gt;
          |                   |         |         |&lt;br /&gt;
          |                   |         |          -- [[#mb_inter_delta_gf|INTER_DELTA_GF]]&lt;br /&gt;
          |                   |         |&lt;br /&gt;
          |                    -- [7] -- &lt;br /&gt;
          |                             |&lt;br /&gt;
          |                             |          -- [[#mb_inter_v1_gf|INTER_V1_GF]]&lt;br /&gt;
          |                             |         |&lt;br /&gt;
          |                              -- [9] -- &lt;br /&gt;
          |                                       |&lt;br /&gt;
          |                                        -- [[#mb_inter_v2_gf|INTER_V2_GF]]&lt;br /&gt;
          |&lt;br /&gt;
 -- [0] -- &lt;br /&gt;
          |&lt;br /&gt;
           -- prev_type&lt;br /&gt;
&lt;br /&gt;
==== Motion vector ====&lt;br /&gt;
&lt;br /&gt;
The motion vector applies to all the blocks in the [[MB]] except in the case of [[#Four motion vectors|four motion vectors]]&lt;br /&gt;
There are different kind of [[MV]] decoding depending on [[MB]] type :&lt;br /&gt;
&lt;br /&gt;
===== Straight vector candidate =====&lt;br /&gt;
Apply to the following [[MB]] types: [[#mb_inter_v1_pf|INTER_V1_PF]], [[#mb_inter_v2_pf|INTER_V2_PF]], [[#mb_inter_v1_gf|INTER_V1_GF]], [[#mb_inter_v2_gf|INTER_V2_GF]]&lt;br /&gt;
&lt;br /&gt;
The motion vector is the first (for V1) or second (for V2) candidate from [[#vector_predictor|vector_predictor]] with frame_type set either to FRAME_PREVIOUS (for PF) or to FRAME_GOLDEN (for GF).&lt;br /&gt;
&lt;br /&gt;
===== Delta vector =====&lt;br /&gt;
Apply to the following [[MB]] types: [[#mb_inter_delta_pf|INTER_DELTA_PF]], [[#mb_inter_delta_gf|INTER_DELTA_GF]]&lt;br /&gt;
&lt;br /&gt;
Default delta, di1, di2 and neg value is 0.&lt;br /&gt;
You then need to apply the following parsing first with comp = 0 (for component x of the vector) and then with comp = 1 (for component y of the vector):&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Syntax !! Number of bits !! Probability || Semantics&lt;br /&gt;
|-&lt;br /&gt;
| if (flag1) { || 1 || vector_model_dct[comp] ||&lt;br /&gt;
|-&lt;br /&gt;
| neg || 1 || vector_model_sig[comp] ||&lt;br /&gt;
|-&lt;br /&gt;
| di1 || 1 || vector_model_pdi[comp][0] ||&lt;br /&gt;
|-&lt;br /&gt;
| di2 || 1 || vector_model_pdi[comp][1] ||&lt;br /&gt;
|-&lt;br /&gt;
| delta || || || here a binary tree parsing happens (see below)&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The delta parsing itself is done according to vector_model_pdv[comp] which defines a binary tree of probabilities. This tree is described right below. In this tree, each [x] means get 1 bit in the input stream using vector_model_pdv[comp][x] as probability for this bit. If bit is 0, go to the top branch, if it's 1, go to the bottom branch. The leaf indicate the final value of delta.&lt;br /&gt;
&lt;br /&gt;
                               -- 0&lt;br /&gt;
                     -- [2] -- &lt;br /&gt;
                    |          -- 1&lt;br /&gt;
           -- [1] -- &lt;br /&gt;
          |         |          -- 2&lt;br /&gt;
          |          -- [3] -- &lt;br /&gt;
          |                    -- 3&lt;br /&gt;
 -- [0] -- &lt;br /&gt;
          |                    -- 4&lt;br /&gt;
          |          -- [5] -- &lt;br /&gt;
          |         |          -- 5&lt;br /&gt;
           -- [4] -- &lt;br /&gt;
                    |          -- 6&lt;br /&gt;
                     -- [6] -- &lt;br /&gt;
                               -- 7&lt;br /&gt;
&lt;br /&gt;
When the value of delta, di1, di2 and neg are parsed, the value of the current vector component can be calculated this way:&lt;br /&gt;
  component = (1-2*neg) * (di1 | (di2 &amp;lt;&amp;lt; 1) | (delta &amp;lt;&amp;lt; 2))&lt;br /&gt;
&lt;br /&gt;
===== Four motion vectors =====&lt;br /&gt;
Apply to the following [[MB]] types: [[#mb_inter_4v|INTER_4V]]&lt;br /&gt;
&lt;br /&gt;
For this type of [[MB]] each of the 4 luma block of the [[MB]] use a different [[MV]]. So each of this 4 luma block has it's own block type. This block type can only be one which refers to PREVIOUS_FRAME (ie. [[#mb_inter_v1_pf|INTER_V1_PF]], [[#mb_inter_v2_pf|INTER_V2_PF]], [[#mb_inter_delta_pf|INTER_DELTA_PF]], [[#mb_inter_novec_pf|INTER_NOVEC_PF]]).&lt;br /&gt;
&lt;br /&gt;
Those 4 block types should be parsed this way:&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Syntax !! Number of bits !! Probability || Semantics&lt;br /&gt;
|-&lt;br /&gt;
| for (block=0; block&amp;lt;4; block  ) {&lt;br /&gt;
|-&lt;br /&gt;
| type[block] || 2 || 128 ||&lt;br /&gt;
|-&lt;br /&gt;
| if (type[block] != INTER_NOVEC_PF) {&lt;br /&gt;
|-&lt;br /&gt;
| type[block]  &lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Then for each of the 4 luma blocks it's [[MV]] is calculated the same way as if it were a full [[MB]], according to it's block type.&lt;br /&gt;
&lt;br /&gt;
The [[MV]] of the 2 chroma block is then calculated as the average of the 4 luma [[MV]].&lt;br /&gt;
&lt;br /&gt;
===== Zero vector =====&lt;br /&gt;
Apply to all the other [[MB]] types.&lt;br /&gt;
&lt;br /&gt;
This is simply a null vector.&lt;br /&gt;
&lt;br /&gt;
==== MB coefficients ====&lt;br /&gt;
&lt;br /&gt;
This is the real content of the [[MB]], ie. the data which will be feeded to the [[#Inverse DCT|Inverse DCT]].&lt;br /&gt;
&lt;br /&gt;
This procedure is repeated 6 times (for each block in the [[MB]], with block_num being the num of the block in the [[MB]] between 0 and 5). It uses several initialized variables :&lt;br /&gt;
* ct: code type, initialized to 1&lt;br /&gt;
* pt: plane type, initialized to 0 for luma blocks and 1 for chroma blocks&lt;br /&gt;
* ctx_last: initialized to the maximum coeff_idx of previous block on the same row and normalized to a maximal value of 24 (initialized to 24 at the start of a row).&lt;br /&gt;
* above_block_ndc: initialized to 0 if the DC coefficient of the block just above the current one is null, 1 else&lt;br /&gt;
* bi: initialized to 0 for blocks 0 and 1, 1 for blocks 2 and 3, 2 for block 4, and 3 for block 5&lt;br /&gt;
* coeff_ctx: this array is filled with 0 at the begining of each macroblock row&lt;br /&gt;
&lt;br /&gt;
  for (coeff_idx=0; coeff_idx&amp;lt;64; coeff_idx  ) {&lt;br /&gt;
      /* select the correct models */&lt;br /&gt;
      if (coeff_idx == 0) {  /* DC coeff */&lt;br /&gt;
          ctx = 6*coeff_ctx[bi][0]   above_block_ndc;&lt;br /&gt;
          m1 = coeff_model_dccv[pt];&lt;br /&gt;
          m2 = coeff_model_dcct[pt][ctx];&lt;br /&gt;
      } else {               /* AC coeff */&lt;br /&gt;
          int cg = coeff_groups[coeff_idx];&lt;br /&gt;
          ctx = coeff_ctx[bi][coeff_idx];&lt;br /&gt;
          m1 = coeff_model_ract[pt][ct][cg];&lt;br /&gt;
          m2 = cg &amp;gt; 2 ? model : coeff_model_act[pt][ct][cg][ctx];&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      /*&lt;br /&gt;
       * Here applies a binary tree parssing as defined below.&lt;br /&gt;
       */&lt;br /&gt;
      &lt;br /&gt;
      block_coeff[block_num][coeff_idx] = (coeff ^ -sign)   sign;&lt;br /&gt;
      coeff_ctx[bi][coeff_idx] = cctx;&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  if (coeff_idx &amp;lt; ctx_last) {&lt;br /&gt;
      for (i=coeff_idx; i&amp;lt;=ctx_last; i  )&lt;br /&gt;
          coeff_ctx[bi][i] = 5;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
The following binary tree parsing allows to extract coefficients of the block plus other parameters useful for the decoding procedure itself. In this tree, each m1[x] or m2[x] means get 1 bit in the input stream using m1[x] or m2[x] as probability for this bit. If bit is 0, go to the top branch, if it's 1, go to the bottom branch. The leaf indicate the value extracted at the end of this tree parsing.&lt;br /&gt;
&lt;br /&gt;
                     -- end of this block (break out of the loop)&lt;br /&gt;
                    |&lt;br /&gt;
           - m2[1] - &lt;br /&gt;
          |         |&lt;br /&gt;
          | if !ct  |&lt;br /&gt;
           --------- -- ct=0, cctx=0&lt;br /&gt;
          |&lt;br /&gt;
 - m2[0] - &lt;br /&gt;
          |&lt;br /&gt;
          |          -- ct=1, cctx=1, sign=get_bit(), coeff=1&lt;br /&gt;
          |         |&lt;br /&gt;
           - m2[2] - &lt;br /&gt;
                    |                    -- ct=2, cctx=2, sign=get_bit(), coeff=2&lt;br /&gt;
                    |                   |&lt;br /&gt;
                    |          - m2[4] - &lt;br /&gt;
                    |         |         |          -- ct=2, cctx=3, sign=get_bit(), coeff=3&lt;br /&gt;
                    |         |         |         |&lt;br /&gt;
                    |         |          - m2[5] - &lt;br /&gt;
                    |         |                   |&lt;br /&gt;
                    |         |                    -- ct=2, cctx=3, sign=get_bit(), coeff=4&lt;br /&gt;
                     - m2[3] - &lt;br /&gt;
                              |&lt;br /&gt;
                              |&lt;br /&gt;
                              |                    -- ct=2, cctx=4, sign=get_bit(), coeff=[[#coeff_parse|coeff_parse]](0)&lt;br /&gt;
                              |                   |&lt;br /&gt;
                              |          - m1[7] - &lt;br /&gt;
                              |         |         |&lt;br /&gt;
                              |         |          -- ct=2, cctx=4, sign=get_bit(), coeff=[[#coeff_parse|coeff_parse]](1)&lt;br /&gt;
                              |         |&lt;br /&gt;
                               - m1[6] - &lt;br /&gt;
                                        |&lt;br /&gt;
                                        |                    -- ct=2, cctx=4, sign=get_bit(), coeff=[[#coeff_parse|coeff_parse]](2)&lt;br /&gt;
                                        |                   |&lt;br /&gt;
                                        |          - m1[9] - &lt;br /&gt;
                                        |         |         |&lt;br /&gt;
                                        |         |          -- ct=2, cctx=4, sign=get_bit(), coeff=[[#coeff_parse|coeff_parse]](3)&lt;br /&gt;
                                        |         |&lt;br /&gt;
                                         - m1[8] - &lt;br /&gt;
                                                  |&lt;br /&gt;
                                                  |          -- ct=2, cctx=4, sign=get_bit(), coeff=[[#coeff_parse|coeff_parse]](4)&lt;br /&gt;
                                                  |         |&lt;br /&gt;
                                                   - m1[10]  &lt;br /&gt;
                                                            |&lt;br /&gt;
                                                             -- ct=2, cctx=4, sign=get_bit(), coeff=[[#coeff_parse|coeff_parse]](5)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;span id=&amp;quot;coeff_parse&amp;quot;&amp;gt;coeff_parse&amp;lt;/span&amp;gt; algorithm used by the previous binary tree parsing takes one parameter called idx and behave like this :&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Syntax !! Number of bits !! Probability || Semantics&lt;br /&gt;
|-&lt;br /&gt;
| coeff = [[#coeff_bias|coeff_bias]][idx]&lt;br /&gt;
|-&lt;br /&gt;
| for (i=[[#coeff_bit_length|coeff_bit_length]][idx]; i&amp;gt;=0; i--) {&lt;br /&gt;
|-&lt;br /&gt;
| v || 1 || [[#coeff_parse_table|coeff_parse_table]][idx][i] ||&lt;br /&gt;
|-&lt;br /&gt;
| coeff  = v &amp;lt;&amp;lt; i&lt;br /&gt;
|-&lt;br /&gt;
| }&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Algorithms ==&lt;br /&gt;
&lt;br /&gt;
=== Entropy Coding ===&lt;br /&gt;
&lt;br /&gt;
Described here is the decoding process for the arithmetically-coded (AC) parts of the bitstream.  VP5 uses a 16-bit [http://en.wikipedia.org/wiki/Range_encoding range coding] scheme to code binary symbols.&lt;br /&gt;
&lt;br /&gt;
The AC decoder maintains three state variables:  ''code'', ''mask'' and ''high''.  &lt;br /&gt;
&lt;br /&gt;
==== Initialization ====&lt;br /&gt;
&lt;br /&gt;
At initialization, the first two bytes of the AC bitstream are shifted into ''code''.  The variable ''high'' is set to 0xff00.  The variable ''mask'' is set to 0xffff.&lt;br /&gt;
&lt;br /&gt;
==== Decoding a Binary Value ====&lt;br /&gt;
&lt;br /&gt;
Each binary symbol has an associated probability ''p'' in the range 0 to 0xff.  &lt;br /&gt;
&lt;br /&gt;
A threshold, ''t'', is computed thus:&lt;br /&gt;
&lt;br /&gt;
: ''t'' = 0x100   ( 0xff00&lt;/div&gt;</summary>
		<author><name>QxvP4q</name></author>
	</entry>
</feed>