VGM

From MultimediaWiki
Jump to navigation Jump to search

VGM (presumably from VideoGraM since originally this format was used for sending short video messages from one user to another) aka XVD (eXtended-play Video Disc) is a format that includes VGM Audio codec and VGM Video codec.

There are some historical variants:

Timeline:

VGM1 Format

This format uses big-endian data in its structure and intended to be used with Muzip 1-4, TELP, VT and Domen codecs.

Container format:

 4 bytes - file size (may be zero)
 4 bytes - duration in milliseconds
 4 bytes - "head" marker
 4 bytes - header size
 1 byte  - number of streams
 (header_size - 1) bytes - stream headers
 4 bytes - "data" marker
 data packets

Stream header format:

 1 byte  - codec name length
 N bytes - codec name
 1 byte  - stream ID
 4 bytes - codec ID
 4 bytes - codec priority
 4 bytes - codec extradata

Packet header:

 1 byte  - stream ID
 4 bytes - timestamp in milliseconds
 4 bytes - data size

VGM2 Format

This format uses little-endian integers

 4 bytes - "VGM2"
 4 bytes - file size (may be zero)
 4 bytes - duration in milliseconds
 1 byte  - number of streams
 1 byte  - file comment length
 N bytes - file comment (usually "Created by BHA dumper")
 1 bytes - string terminator?
 stream headers
 data packets

Stream header:

 1 byte  - stream type
 4 bytes - codec ID
 4 bytes - stream header extradata size
 extradata

Stream types:

 1    - audio stream
 2    - video stream
 5    - stream with end-of-stream marker (single packet almost at the end of file), maybe other system messages
 6    - stream with seek table (?), also single packet at the end of file
 >128 - just some padding that occurs time from time

Packet header:

 1 byte - stream number (in the order they appear in the header)
 1 byte - flags
 2/4 bytes - timestamp in milliseconds (4 bytes if bit 2 in flags is set, 2 bytes otherwise)
 2/4 bytes - packet size including the header (4 bytes if bit 1 in flags is set, 2 bytes otherwise)
 2/4 bytes - some size for video streams only, maybe second field or for P+B frame combination (4 bytes if bit 1 in flags is set, 2 bytes otherwise). Usually it is zero.

Known codec IDs and their headers

  • 3 - Muzip first version
  • 4 - TELP
  • 5..9 - Muzip
  • 0xAC3 - AC-3
  • 0x010001 - VT
  • 0x010002 - Domen
  • 0x010006 - V2K
  • 0x010007 - V2K-II
  • 0x010027 - probably XVD 1.x
  • 0x110027 - XVD 2.4
  • 0x210027 - XVD 2.5

Audio and video header have the same format in VGM 1 and 2 except that in version 2 there are two additional 4-byte fields in the beginning that can be ignored. All data is in little-endian format.

Audio header:

 2 bytes - should be 0x300
 2 bytes - number of channels
 4 bytes - sampling rate

For Muzip starting at byte 18 there is also codec sub-flavour, known flavours are CTP03-CTP07 and MZIP13R (for the latest known version).

Video header:

 2 bytes - width
 2 bytes - height
 4 bytes - unknown
 (the rest is for newer versions only)
 4 bytes - width
 4 bytes - height
 4 bytes - bitrate
 4 bytes - frames per second