#LyX 1.3 created this file. For more info see http://www.lyx.org/ \lyxformat 221 \textclass article \language english \inputencoding auto \fontscheme default \graphics default \paperfontsize default \spacing single \papersize Default \paperpackage a4 \use_geometry 0 \use_amsmath 0 \use_natbib 0 \use_numerical_citations 0 \paperorientation portrait \secnumdepth 3 \tocdepth 3 \paragraph_separation skip \defskip medskip \quotes_language english \quotes_times 2 \papercolumns 1 \papersides 1 \paperpagestyle default \layout Title \noindent ASUS V1/V2 Codecs \layout Standard \begin_inset LatexCommand \tableofcontents{} \end_inset \layout Section Introduction \layout Standard ASV1/2 are purely intracoded DCT-based codecs, with a per file quantization parameter (QP), use 4:2:0 YCbCr colorspace and operate on macroblocks. \newline The latest version of this document is available at http://www.mplayerhq.hu/~micha el/asv1.{lyx,txt,html,ps} \layout Standard \noindent This document assumes familiarity with mathematical and coding concepts such as the discrete cosine transform, quantization, YUV (YCbCr) colorspaces, macroblocks, and variable length codes (VLCs). \layout Section Terms and definitions \layout List \labelwidthstring 00.00.0000 AC Any DCT coefficient for which the frequency in one or both both dimensions in non-zero. \layout List \labelwidthstring 00.00.0000 DC The DCT coefficient for which the frequency is zero in both dimensions \layout List \labelwidthstring 00.00.0000 QP Quantization Parameter \layout List \labelwidthstring 00.00.0000 (I)DCT (Inverse) Discrete Cosine Transform \layout List \labelwidthstring 00.00.0000 VLC Variable Length Code \layout Section Highlevel Description \layout Subsection Picture \layout Standard The picture is split into macroblocks which are coded left->right, top->bottom, as long as MBs are completely within the width/height area that is divisible by 16. If width is not divisible by 16, the right column is coded after the main body. If height is not divisible by 16, the bottom strip is coded after the right column. \layout Standard Example: 56x56 sized image \layout Standard \begin_inset Tabular \begin_inset Text \layout Standard 0 \end_inset \begin_inset Text \layout Standard 1 \end_inset \begin_inset Text \layout Standard 2 \end_inset \begin_inset Text \layout Standard 9 \end_inset \begin_inset Text \layout Standard 3 \end_inset \begin_inset Text \layout Standard 4 \end_inset \begin_inset Text \layout Standard 5 \end_inset \begin_inset Text \layout Standard 10 \end_inset \begin_inset Text \layout Standard 6 \end_inset \begin_inset Text \layout Standard 7 \end_inset \begin_inset Text \layout Standard 8 \end_inset \begin_inset Text \layout Standard 11 \end_inset \begin_inset Text \layout Standard 12 \end_inset \begin_inset Text \layout Standard 13 \end_inset \begin_inset Text \layout Standard 14 \end_inset \begin_inset Text \layout Standard 15 \end_inset \end_inset \layout Subsection Macroblock \layout Standard 16x16 luma + 8x8 chroma as 4 8x8 luma blocks and 2 8x8 chroma blocks \newline Y: \begin_inset Tabular \begin_inset Text \layout Standard 0 \end_inset \begin_inset Text \layout Standard 1 \end_inset \begin_inset Text \layout Standard 2 \end_inset \begin_inset Text \layout Standard 3 \end_inset \end_inset Cb: \begin_inset Tabular \begin_inset Text \layout Standard 4 \end_inset \end_inset Cr: \begin_inset Tabular \begin_inset Text \layout Standard 5 \end_inset \end_inset \layout Subsection Block \layout Standard Contains 64(=8x8) coefficients in 16(=4x4) coefficient groups with 4(=2x2) coefficients each \newline \begin_inset Tabular \begin_inset Text \layout Standard 0 \end_inset \begin_inset Text \layout Standard 1 \end_inset \begin_inset Text \layout Standard 5 \end_inset \begin_inset Text \layout Standard 9 \end_inset \begin_inset Text \layout Standard 2 \end_inset \begin_inset Text \layout Standard 3 \end_inset \begin_inset Text \layout Standard 8 \end_inset \begin_inset Text \layout Standard 12 \end_inset \begin_inset Text \layout Standard 4 \end_inset \begin_inset Text \layout Standard 7 \end_inset \begin_inset Text \layout Standard 11 \end_inset \begin_inset Text \layout Standard 14 \end_inset \begin_inset Text \layout Standard 6 \end_inset \begin_inset Text \layout Standard 10 \end_inset \begin_inset Text \layout Standard 13 \end_inset \begin_inset Text \layout Standard 15 \end_inset \end_inset \layout Standard Coefficients in the coefficient groups 10..15 cannot be coded (they must be 0) in ASV1. \newline The first coefficient (DC coefficient) in the first coefficient group must be coded as 0. Note it is coded seperately in the 8 bits prior to the AC coefficients. \layout Subsection Coefficient group \layout Standard \begin_inset Tabular \begin_inset Text \layout Standard 0 \end_inset \begin_inset Text \layout Standard 1 \end_inset \begin_inset Text \layout Standard 2 \end_inset \begin_inset Text \layout Standard 3 \end_inset \end_inset \layout Subsection DC coefficient Dequantization \layout Standard \begin_inset Formula $c_{00}'=8c_{00}$ \end_inset \layout List \labelwidthstring 00.00.0000 \begin_inset Formula $c_{00}$ \end_inset quantized and coded DC coefficient \layout List \labelwidthstring 00.00.0000 \begin_inset Formula $c_{00}'$ \end_inset unquantized DC coefficient \layout Subsection AC coefficient Dequantization \layout Paragraph \begin_inset Formula $c_{xy}'=\frac{c_{xy}}{16}\left\lfloor \frac{Dq_{xy}}{QP}\right\rfloor $ \end_inset \layout List \labelwidthstring 00.00.0000 QP Quantization Parameter from the global header \layout List \labelwidthstring 00.00.0000 D 64 for ASV1, 128 forASV2 \layout List \labelwidthstring 00.00.0000 c quantized and coded coefficient \layout List \labelwidthstring 00.00.0000 c' unquantized coefficient \layout List \labelwidthstring 00.00.0000 q ISO MPEG1 intra quantization matrix \layout Section Bitstream \layout Standard The bitstream in ASV1 is stored with byte-swapped 32bit words (24..31, 16..23, 8..15, 0..7, 56..63, 48..55, 40..47, 32..39, ...) \layout Standard The bitstream in ASV2 is stored with the bits in each byte reversed so (7..0, 15..8, 23..16, 31..24, 39..32, ...) \layout Subsection Fourcc \layout Standard ASV1 / ASV2 \layout Subsection Global (per file) Header \layout Standard \begin_inset Tabular \begin_inset Text \layout Standard Length in bits \end_inset \begin_inset Text \layout Standard Value \end_inset \begin_inset Text \layout Standard 8 \end_inset \begin_inset Text \layout Standard QP \end_inset \begin_inset Text \layout Standard 24 \end_inset \begin_inset Text \layout Standard unkown, 0 for ASV1 \end_inset \begin_inset Text \layout Standard 8 \end_inset \begin_inset Text \layout Standard 'A' \end_inset \begin_inset Text \layout Standard 8 \end_inset \begin_inset Text \layout Standard 'S' \end_inset \begin_inset Text \layout Standard 8 \end_inset \begin_inset Text \layout Standard 'U' \end_inset \begin_inset Text \layout Standard 8 \end_inset \begin_inset Text \layout Standard 'S' \end_inset \end_inset \layout Subsection Macroblock \layout Standard Simply the bitstream of the 6 blocks \layout Subsection ASV1 Block \layout List \labelwidthstring 00.00.0000 8-bit DC coefficient \layout List \labelwidthstring 00.00.0000 . for each coefficient group \begin_deeper \layout List \labelwidthstring 00.00.0000 2-5bit Coded coefficient pattern \layout List \labelwidthstring 00.00.0000 . for each coded coefficient \begin_deeper \layout List \labelwidthstring 00.00.0000 2-11bit level \end_deeper \end_deeper \layout List \labelwidthstring 00.00.0000 5bit End Of Block \layout Subsection ASV2 Block \layout List \labelwidthstring 00.00.0000 4-bit coefficient group count \layout List \labelwidthstring 00.00.0000 8-bit DC coefficient \layout List \labelwidthstring 00.00.0000 2-4bit First Coded coefficient pattern \layout List \labelwidthstring 00.00.0000 . for each coded coefficient \begin_deeper \layout List \labelwidthstring 00.00.0000 2-13bit level \end_deeper \layout List \labelwidthstring 00.00.0000 . for each coefficient group \begin_deeper \layout List \labelwidthstring 00.00.0000 2-6bit Coded coefficient pattern \layout List \labelwidthstring 00.00.0000 . for each coded coefficient \begin_deeper \layout List \labelwidthstring 00.00.0000 2-13bit level \end_deeper \end_deeper \layout Section VLC Codes \layout Subsection ASV1 \layout Subsubsection Level \layout Standard \begin_inset Tabular \begin_inset Text \layout Standard 0011 \end_inset \begin_inset Text \layout Standard -3 \end_inset \begin_inset Text \layout Standard 011 \end_inset \begin_inset Text \layout Standard -2 \end_inset \begin_inset Text \layout Standard 11 \end_inset \begin_inset Text \layout Standard -1 \end_inset \begin_inset Text \layout Standard 000xxxxxxxx \end_inset \begin_inset Text \layout Standard xxxxxxxx \end_inset \begin_inset Text \layout Standard 10 \end_inset \begin_inset Text \layout Standard 1 \end_inset \begin_inset Text \layout Standard 010 \end_inset \begin_inset Text \layout Standard 2 \end_inset \begin_inset Text \layout Standard 0010 \end_inset \begin_inset Text \layout Standard 3 \end_inset \end_inset \layout Standard xxxxxxxx is a twos complement signed 8 bit nubmer (=int8_t) \layout Subsubsection Coded coefficient pattern \layout Standard \begin_inset Tabular \begin_inset Text \layout Standard 00001 \end_inset \begin_inset Text \layout Standard 14 \end_inset \begin_inset Text \layout Standard 00010 \end_inset \begin_inset Text \layout Standard 13 \end_inset \begin_inset Text \layout Standard ... \end_inset \begin_inset Text \layout Standard ... \end_inset \begin_inset Text \layout Standard 01101 \end_inset \begin_inset Text \layout Standard 2 \end_inset \begin_inset Text \layout Standard 01110 \end_inset \begin_inset Text \layout Standard 1 \end_inset \begin_inset Text \layout Standard 01111 \end_inset \begin_inset Text \layout Standard EOB \end_inset \begin_inset Text \layout Standard 10 \end_inset \begin_inset Text \layout Standard 0 \end_inset \begin_inset Text \layout Standard 11 \end_inset \begin_inset Text \layout Standard 15 \end_inset \end_inset \layout Subsection ASV2 \layout Subsubsection First Coded coefficient pattern \layout Standard \begin_inset Tabular \begin_inset Text \layout Standard VLC \end_inset \begin_inset Text \layout Standard CCP \end_inset \begin_inset Text \layout Standard 00 \end_inset \begin_inset Text \layout Standard 0111 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 01 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0000 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 100 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0110 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 101 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0100 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1100 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0011 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1101 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0001 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1110 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0101 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1111 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0010 \end_inset \end_inset \layout Subsubsection Coded coefficient pattern \layout Standard \begin_inset Tabular \begin_inset Text \layout Standard VLC \end_inset \begin_inset Text \layout Standard CCP \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 00 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0000 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 010 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0100 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 011 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1000 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1000 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1010 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1001 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1100 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1010 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0010 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1011 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1101 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1100 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1111 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1101 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1110 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 111000 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0111 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 111001 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0101 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 111010 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0011 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 111011 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0001 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 111100 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 0110 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 111101 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1001 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 11111 \end_inset \begin_inset Text \layout Standard \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none 1011 \end_inset \end_inset \layout Subsubsection Level \layout Standard \begin_inset Tabular \begin_inset Text \layout Standard 0000111111 \end_inset \begin_inset Text \layout Standard -31 \end_inset \begin_inset Text \layout Standard ... \end_inset \begin_inset Text \layout Standard ... \end_inset \begin_inset Text \layout Standard 001111 \end_inset \begin_inset Text \layout Standard -7 \end_inset \begin_inset Text \layout Standard 001011 \end_inset \begin_inset Text \layout Standard -6 \end_inset \begin_inset Text \layout Standard 001101 \end_inset \begin_inset Text \layout Standard -5 \end_inset \begin_inset Text \layout Standard 001001 \end_inset \begin_inset Text \layout Standard -4 \end_inset \begin_inset Text \layout Standard 0111 \end_inset \begin_inset Text \layout Standard -3 \end_inset \begin_inset Text \layout Standard 0101 \end_inset \begin_inset Text \layout Standard -2 \end_inset \begin_inset Text \layout Standard 11 \end_inset \begin_inset Text \layout Standard -1 \end_inset \begin_inset Text \layout Standard 00000xxxxxxxx \end_inset \begin_inset Text \layout Standard xxxxxxxx \end_inset \begin_inset Text \layout Standard 10 \end_inset \begin_inset Text \layout Standard 1 \end_inset \begin_inset Text \layout Standard 0100 \end_inset \begin_inset Text \layout Standard 2 \end_inset \begin_inset Text \layout Standard 0110 \end_inset \begin_inset Text \layout Standard 3 \end_inset \begin_inset Text \layout Standard 001000 \end_inset \begin_inset Text \layout Standard 4 \end_inset \begin_inset Text \layout Standard 001100 \end_inset \begin_inset Text \layout Standard 5 \end_inset \begin_inset Text \layout Standard 001010 \end_inset \begin_inset Text \layout Standard 6 \end_inset \begin_inset Text \layout Standard 001110 \end_inset \begin_inset Text \layout Standard 7 \end_inset \begin_inset Text \layout Standard ... \end_inset \begin_inset Text \layout Standard ... \end_inset \begin_inset Text \layout Standard 0000111110 \end_inset \begin_inset Text \layout Standard 31 \end_inset \end_inset \layout Standard xxxxxxxx is a twos complement signed 8 bit nubmer (=int8_t) \layout Section Example ASV1 decoder \layout Itemize foreach macroblock, decode Y0 Y1 Y2 Y3 U V blocks, Y blocks are arranged as: \newline Y0 Y1 \newline Y2 Y3 \layout Itemize foreach block: \begin_deeper \layout Itemize DC coeff is the next 8 bits in the stream * 8 (this gives a range of 0..2040) \layout Itemize foreach of up to 11 coefficient groups: \begin_deeper \layout Itemize get vlc from ccp table, value should range from 0..16 \layout Itemize if value is 16, coefficient decode is done \layout Itemize if 11th iteration, 16 should occur, else error \layout Itemize ccp contains 4 bits at this point (3-0) \layout Itemize each bit corresponds to a quantized coeff. #(iter. * 4 + bit) \layout Itemize if 0, coeff. is 0 else get_level(): \begin_deeper \layout Itemize get vlc from level vlc table \layout Itemize if vlc is 3, use the next 8 bits (as a signed number) as level \layout Itemize else, use vlc - 3 \layout Itemize store coefficient \end_deeper \end_deeper \layout Itemize dequantize, idct \end_deeper \layout Section Changelog \layout List \labelwidthstring 00.00.0000 0.01 2003-05-21 \newline initial version by Michael Niedermayer with some stuff from Mike Melanson \layout List \labelwidthstring 00.00.0000 0.02 2003-05-21 \newline spelling, punctuation, example decoder, various minor changes by Mike Melanson \newline various minor changes by Michael \layout List \labelwidthstring 00.00.0000 0.03 2003-09-01 \newline minor fixes and ASV2 by Michael \layout List \labelwidthstring 00.00.0000 0.04 2004-08-24 \newline clarify bitstream order by Michael \layout Section Copyright \layout Standard Copyright 2003 Michael Niedermayer \newline This text can be used under the GNU Free Documentation License or GNU General Public License \newline see http://www.gnu.org/licenses/fdl.txt \the_end