Reaper

From MultimediaWiki
Jump to navigation Jump to search
  • Extension: fmv

Psygnosis' 1999 title Rollcage included directory full of video with a .fmv extension. The first 8 bytes of the files contain a header of "!Reaper!".

Looking at the strings in the either of the games binaries (Glide or Direct3D) the string "Reaper '95 Version 1.30, (c) Paul Hughes" can also be found.

The game (its PSX version) take advantage of an MDEC chip, therefore the video encoding is an MPEG variant and audio is IMA ADPCM packaged in a custom container.

File Format

All numbers are little-endian. File consist of a main header:

s8  signature[8]   -- "!Reaper!"  (but only first 5 characters actually checked)
s32 headersize     -- size of the header and coefficients table (i.e. it's an offset of the first data chunk)
s16 width          -- video width
s16 height         -- video height
s16 nframes        -- number of frames
s16 audiotype      -- 0 - no sound, 1 - IMA sound
s16 audiorate      -- audio frequency
s16 audiobits      -- sound sample bits (always 16?)
s16 audiochnl      -- 1 - mono, 2 - stereo
s16 unknown

then followed by RLE-packed frame quantisers (size = headersize - sizeof(header)) and then followed by frame chunks. Chunk format:

u32 signature      -- chunk type
u32 size           -- chunk size, including this header
u8  payload[]      -- chunk payload

Observed chunk types:

  • 0x0B85120F - video chunk
  • 0x90FC0302 - audio chunk
  • 0xD6BD0106 - raw audio chunk?

Frame quantisers run coding is triggered by two consequent values being the same (or previous run having size 255). E.g. 64 64 06 decodes to value of 0x64 repeated eight times and 62 62 FF 62 02 decodes to 259 repeats of value 0x62 run of two values is coded as 5F 5F 00.

Video Decompression

Video is DCT-based sequence of macroblocks that may be either motion-compensated, filled or fully decoded. It uses 7-bit YUV colourspace internally with the following conversion formulae:

  • first expand all YUV component values as val * 2 + 1;
  • R = Y + (Cr * 91881 >> 16) + 128;
  • G = Y + (Cb * -22050 >> 16) + (Cr * -46799 >> 16) + 128;
  • B = Y + (Cb * 116129 >> 16) + 128;

Data decoding

Each macroblock is prefixed by the value XORed with 0xB6 and may have the following values (not coincidentally it's the same as the number of bytes following the MB type):

  • 1 -- motion block, next byte high nibble is signed vertical motion component and low nibble is signed horizontal motion component;
  • 3 -- the next three bytes are YUV values to fill the whole macroblock with;
  • 6 -- the next six bytes are four Y plus UV values to fill the blocks of the whole macroblock
  • 12 -- the same as the previous but every other byte is ignored (i.e. Y0 0 Y1 0 Y2 0 Y3 0 U 0 V 0)
  • 2, 4, 5, 7-11 -- should not happen
  • other values denote a full coded macroblock

For a full-coded macroblock data is decoded per block. First byte is the (signed) DC value, then the data for AC follows (LSB first, the loop starts from coefficient 63 and goes back to zero):

  • 3 bits - RL type:
    • 0 -- zero
    • 1 -- 6-bit zero run
    • 2 -- one
    • 3 and 7 -- 6-bit signed value (0x3F means escape and reading full 8-bit value)
    • 4 -- two zero coefficients
    • 5 -- 6-bit zero run plus another zero value
    • 6 -- minus one

Scan order:

 0x00, 0x3f, 0x37, 0x3e, 0x3d, 0x36, 0x2f, 0x27,
 0x2e, 0x35, 0x3c, 0x3b, 0x34, 0x2d, 0x26, 0x1f,
 0x17, 0x1e, 0x25, 0x2c, 0x33, 0x3a, 0x39, 0x32,
 0x2b, 0x24, 0x1d, 0x16, 0x0f, 0x07, 0x0e, 0x15,
 0x1c, 0x23, 0x2a, 0x31, 0x38, 0x30, 0x29, 0x22,
 0x1b, 0x14, 0x0d, 0x06, 0x05, 0x0c, 0x13, 0x1a,
 0x21, 0x28, 0x20, 0x19, 0x12, 0x0b, 0x04, 0x03,
 0x0a, 0x11, 0x18, 0x10, 0x09, 0x02, 0x01, 0x08

Quantiser

Actual frame quantisation matrix is obtained from the frame quality stored in the header as

 quant = (100 - quality) / 2 - (100 - quality) * 22 / 100 + 2;

multiplied by the default quantisation matrix.

Default quantisation matrix:

  8192,  5906,  6270,   6967,
  8192, 10426, 15137,  29692,
  5906,  4258,  4520,   5023,
  5906,  7517, 10913,  21407,
  6270,  4520,  4799,   5332,
  6270,  7980, 11585,  22725,
  6967,  5023,  5332,   5925,
  6967,  8867, 12873,  25251,
  8192,  5906,  6270,   6967,
  8192, 10426, 15137,  29692,
 10426,  7517,  7980,   8867,
 10426, 13270, 19266,  37791,
 15137, 10913, 11585,  12873,
 15137, 19266, 27969,  54864,
 29692, 21407, 22725,  25251,
 29692, 37791, 54864, 107619