📄 vp3-format.txt
字号:
(0, -1). The next 3 bits are 6 which indicate 8 + next 3 bits (7) withanother bit indicating sign (1 in this case, which is negative). Thus,the X MV component is -15. The next 3 bits are 4 which indicate a Y MVcomponent of 3 with one more bit for the sign (0 is positive). So thesecond motion vector encoded in this stream is (-15, 3).As an example of the fixed-length entropy method, consider the followingcontrived bitstream: 1010101101010...The stream is read as: 1 01010 1 10101 0The first bit indicates the fixed length entropy method. The first 5 bitsare 10 followed by a negative sign bit. The next 5 bits are 21 followed bya positive sign bit. The first motion vector in this stream is (-10, 21).During this phase of the decoding process, it is traditional to assign allmotion vectors for all coded macroblocks that require them, whether theyare unpacked from the motion vector bitstream or copied from previouscoded macroblocks. It is necessary to track the motion vectors for boththe previous macroblock as well as the next-to-last (prior) macroblock.The general algorithm for this phase is as follows: foreach coded macroblock last MV = 0 prior last MV = 0 if coding mode = MODE_INTER_PLUS_MV or MODE_GOLDEN_MV read current MV pair from the bitstream and set all fragment motion vectors to that pair prior last MV = last MV last MV = current MV if coding mode = MODE_INTER_FOURMV read MV for first Y fragment in macroblock read MV for second Y fragment in macroblock read MV for third Y fragment in macroblock read MV for fourth Y fragment in macroblock set U & V fragment motion vectors to average of 4 Y vectors, calculated as follows: if sum of all 4 X motion components is positive, the X motion component for the U & V fragments is (sum + 2) / 4, otherwise, it is (sum - 2) / 4; repeat the same process for the Y components prior last MV = last MV last MV = MV for fourth Y fragment from this macroblock if coding mode = MODE_INTER_LAST_MV motion vectors for this macroblock are the same as last MV; note that in this case, the last MV remains the last MV and the prior last MV remains the prior last MV if coding mode = MODE_INTER_PRIOR_LAST motion vectors for this macroblock are the same as prior last MV prior last MV = last MV last MV = current MV (effectively, swap last and prior last vectors)Unpacking The DCT Coefficients------------------------------After unpacking the macroblock motion vectors, the decoder unpacks thefragment DCT coefficient data. Each coded fragment has 64 DCT coefficients. Some of the coefficients will be non-zero. Many of the coefficients will, or should be 0 as this is where the coding methodderives much of its compression.During this phase, the decoder will be unpacking DCT coefficients, zeroruns, and end-of-block (EOB) codes. The decoder unpacks the the DC coefficients for all fragments, then all of the first AC coefficients, and so on until all of the 64 DCT coefficients are unpacked from thebitstream.To obtain the DCT coefficients, the decoder unpacks a series of VLCsfrom the bitstream which turn into a series of tokens ranging from0..31. Each of these tokens specifies which action to take next. VP3defines 80 different 32-element histograms for VLC decoding: 16 histograms for DC token decoding 16 histograms for group 1 AC token decoding 16 histograms for group 2 AC token decoding 16 histograms for group 3 AC token decoding 16 histograms for group 4 AC token decodingThe decoder fetches 4 bits from the bitstream that will be used toselect a DC histogram and 4 bits that will be used to select 4 AChistograms, one for each AC group.The meaning of each of the 32 possible tokens follows. 'EB' stands forextra bits read from bitstream directly after the VLC token:0, DCT_EOB_TOKENset the current block to EOB, meaning that the block is marked as beingfully unpacked1, DCT_EOB_PAIR_TOKENset the next 2 blocks to EOB2. DCT_EOB_TRIPLE_TOKENset the next 3 blocks to EOB3, DCT_REPEAT_RUN_TOKENset the next (2 EBs + 4) blocks to EOB4, DCT_REPEAT_RUN2_TOKENset the next (3 EBs + 8) blocks to EOB5, DCT_REPEAT_RUN3_TOKENset the next (4 EBs + 16) blocks to EOB6, DCT_REPEAT_RUN4_TOKENset the next (12 EBs) blocks to EOB7, DCT_SHORT_ZRL_TOKENskip (3 EBs + 1) positions in the output matrix8, DCT_ZRL_TOKENskip (6 EBs + 1) positions in the output matrix9, ONE_TOKENoutput 1 as coefficient10, MINUS_ONE_TOKENoutput -1 as coefficient11, TWO_TOKENoutput 2 as coefficient12, MINUS_TWO_TOKENoutput -2 as coefficient13, 14, 15, 16, LOW_VAL_TOKENSnext EB determines coefficient sign; coeff = DCT_VAL_CAT2_MIN (3) +(token - 13) (this gives a range of +/- 3..6)17, DCT_VAL_CATEGORY3next EB determines coefficient sign; coeff = DCT_VAL_CAT3_MIN (7) + nextEB (this gives a range of +/- 7..8)18, DCT_VAL_CATEGORY4next EB determines coefficient sign; coeff = DCT_VAL_CAT4_MIN (9) + next2 EBs (this gives a range of +/- 9..12)19, DCT_VAL_CATEGORY5next EB determines coefficient sign; coeff = DCT_VAL_CAT5_MIN (13) +next 3 EBs (this gives a range of +/- 13..20)20, DCT_VAL_CATEGORY6next EB determines coefficient sign; coeff = DCT_VAL_CAT6_MIN (21) +next 4 EBs (this gives a range of +/- 21..36)21, DCT_VAL_CATEGORY7next EB determines coefficient sign; coeff = DCT_VAL_CAT7_MIN (37) +next 5 EBs (this gives a range of +/- 37..68)22, DCT_VAL_CATEGORY8next EB determines coefficient sign; coeff = DCT_VAL_CAT8_MIN (69) +next 9 EBs (this gives a range of +/- 69..580)23, 24, 25, 26, 27, DCT_RUN_CATEGORY1coefficient of +/- 1 preceded by a number of 0s; next EB determines signof coefficient; skip (token - 22) 0s in the output matrix beforeplacing the final coefficient (this gives a range of 1..5 0s)28, DCT_RUN_CATEGORY1Bcoefficient of +/- 1 preceded by a number of 0s; next EB determines signof coefficient; skip (next 2 EBs + 6) 0s in the output matrix beforeplacing the final coefficient (this gives a range of 6..9 0s)29, DCT_RUN_CATEGORY1Ccoefficient of +/- 1 preceded by a number of 0s; next EB determines signof coefficient; skip (next 3 EBs + 10) 0s in the output matrix beforeplacing the final coefficient (this gives a range of 10..17 0s)30, DCT_RUN_CATEGORY2coefficient of +/- 2..3 preceded by a single zero; next EB determinessign of coefficient; coefficient = (next EB + 2)31, DCT_RUN_CATEGORY2B (not specifically named in VP3 source)coefficient of +/- 2..3 preceded by 2 or 3 0s; next EB determinessign of coefficient; coefficient = (next EB + 2); skip (next EB + 2) 0sbefore placing coefficient in output matrixNote: EOB runs can, and often do, cross threshold stages and planeboundaries. For example, a decoder may have decoded all of the AC #2coefficients for all fragments and still have an EOB run of 2. Thatmeans that during the AC #3 decode process, the first 2 coded fragmentsthat are not already EOB will be set to EOB.Let's work through a highly contrived example to illustrate thecoefficient decoding process.[not finished]When the decoder is finished unpacking the DCT coefficients, the entireencoded VP3 frame bitstream should be consumed.Reversing The DC Prediction---------------------------Now that all of the DCT coefficient data has been unpacked, the DCcoefficients need to be fully reconstructed before the IDCT can beperformed.VP3 uses a somewhat involved process for DC prediction which uses up tofour DC coefficients from surrounding fragments. For each fragment to betransformed with the IDCT, the DC coefficient is predicted from weightedsum of the DC coefficients in the left (l), up-left (ul), up (u), andup-right (ur) fragments, if they are coded (not unchanged from theprevious frame) in a compatible frame (current, previous, or golden).In a golden frame, the prediction is quite straightforward since allfragments will be coded. A fragment's DC prediction will fall into 1 of5 groups: abbbbbbbbb cdddddddde cdddddddde cdddddddde cdddddddde* Group a is the top left corner fragment. There is nothing to predictfrom. This DC coefficient has a lot of energy and requires many bits tocode.* Group b is the remainder of the top row of fragments. These fragmentscan only predict from the left fragment.* Group c is the left column of fragments, not including the top leftfragment. These fragments have the top and top-right fragments fromwhich to predict.* Group d is the main body of fragments. These fragments have access toall 4 predictors.* Group e is the right column of fragments, not including the top rightfragment. These fragments can predict from the left, up-left and upfragments.The process of reversing prediction for interframes grows more complex.First, the decoder must evaluate which candidate fragments (l, ul, u, orur) are available for as predictors. Then, it can only use fragmentsthat are coded within the same frame (current, previous, or golden).Further, there are auxiliary predictors for each frame type that areinitialized to 0 at the start of each video frame decode operation. Thedecoder falls back on these auxiliary predictors when it can not findany valid candidate predictors for the current fragment.To work through some examples, consider the following notation, e.g.: ul-C = up-left fragment, coded in the current frame u-P = up fragment, coded as a motion residual from the previous frame ur-C = up-right fragment, coded in the current frame l-G = left fragment, coded as a motion residual from the golden frame x-P = current fragment where DC prediction is being performed, coded as a motion residual from the previous frameThis is a simple case: ul-C u-C ur-C l-C x-CThe current fragment predicts from all four of the candidate fragmentssince they are coded in the same frame. ul-P u-C ur-C l-P x-PThe current fragment predicts from the left and up-left fragments. ul-C u-P ur-G l-P x-GThe current fragment predicts from the up-right fragment. ul-C u-C ur-C l-C x-GThe current fragment does not predict from any of the candidatefragments since the current fragment is a motion residual from thegolden frame. Rather, add the auxiliary golden frame predictor to thecurrent fragment's DC coefficient. Save the new DC coefficient as thenew golden frame auxiliary DC predictor.If the decoder only finds one valid candidate predictor, then it is usedby itself. When the decoder finds multiple valid candidate fragmentsfrom which to predict DC, it applies a weighting function to thesurrounding fragments' DC coefficients. The following table presents all 16 possible combinations of available/not available predictors and what to do in each case: ul u ur l -- -- -- -- 0 0 0 0 no predictors available: use the last predictor saved for the frame type (either intra, inter, or golden) 0 0 0 1 left predictor available: pred = l.dc 0 0 1 0 up-right predictor available: pred = ur.dc 0 0 1 1 up-right, left predictors available: pred = (53 * ur.dc) + (75 * l.dc) -------------------------- 128 0 1 0 0 up predictor available: pred = u.dc 0 1 0 1 up, left predictors available: pred = (u.dc + l.dc) ------------- 2 0 1 1 0 up, up-right predictors available: discard up-right predictor pred = u.dc 0 1 1 1 up, up-right, left predictors available:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -