VIDPAK

From MultimediaWiki
Jump to navigation Jump to search
  • Extension: vdo
  • Developer: John W. Ratcliff

VIDPAK as it is officially called, or Ratvideo (after the first six bytes in file header, most likely after the developer's name) is an 8-bit format using RLE for video compression and DPCM/RLE for audio compression

File format

VIDPAK files start with 24-byte header followed by a global palette (the number of colours is given in the header), followed by interleaved video and audio frames. All values are little-endian.

Header format

 6 bytes - "RATVID"
 2 bytes - version? (always 1)
 1 byte  - frames per second
 1 byte  - audio mode (0 - no audio, 1 - unpacked frames, 2 - packed frames)
 2 bytes - unknown
 2 bytes - audio block size
 1 byte  - unknown
 1 byte  - transparency index (0 - no transparency)
 2 bytes - number of video frames
 2 bytes - width
 2 bytes - height
 2 bytes - number of palette colours

Audio frames are either unpacked 8-bit PCM with the frame size given in the header or packed frames with 16-bit frame size preceding packed data (unpacked size is always audio block size given in the header).

Video frames are stored in different way which is signalled in the stream. If first 16-bit value is 0x0002 then masked unpack mode depends on previous line and actual value is stored in the next 16-bit word. Value 0x0001 mean the frame is RLE-compressed, otherwise frame is coded as a masked update and the value is actually a length of mask data (RLE-packed if top bit is set, unpacked otherwise), then pixel data follows after 16-bit tag (0 - use old data, 0xFFFF - data is RLE'd and its actual size is stored next, other values are for unpacked data length).

Video compression

RLE

RLE data starts with two 16-bit values, for the lengths of uncompressed and compressed data sizes. Opcodes are single bytes (top bit set signals run, 0xFF means actual run length minus one follows in the next 16-bit word, otherwise it is a copy operation).

Masked decoding

Inter frames may be compressed using a mask and new pixel data. For each pixel if a corresponding bit in mask data is set, it should be replaced with a new value from new pixel data, otherwise pixel is left unchanged.

There is an alternative mode where, instead of updating a whole frame, each line is coded as an update to the previous line. This is signalled by sending 0x0002 before frame data.

Audio compression

Compressed audio is stored using opcodes, mostly as a difference to the previous 8-bit sample value. First sample is transmitted as is.

Opcodes are:

  • 1xxxxxxx - immediate sample value with bottom bit shaved off
  • 01xxxxxx - repeat previous sample xxxxxxx times
  • 00xxyyyy - decode 32 deltas using scale yyyy + 1:
    • xx = 01 - 1 bit per delta (1 - add scale value, 0 - subtract scale value)
    • xx = 10 - 2 bits per delta ({-2, -1, 1, 2} * scale)
    • xx = 11 - 4 bits per delta ({-8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8} * scale)

Games using Ratvideo