The file begins with the main header. In the AVI file, this header is identified with an 'avih' four-character code. The header contains general information about the file, such as the number of streams within the file and the width and height of the AVI sequence. The main header has the following data structure defined for it:
typedef struct { ULONG ulMicroSecPerFrame; ULONG ulMaxBytesPerSec; ULONG ulReserved1; ULONG ulFlags; ULONG ulTotalFrames; ULONG ulInitialFrames; ULONG ulStreams; ULONG ulSuggestedBufferSize; ULONG ulWidth; ULONG ulHeight; ULONG ulReserved[4]; } MainAVIHeader;
The ulMicroSecPerFrame field specifies the period between video frames. This value indicates the overall timing for the file.
The ulMaxBytesPerSec field specifies the approximate maximum data rate of the file. This value indicates the number of bytes per second the system must handle to present an AVI sequence as specified by the other parameters contained in the main header and stream header chunks.
The ulFlags field contains any flags for the file. The AVIF_HASINDEX flag applies to files with an index chunk. The AVI_HASINDEX flag indicates an index is present. The AVIF_ISINTERLEAVED flag indicates the AVI file has been interleaved. The system can stream interleaved data more efficiently than non-interleaved data.
The ulTotalFrames field of the main header specifies the total number of frames of data in file.
The ulInitialFrames field is used for some interleaved files. If you are creating interleaved files with audio skewing, specify the number of audio frames in the file prior to the initial video frame of the AVI sequence in this field.
The ulStreams field specifies the number of streams in the file. For example, a file with audio and video has two (2) streams.
The ulSuggestedBufferSize field specifies the suggested buffer size for reading the file. Generally, this size should be large enough to contain the largest chunk in the file. For an interleaved file, the buffer size should be large enough to read an entire record and not just a chunk.
The ulWidth and ulHeight fields specify the width and height of the AVI file in pixels.