Every AVI file is a RIFF file with the form type AVI . The first thing
inside it is a LIST of type hdrl, which starts with the main
header chunk avih and goes on with one
strl list per stream.
All numbers are little-endian.
The RIFF form
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 4 | FOURCC | RIFF | Literal. |
| 4 | 4 | DWORD | fileSize | Size of everything after this field: the form type and the data. |
| 8 | 4 | FOURCC | fileType | AVI , with a trailing space. |
| 12 | varies | chunks | data | LIST hdrl, LIST movi, then optionally idx1, in that order. |
A chunk is a FOURCC, a 4-byte size that counts only the data, and the data, padded to
an even length; the pad byte is not counted. A LIST is the same with a
FOURCC list type at the start of its data, and its size counts that type. A
JUNK chunk is padding that readers must skip.
The avih chunk
Microsoft’s AVIMAINHEADER structure. The offsets include the chunk ID and
size, so the fields begin at offset 8 of the chunk; cb is normally 56.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 4 | FOURCC | fcc | avih. |
| 4 | 4 | DWORD | cb | Size of the structure, not counting these first 8 bytes. |
| 8 | 4 | DWORD | dwMicroSecPerFrame | Microseconds between frames, the overall timing for the file. |
| 12 | 4 | DWORD | dwMaxBytesPerSec | Approximate maximum data rate of the file. |
| 16 | 4 | DWORD | dwPaddingGranularity | Alignment of data in bytes; data is padded to multiples of this. |
| 20 | 4 | DWORD | dwFlags | The flags in the next table. |
| 24 | 4 | DWORD | dwTotalFrames | Total frames of data in the file. |
| 28 | 4 | DWORD | dwInitialFrames | Initial frame for interleaved files; zero otherwise. The number of frames before the first frame of the sequence, usually the audio skew. |
| 32 | 4 | DWORD | dwStreams | Number of streams. |
| 36 | 4 | DWORD | dwSuggestedBufferSize | Suggested read buffer, large enough for the largest chunk, or for a whole rec list in an interleaved file. |
| 40 | 4 | DWORD | dwWidth | Width in pixels. |
| 44 | 4 | DWORD | dwHeight | Height in pixels. |
| 48 | 16 | DWORD[4] | dwReserved | Zero. |
dwFlags
| Value | Name | Meaning |
|---|---|---|
0x00000010 | AVIF_HASINDEX | The file has an idx1 index. |
0x00000020 | AVIF_MUSTUSEINDEX | The index, not the order of the chunks, gives the order of presentation. |
0x00000100 | AVIF_ISINTERLEAVED | The file is interleaved. |
0x00000800 | AVIF_TRUSTCKTYPE | The chunk type in the index can be trusted to say whether a frame is a key frame. In aviriff.h; not described on Microsoft’s page. |
0x00010000 | AVIF_WASCAPTUREFILE | A file specially allocated for capture. Programs should warn before overwriting it. |
0x00020000 | AVIF_COPYRIGHTED | The file contains copyrighted data; software should not let it be duplicated. |