Duck TrueMotion 2

From MultimediaWiki
Jump to navigation Jump to search

Duck TrueMotion 2 relies on differential coding of samples in a YUV colorspace and coding those deltas using Huffman codes.

Codec principles

This codec operates on 4x4 blocks and employs data separation, so packed frame data is composed from these segments:

  1. luma deltas for hi-res blocks
  2. luma deltas for low-res blocks
  3. chroma deltas for hi-res blocks
  4. chroma deltas for med-res and low-res blocks
  5. values for updating whole block
  6. motion vectors
  7. block types

Each segment is compressed with own Huffman codes (Huffman tree is stored in segment header), thus gaining compression from grouping similar data.

Blocks are unpacked in this way:

         LAST 4 ELEMENTS
         |    |    |    |
         V    V    V    V
 D0 -> +d00 +d10 +d20 +d30 -> D0
 D1 -> +d01 +d11 +d21 +d31 -> D1
 D2 -> +d02 +d12 +d22 +d32 -> D2
 D3 -> +d03 +d13 +d23 +d33 -> D2
         |    |    |    |
         V    V    V    V
         LAST 4 ELEMENTS

When current block is low-res block, an average value of pair of two last elements is calculated and used instead of them. When another type of block occurs (update, motion, still) after doing operation we need to re-calculate deltas. The same applies to chroma blocks, they are just 2x2 size.

Block types:

  1. Hi-resolution block: 16 luma deltas, 8 chroma deltas
  2. Medium-resolution block: 16 luma deltas, 2 chroma deltas
  3. Low-resolution block: 4 luma deltas, 2 chroma deltas
  4. Null block: no deltas, interpolate it from last 4 elements and deltas
  5. Still block: copy data from previous frame (and update Dx)
  6. Update block: 16 luma deltas, 8 chroma deltas, all applied independently , so recalculation is needed
  7. Motion block: copy block from previous frame with offset provided by motion vector.

Frame decoding is done this way:

 read header
 unpack all segments
 for each block in frame {
   get block type from 'block types' segment
   decode corresponding block type
 }

Bitstream format

Frame header consists of 32-bit codec version (0x100 or 0x101) and 36 bytes which value can be ignored. All values are little-endian, LSB first.

Stream data has the following format:

  • 32-bit stream size in 32-bit words
  • 31-bit number of tokens coded
  • 1-bit delta table present flag
    • (optional) delta table:
    • 9-bit number of deltas
    • 5-bit delta bits
    • NxM bits - delta values
    • padding to 32-bit word
  • 32-bit tree length
  • 32-bit algorithm
  • Huffman tree data
  • padding to 32-bit word
  • 32-bit token data length (when zero, stream tokens all have the same value)
  • Huffman-coded token data

Huffman tree descriptor:

 5 bits - symbol bits
 5 bits - maximum codeword length
 5 bits - minimum codeword length
 17 bits - number of leaves
 tree data (recursive, 1 bit to signal leaf/node; leaf contains symbol value)

Games Using Duck TrueMotion 2

These software titles are known to use the Duck TrueMotion 2 video codec to encode full motion video:

Final Fantasy VII (Windows)

[[Category:Video Codecs]