DV Data in the AVI File Format
Specification, Version 1.01

Microsoft Corporation
June 25, 1997

The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.
This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT.
Microsoft does not make any representation or warranty regarding specifications in this document or any product or item developed based on these specifications. Microsoft disclaims all express and implied warranties, including but not limited to the implied warranties of merchantability, fitness for a particular purpose and freedom from infringement. Without limiting the generality of the foregoing, Microsoft does not make any warranty of any kind that any item developed based on these specifications, or any portion of a specification, will not infringe any copyright, patent, trade secret or other intellectual property right of any person or entity in any country. It is your responsibility to seek licenses for such intellectual property rights where appropriate. Microsoft shall not be liable for any damages arising out of or in connection with the use of these specifications, including liability for lost profit, business interruption, or any other damages whatsoever. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages; the above limitation may not apply to you. 
ActiveMovie, ActiveX, Direct3D, DirectDraw, DirectInput, DirectMusic, DirectPlay, DirectShow, DirectSound, DirectX, Microsoft, Visual C++, Win32, Windows, and Windows NT are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners.
© 1997 Microsoft Corporation. All rights reserved.
Please send feedback to ihv@microsoft.com with “DVD Data Format Specification” in the Subject line.

Contents
Introduction	4
Scope	4
References	4
Version History	4
1.0	Types of DV AVI Files	5
1.1.	Type 1: AVI files containing one DV data stream	5
1.2.	Type 2: AVI files containing DV video as a ‘vids’ stream and DV audio as ‘auds’ streams	9
2.0	AVI File Background Information	12
2.1	AVI files	12
2.2	AVI RIFF Form	12
2.3	The Main AVI Header Chunk	13
2.4	The Stream Header (‘strl’) List Chunk	15
2.5	The LIST ‘movi’ Chunk	16
2.6	AVI RIFF File Reference	17
2.6.1	MainAVIHeader	17
2.6.2	AVIStreamHeader	18
2.6.3	BITMAPINFOHEADER structure	20
2.6.4	WAVEFORMATEX structure	21

Introduction
Microsoft is specifying the format for storage of DV data in AVI files.  Conforming to this specification will ensure the AVI files authored in this format will be compatible with future versions of the Microsoft® DirectShow® (formerly ActiveMovie™) digital video architecture for the Microsoft Windows® platform.

The contents of this specification should be used as background information to understand the format of AVI files containing DV audio and video data, or for programmers who are using DV-AVI files on other platforms.  Applications that read or write AVI files should use the File Reader (Async) / AVI Splitter and the AVI Mux / File Writer filters and their associated interfaces provided in the DirectShow architecture, rather than developing the routines to perform these services.  These filters simplify the programming requirements for accessing these files.

Scope
This document describes the format of AVI files containing DV data.  Specific four-character codes for interleaved DV data streams and  DV compressor / decompressor stream handlers are defined.  The stream format structure for DV data is defined.  Specifications for two methods of storing DV data in the AVI file format are specified.

It is assumed that the reader is familiar with the DV data format as defined in the so called “Blue Book”.  For additional information on DV data formats, see the Specification of Consumer-use Digital VCRs (The “Blue Book”; available from Matsushita Electrical Industrial Co., Ltd.). 

References
For additional information about RIFF files, see the Microsoft Windows Software Development Kit Multimedia Programmer’s Guide and Multimedia Programmer’s Reference.

For additional information about AVI files, see chapter 6 of the Microsoft Video for Windows Development Kit, version 1.1, Programmer’s Guide; see also OpenDML AVI File Format Extensions, version 1.02, published by the OpenDML AVI M-JPEG File Format Subcommittee, February 28, 1996.

For additional information on installable compressors and decompressors, see the Video Compression/Decompression Drivers Technical Note from Microsoft.

For additional information on Microsoft DirectShow architecture, filters, data-types, interfaces, etc., see the Microsoft DirectX Media Software Development Kit documentation (which includes DirectShow).

Portions of the above Microsoft and OpenDML Subcommittee documents may have been reprinted in this specification. Microsoft SDKs are available through Microsoft Developer Network (MSDN) Professional membership.

Version History

Version 0.90	June 6, 1997	First draft in specification format
Version 0.95	June 13, 1997	Minor corrections, includes example filter graphs
Version 1.00	June 23, 1997	Final first version, includes pro/cons of two types of AVI files, example RIFF dumps of headers
Version 1.01	June 25, 1997	Very minor typo correction; formatting

1.0	Types of DV AVI Files
1.1.	Type 1: AVI files containing one DV data stream
Interleaved DV data can be stored in its native format as a single stream within an AVI RIFF file.  This has the advantage of using the minimum amount of data storage for DV.  The primary disadvantage is that this file format is not backward compatable with Video for Windows, as it does not contain either a video ‘vids’ or an audio ‘auds’ stream.  Support is provided for the interleaved DV stream via the “DV Mux” and “DV Splitter” DirectShow filters.

DV data can be stored in a single stream within an AVI RIFF file by specifying the ‘ivas’ (interleaved video and audio stream) four-character code in the fccType member and either of the ‘dvsd’, ‘dvhd’, or ‘dvsl’ four-character codes in the fccHandler member of the ‘strh’ stream header chunk.  The frames per second of the video stream must be specified in the dwRate / dwScale members and the total number of video blocks in the ‘movi’ chunk in the dwLength member.

The ‘dvsd’ stream handler four-character code specifies that the DV data is as defined in Part 2 of the “Blue Book.”  Video is in the format of 525 lines at 29.97Hz (525-60) or 625 lines at 25.00Hz (625-50).

The ‘dvhd’ stream handler four-character code specifies that the DV data is as defined in Part 3 of the “Blue Book.”  Video is in the format of 1125 lines at 30.00Hz (1125-60) or 1250 lines at 25.00Hz (1250-50).

The ‘dvsl’ stream handler four-character code specifies that the DV data is as defined in Part 6 of the “Blue Book.”  Video is in the format of high-compression SD (SDL).

NOTE:  The remainder of this specification provides definitions for ‘dvsd’ streams.  Definitions for ‘dvhd’ and ‘dvsl’ will be provided at a later date.

This stream header chunk must be followed by DVINFO stream format chunk.  The DVINFO stream format has the following data structure defined for it:

typedef struct tag_DVINFO {
	DWORD dwDVAAuxSrc;
	DWORD dwDVAAuxCtl;
	DWORD dwDVAAuxSrc1;
	DWORD dwDVAAuxCtl1;
	DWORD dwDVVAuxSrc;
	DWORD dwDVVAuxCtl;
	DWORD dwDVReserved[2];
} DVINFO, *PDVINFO;

dwDVAAuxSrc
Specifies the Audio Auxiliary Data Source Pack for the first audio block (first 5 DV DIF sequences for 525-60 systems or 6 DV DIF sequences for 625-50 systems) of a frame.  The Audio Auxiliary Data Source Pack is defined in section D.7.1 of Part 2, Annex D, “The Pack Header Table and Contents of Packs” of the “Blue Book.”
dwDVAAuxCtl
Specifies the Audio Auxiliary Data Source Control Pack for the first audio block of a frame. The Audio Auxiliary Data Control Pack is defined in section D.7.2 of Part 2, Annex D, “The Pack Header Table and Contents of Packs” of the “Blue Book.”
dwDVAAuxSrc1
Specifies the Audio Auxiliary Data Source Pack for the second audio block (second 5 DV DIF sequences for 525-60 systems or 6 DV DIF sequences for 625-50 systems) of a frame.
dwDVAAuxCrl1
Specifies the Audio Auxiliary Data Source Control Pack for the second audio block of a frame.
dwDVVAuxSrc
Specifies the Video Auxiliary Data Source Pack as defined in section D.8.1 of Part 2, Annex D, “The Pack Header Table and Contents of Packs” of the “Blue Book.”
dwDVVAuxCtl
Specifies the Video Auxiliary Data Source Control Pack as defined in section D.8.2 of Part 2, Annex D, “The Pack Header Table and Contents of Packs” of  the “Blue Book.”
DwDVReserved[2]
Reserved.  Set this array to zero.

The actual DV data is stored as ‘##dc’ chunks in the ‘movi’ chunk (the ## in the format represents the stream identifier).  Each chunk contains one frame of data, either 10 or 12 DV DIF sequences for 525-60 or 625-50 systems, respectively.  The DV SD (‘dvsd’) DIF sequence format is defined in Part 2 of the “Blue Book.”

Figure 1, below, illustrates the playback of a type 1 DV-AVI file using a DirectShow filter graph (filters included in DirectShow that deal specifically with DV data are highlighted in gray). Table 1, below, defines the media types.

Figure 1:  Playback of type-1 DV-AVI file

Table 1:  DV media types
Connection	Major Type	Sub Type	Format Block Type	Format Block Struct	
A	MEDIATYPE_Stream	MEDIASUBTYPE_AVI			
B	MEDIATYPE_iavs	MEDIASUBTYPE_dvsd
MEDIASUBTYPE_dvhd
MEDIASUBTYPE_dvsl	FORMAT_DVinfo	DVINFO	
C	MEDIATYPE_VIDEO	MEDIASUBTYPE_dvsd
MEDIASUBTYPE_dvhd
MEDIASUBTYPE_dvsl	FORMAT_DVinfo	DVINFO	
D	MEDIATYPE_AUDIO	NULL	FORMAT_WaveFormatEx	WAVEFORMATEX	
E	MEDIATYPE_VIDEO	standard video subtypes	FORMAT_VideoInfo	VIDEOINFO	

Figure 2, below, illustrates the creation of a type 1 DV-AVI file using a DirectShow filter graph.  Table 1, above, defines the media types.  Upstream filters (not shown) can be of any combination to produce the proper media types, D and E.

Figure 2:  Creation of type 1 DV-AVI file

Figure 3, below, illustrates the creation of a type 1 DV-AVI file utilizing a “source” filter that communicates via hardware device drivers to a DV device (such as a 1394-based DV camcorder) for DV data input using a DirectShow filter graph.  Table 1, above, defines theÿ@edia types.

Figure 3:  DV capture to type 1 DV-AVI file

Figure 4, below, illustrates the “output” of a type 1 DV-AVI file utilizing a “sink” filter that communicates via hardware device drivers to a DV device (such as a 1394-based DV camcorder) for DV data output using a DirectShow filter graph.  Table 1, above, defines the media types.

Figure 4:  “Output” of type 1 DV-AVI file

The following example shows the type 1 DV-AIFF RIFF form expanded with completed header chunks:

00000000 RIFF (0FAE35D4) 'AVI '
0000000C     LIST (00000106) 'hdrl'
00000018         avih (00000038)
                     dwMicroSecPerFrame    : 33367
                     dwMaxBytesPerSec      : 3728000
                     dwPaddingGranularity  : 0
                     dwFlags               : 0x810 HASINDEX | TRUSTCKTYPE
                     dwTotalFrames         : 2192
                     dwInitialFrames       : 0
                     dwStreams             : 1
                     dwSuggestedBufferSize : 120000
                     dwWidth               : 720
                     dwHeight              : 480
                     dwReserved            : 0x0
00000058         LIST (0000006C) 'strl'
00000064             strh (00000038)
                         fccType               : 'ivas'
                         fccHandler            : 'dvsd'
                         dwFlags               : 0x0
                         wPriority             : 0
                         wLanguage             : 0x0 undefined
                         dwInitialFrames       : 0
                         dwScale               : 100 (29.970 Frames/Sec)
                         dwRate                : 2997
                         dwStart               : 0
                         dwLength              : 2192
                         dwSuggestedBufferSize : 120000
                         dwQuality             : 0
                         dwSampleSize          : 0
                         rcFrame               : 0,0,720,480
000000A4             strf (00000020)
                         dwDVAAuxSrc     : 0x........
                         dwDVAAuxCtl     : 0x........
                         dwDVAAuxSrc1    : 0x........
                         dwDVAAuxCtl1    : 0x........
                         dwDVVAuxSrc     : 0x........
                         dwDVVAuxCtl     : 0x........
                         dwDVReserved[2] : 0,0
000000CC     LIST (0FADAC00) 'movi'
0FADACD4     idx1 (00008900)
1.2.	Type 2: AVI files containing DV video as a ‘vids’ stream and DV audio as ‘auds’ streams
Interleaved DV data can be split into a video stream and one to four audio streams within an AVI RIFF file.  This has the advantage of being backward compatable with Video for Windows, as it does contains a standard video ‘vids’ stream and at least one standard audio ‘auds’ stream  The primary disadvantage is that this file format requires the audio data to be redundantly stored as audio streams.  The “video” stream is actually the native interleaved DV data stream.  However, as a standard ‘vids’ stream with a handler type of ‘dvsd’, the DV Video Decoder is used.  This format also requires that “captured” files are split using the “DV Splitter” filter before they are written as AVI files.

DV data can be stored as a video stream with a separate number of audio streams in an AVI RIFF file.  The video stream is specified with a standard video stream header (the fccType member value is ‘vids’).  The fccHandler member is specified as ‘dvsd’, ‘dvhd’, or ‘dvsl’.  The frames per second of the video stream must be specified in the dwRate / dwScale members and the total number of video blocks in the ‘movi’ chunk in the dwLength member.

In this type 2 form, the video stream format chunk is a standard BITMAPINFOHEADER structure.  The stream format chunk can be optionally extended to include the DVINFO structure, as defined above for the type 1 form, by increasing the stream format chunk size from 40 bytes (size of the BITMAPINFOHEADER structure) to 72 bytes (size of BITMAPINFOHEADER plus DVINFO structures) and immediately following the BITMAPINFOHEADER data structure with a DVINFO data structure.

The audio stream(s) is specified with a standard audio stream header (the fccType member value is ‘auds’).  The fccHandler member is not used for audio streams.

The DV video data is stored as ‘##dc’ chunks, as defined in the type 1 AVI section above, and the audio data is stored as ‘##wb’ chunks in the ‘movi’ chunk.

Figure 5, below, illustrate the playback of a type 2 DV-AVI file using a DirectShow filter graph. Table 1, above, defines the media types.

Figure 5:  Playback of type 2 DV-AVI file

Figure 6, below, illustrates the creation of a type 2 DV-AVI file using a DirectShow filter graph.  Table 1, above, defines the media types.  Upstream filters (not shown) can be of any combination to produce the proper media types, D and E.

Figure 6:  Creation of type 2 DV-AVI file

Figure 7, below, illustrates the creation of a type 2 DV-AVI file utilizing a “source” filter that communicates via hardware device drivers to a DV device (such as a 1394-based DV camcorder) for DV data input using a DirectShow filter graph.  Table 1 above defines the media types.

Figure 7:  DV capture to type 2 DV-AVI file

Figure 8, below, illustrates the “output” of a type 1 DV-AVI file utilizing a “sink” filter that communicates via hardware device drivers to a DV device (such as a 1394-based DV camcorder) for DV data output using a DirectShow filter graph.  Table 1 above defines the media types.

Figure 8:  “Output” of type 2 DV-AVI file

The following example shows the type 2 DV-AIFF RIFF form expanded with completed header chunks (including optional DVINFO data following the BAPMAPINFO in the ‘strf’ sub-chunk for the ‘vids’ stream):

00000000 RIFF (103E2920) 'AVI '
0000000C     LIST (00000146) 'hdrl'
00000018         avih (00000038)
                     dwMicroSecPerFrame    : 33367
                     dwMaxBytesPerSec      : 3728000
                     dwPaddingGranularity  : 0
                     dwFlags               : 0x810 HASINDEX | TRUSTCKTYPE
                     dwTotalFrames         : 2192
                     dwInitialFrames       : 0
                     dwStreams             : 2
                     dwSuggestedBufferSize : 120000
                     dwWidth               : 720
                     dwHeight              : 480
                     dwReserved            : 0x0
00000058         LIST (00000094) 'strl'
00000064             strh (00000038)
                         fccType               : 'vids'
                         fccHandler            : 'dvsd'
                         dwFlags               : 0x0
                         wPriority             : 0
                         wLanguage             : 0x0 undefined
                         dwInitialFrames       : 0
                         dwScale               : 100 (29.970 Frames/Sec)
                         dwRate                : 2997
                         dwStart               : 0
                         dwLength              : 2192
                         dwSuggestedBufferSize : 120000
                         dwQuality             : 0
                         dwSampleSize          : 0
                         rcFrame               : 0,0,720,480
000000A4             strf (00000048)
                         biSize          : 40
                         biWidth         : 720
                         biHeight        : 480
                         biPlanes        : 1
                         biBitCount      : 24
                         biCompression   : 0x64737664 'dvsd'
                         biSizeImage     : 120000
                         biXPelsPerMeter : 0
                         biYPelsPerMeter : 0
                         biClrUsed       : 0
                         biClrImportant  : 0
                         dwDVAAuxSrc     : 0x........
                         dwDVAAuxCtl     : 0x........
                         dwDVAAuxSrc1    : 0x........
                         dwDVAAuxCtl1    : 0x........
                         dwDVVAuxSrc     : 0x........
                         dwDVVAuxCtl     : 0x........
                         dwDVReserved[2] : 0,0
000000F4         LIST (0000005E) 'strl'
00000100             strh (00000038)
                         fccType               : 'auds'
                         fccHandler            : '    '
                         dwFlags               : 0x0
                         wPriority             : 0
                         wLanguage             : 0x0 undefined
                         dwInitialFrames       : 0
                         dwScale               : 1 (32000.000 Samples/Sec)
                         dwRate                : 32000
                         dwStart               : 0
                         dwLength              : 2340474
                         dwSuggestedBufferSize : 4272
                         dwQuality             : 0
                         dwSampleSize          : 4
                         rcFrame               : 0,0,0,0
00000140             strf (00000012)
                         wFormatTag      : 1 PCM
                         nChannels       : 2
                         nSamplesPerSec  : 32000
                         nAvgBytesPerSec : 128000
                         nBlockAlign     : 4
                         wBitsPerSample  : 16
                         cbSize          : 0
00000814     LIST (103D0EF4) 'movi'
103D1710     idx1 (00011210)
2.0	AVI File Background Information
2.1	AVI files
The Microsoft audio-video interleaved (AVI) file format is a RIFF file specification used with applications that capture, edit, and play back audio-video sequences.  In general, AVI files contain multiple streams of different types of data.  Most AVI sequences use both audio and video streams.  A simple variation for an AVI sequence uses video data and does not require an audio stream.

Modifications to the original AVI file specification made in the OpenDML AVI File Format Extensions are not discussed in this section.  For further information on these extensions, see OpenDML AVI File Format Extensions.

2.2	AVI RIFF Form
AVI files use the AVI RIFF form.  The AVI RIFF form is identified by the four-character code ‘AVI ’.  All AVI files include two mandatory LIST chunks.  These chunks define the format of the stream and stream data.  AVI files might also include an index chunk.  This optional chunk specifies the location of data chunks within the file.  An AVI file with these components has the following form:

RIFF ('AVI '
      LIST ('hdrl'
              .
              .
              .
           )
      LIST ('movi'
              .
              .
              .
           )
      ['idx1'<AVI Index>]
     )

The LIST chunks and the index chunk are subchunks of the RIFF ‘AVI ’ chunk.  The ‘AVI ’ chunk identifies the file as an AVI RIFF file.  The LIST ‘hdrl’ chunk defines the format of the data and is the first required LIST chunk.  The LIST ‘movi’ chunk contains the data for the AVI sequence and is the second required LIST chunk.  The ‘idx1’ chunk is the index chunk.  AVI files must keep these three components in the proper sequence.

The LIST ‘hdrl’ and LIST ‘movi’ chunks use subchunks for their data.  The following example shows the AVI RIFF form expanded with the chunks needed to complete the LIST ‘hdrl’ and LIST ‘movi’ chunks:

RIFF ('AVI '
      LIST ('hdrl'
            'avih'(<Main AVI Header>)
            LIST ('strl'
                  'strh'(<Stream header>)
                  'strf'(<Stream format>)
                  'strd'(<additional header data>)
                  'strn'(<Stream name>)
                  ...
                 )
             .
             .
             .
           )

      LIST ('movi'
            {SubChunk | LIST ('rec '
                              SubChunk1
                              SubChunk2
                                .
                                .
                                .
                             )
               .
               .
               .
            }
            .
            .
            .
           )

      ['idx1'<AVI Index>]
     )

The following sections describe the chunks contained in the LIST ‘hdrl’ and LIST ‘movi’ chunks. The ‘idx1’ chunk is not described in this document.  For further information on the ‘idx1’ chunk and indexes in AVI files, see the OpenDML AVI File Format Extensions.

2.3	The Main AVI Header Chunk
The file begins with the main header.  In the AVI file, this header is identified by the ‘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 {
	DWORD dwMicroSecPerFrame;
	DWORD dwMaxBytesPerSec;
	DWORD dwReserved1;
	DWORD dwFlags;
	DWORD dwTotalFrames;
	DWORD dwInitialFrames;
	DWORD dwStreams;
	DWORD dwSuggestedBufferSize;
	DWORD dwWidth;
	DWORD dwHeight;
	DWORD dwReserved[4];
} MainAVIHeader;

The dwMicroSecPerFrame member specifies the period between video frames.  This value indicates the overall timing for the file.

The dwMaxBytesPerSec member 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 dwFlags member contains any flags for the file.  The AVIF_HASINDEX, AVIF_MUSTUSEINDEX, AVIF_ISINTERLEAVED, AVIF_COPYRIGHTED, and AVIF_WASCAPTUREFILE flags are defined.

The AVIF_HASINDEX and AVIF_MUSTUSEINDEX flags apply to files with an index chunk.  The AVI_HASINDEX flag indicates an index is present.  The AVIF_MUSTUSEINDEX flag indicates the index should be used to determine the order of the presentation of the data.  When this flag is set, it implies the physical ordering of the chunks in the file does not correspond to the presentation order.

The AVIF_ISINTERLEAVED flag indicates the AVI file has been interleaved.  The system can stream interleaved data from a CD-ROM more efficiently than non-interleaved data.  For more information about interleaved files, see “Special Information for Interleaved Files” in the Video for Windows Programmer’s Guide.

The AVIF_COPYRIGHTED flag indicates the AVI file contains copyrighted data.  When this flag is set, applications should not let users duplicate the file or the data in the file.

The AVIF_WASCAPTUREFILE flag indicates the AVI file is a specially allocated file used for capturing real-time video.  Typically, capture files have been defragmented by the user so video capture data can be efficiently streamed into the file.  If this flag is set, an application should warn the user before writing over the file.

The dwTotalFrames member of the main header specifies the total number of frames of data in the file.

The dwInitialFrames member is used for interleaved files.  If you are creating interleaved files, specify the number of frames in the file prior to the initial frame of the AVI sequence in this member.  For more information about the contents of this member, see “Special Information for Interleaved Files” in the Video for Windows Programmer’s Guide.

The dwStreams member specifies the number of streams in the file.  For example, a file with audio and video has two streams.

The dwSuggestedBufferSize member specifies the suggested buffer size for reading the file.  Generally, this size should be large enough to contain the largest chunk in the file.  If set to zero, or if it is too small, the playback software will have to reallocate memory during playback, which will reduce performance.  For an interleaved file, the buffer size should be large enough to read an entire record, and not just a chunk.

The dwWidth and dwHeight members specify the width and height of the AVI file in pixels.

2.4	The Stream Header (‘strl’) List Chunk
The main header is followed by one or more ‘strl’ chunks.  (A ‘strl’ chunk is required for each data stream.)  These chunks contain information about the streams in the file.  Each ‘strl’ chunk must contain a stream header and stream format chunk.  Stream header chunks are identified by the four-character code ‘strh’ and the stream format chunks are identified by the four-character code ‘strf’.  In addition to the stream header and stream format chunks, the ‘strl’ chunk might also contain a stream-header data chunk and a stream name chunk.  Stream-header data chunks are identified by the four-character code ‘strd’.  Stream name chunks are identified by the four-character code ‘strn’.

The stream header has the following data structure defined for it:

typedef struct {
	FOURCC fccType;
	FOURCC fccHandler;
	DWORD  dwFlags;
	DWORD  dwPriority;
	DWORD  dwInitialFrames;
	DWORD  dwScale;
	DWORD  dwRate;
	DWORD  dwStart;
	DWORD  dwLength;
	DWORD  dwSuggestedBufferSize;
	DWORD  dwQuality;
	DWORD  dwSampleSize;
	RECT   rcFrame;
} AVIStreamHeader;

The stream header specifies the type of data the stream contains, such as audio or video, by means of a four-character code.  The fccType member is set to ‘vids’ if the stream it specifies contains video data.  It is set to ‘auds’ if it contains audio data.  It is set to ‘TXTS’ if it contains text data.

The fccHandler member contains a four-character code describing the stream handler for the data.  For audio and video streams, this specifies the installable compressor or decompressor.

The dwFlags member contains any flags for the data stream.  The AVISF_DISABLED flag indicates that the stream data should be rendered only when explicitly enabled by the user.  The AVISF_VIDEO_PALCHANGES flag indicates palette changes are embedded in the file.

The dwInitialFrames member is used for interleaved files.  If you are creating interleaved files, specify the number of frames in the file prior to the initial frame of the AVI sequence in this member.  For more information about the contents of this member, see “Special Information for Interleaved Files” in the Video for Windows Programmer’s Guide.

The remaining members describe the playback characteristics of the stream.  These factors include the playback rate (dwScale and dwRate), the starting time of the sequence (dwStart), the length of the sequence (dwLength), the size of the playback buffer (dwSuggestedBuffer), an indicator of the data quality (dwQuality), and the sample size (dwSampleSize).  For more information about these members, see the “AVI RIFF File Reference,” later in this specification.

Some of the members in the stream header structure are also present in the main header structure.  The data in the main header applies to the whole file, while the data in the stream header structure applies only to a stream.

A stream format (‘strf’) chunk must follow a stream header (‘strh’) chunk.  The stream format chunk describes the format of the data in the stream.  For video streams, the information in this chunk is a BITMAPINFO structure (including palette information if appropriate).  For audio streams, the information in this chunk is a WAVEFORMATEX or PCMWAVEFORMAT structure.  (The WAVEFORMATEX structure is an extended version of the WAVEFORMAT structure.)  For more information about this structure and other stream types, see the New Multimedia Data Types and Data Techniques Standards Update.

The ‘strl’ chunk might also contain an additional stream-header data (‘strd’) chunk.  If used, this chunk follows the stream format chunk.  The format and content of this chunk is defined by installable compression or decompression drivers.  Typically, drivers use this information for configuration.  Applications that read and write RIFF files do not need to decode this information.  They transfer this data to and from a driver as a memory block.

The optional ‘strn’ stream name chunk provides a zero-terminated text string describing the stream.  (The AVIFile functions can use this chunk to let applications identify the streams they want to access by their names.)

An AVI player associates the stream headers in the LIST ‘hdrl’ chunk with the stream data in the LIST ‘movi’ chunk by using the order of the ‘strl’ chunks.  The first ‘strl’ chunk applies to stream 0, the second applies to stream 1, and so forth.

For example, if the first ‘strl’ chunk describes the wave audio data, the wave audio data is contained in stream 0.  Similarly, if the second ‘strl’ chunk describes video data, then the video data is contained in stream 1.

2.5	The LIST ‘movi’ Chunk
Following the header information is a LIST ‘movi’ chunk that contains chunks of the actual data in the streams – that is, the pictures and sounds themselves.  The data chunks can reside directly in the LIST ‘movi’ chunk or they might be grouped into ‘rec ’ chunks.  The ‘rec ’ grouping implies that the grouped chunks should be read from disk all at once.  This is used only for files specifically interleaved to play from CD-ROM.

Like any RIFF chunk, the data chunks contain a four-character code to identify the chunk type.  The four-character code that identifies each chunk consists of the stream number and a two-character code that defines the type of information encapsulated in the chunk.  For example, a waveform chunk is identified by a two-character code of ‘wb’.  If a waveform chunk corresponded to the second LIST ‘hdrl’ stream description, it would have a four-character code of ‘01wb’.

Note:  While two-character codes are a convenient way to describe a stream, do not expect them to be recognized by other applications.  Use four-character codes when creating a stream or transferring the information to other applications.

Because all the format information is in the header, the audio data contained in these data chunks does not contain any information about its format.  An audio data chunk has the following format (the ## in the format represents the stream identifier):

WAVE Bytes '##wb'
     BYTE  abBytes[];

Video data can be compressed or uncompressed DIBs.  An uncompressed DIB has BI_RGB specified for the biCompression member in its associated BITMAPINFO structure.  A compressed DIB has a value other than BI_RGB specified in the biCompression member.  For more information about compression formats, see the description of the BITMAPINFOHEADER data structure in the Microsoft Windows Programmer’s Reference.

A data chunk for an uncompressed DIB contains RGB video data.  These chunks are identified by a two-character code of ‘db’ (db is an abbreviation for DIB bits).  Data chunks for a compressed DIB are identified by a two-character code of ‘dc’ (dc is an abbreviation for DIB compressed).  Neither data chunk will contain any header information about the DIBs.  The data chunk for an uncompressed DIB has the following form:

DIB  Bits  '##db'
     BYTE  abBits[];

The data chunk for a compressed DIB has the following form:

Compressed DIB  Bits  '##dc'
                BYTE  abBits[];

Video data chunks can also define new palette entries used to update the palette during an AVI sequence.  For more information on specifying palette information, see Video for Windows Programmer’s Guide.

Text streams can use arbitrary two-character codes.

2.6	AVI RIFF File Reference
This section lists data structures used to support AVI RIFF files.  The structure definition is given, followed by a description of each member.
2.6.1	MainAVIHeader
The MainAVIHeader structure contains global information for the entire AVI file.  It is contained within an ‘avih’ chunk within the LIST ‘hdrl’ chunk at the beginning of an AVI RIFF file.

typedef struct {
	DWORD dwMicroSecPerFrame;
	DWORD dwMaxBytesPerSec;
	DWORD dwReserved1;
	DWORD dwFlags;
	DWORD dwTotalFrames;
	DWORD dwInitialFrames;
	DWORD dwStreams;
	DWORD dwSuggestedBufferSize;
	DWORD dwWidth;
	DWORD dwHeight;
	DWORD dwReserved[4];
} MainAVIHeader;

dwMicroSecPerFrame
Specifies the number of microseconds between frames.
dwMaxBytesPerSec
Specifies the approximate maximum data rate of a file.
dwReserved1
Reserved.  Set this to zero.
dwFlags
Specifies any applicable flags.  The following flags are defined:
AVIF_HASINDEX
Indicates the AVI file has an ‘idx1’ chunk containing an index at the end of the file.  For good performance, all AVI files should contain an index.
AVIF_MUSTUSEINDEX
Indicates that the index, rather than the physical ordering of the chunks in the file, should be used to determine the order of presentation of the data.  For example, this could be used for creating a list of frames for editing.
AVIF_ISINTERLEAVED
Indicates the AVI file is interleaved.
AVIF_WASCAPTUREFILE
Indicates the AVI file is a specially allocated file use for capturing real-time video.  Applications should warn the user before writing over a file with this flag set because the user probably defragmented this file.
AVIF_COPYRIGHTED
Indicates the AVI file contains copyrighted data and software.  When this flag is used, software should not permit the data to be duplicated.
dwTotalFrames
Specifies the number of frames of data in file.
dwInitialFrames
Specifies the initial frame for interleaved files.  Non-interleaved files should specify zero.
dwStreams
Specifies the number of streams in the file.  For example, a file with audio and video has two streams.
dwSuggestedBufferSize
Specifies the suggested buffer size for reading the file.  Generally, this size should be large enough to contain the largest check in the file.  If set to zero, or if it is too small, the playback software will have to reallocate memory during playback, which will reduce performance.  For an interleaved file, this buffer size should be large enough to read and entire record, and not just a chunk.
dwWidth
Specifies the width of the AVI file in pixels.
dwHeight
Specifies the height of the AVI file in pixels.
dwReserved[4]
Reserved.  Set this array to zero.

2.6.2	AVIStreamHeader
The AVIStreamHeader structure contains header information for a single stream of a file.  It is contained within an ‘strh’ chunk within a LIST ‘strl’ chunk that is itself contained with the LIST ‘hdrl’ chunk at the beginning of an AVI RIFF file.

typedef struct {
	FOURCC fccType;
	FOURCC fccHandler;
	DWORD  dwFlags;
	DWORD  dwPriority;
	DWORD  dwInitialFrames;
	DWORD  dwScale;
	DWORD  dwRate;
	DWORD  dwStart;
	DWORD  dwLength;
	DWORD  dwSuggestedBufferSize;
	DWORD  dwQuality;
	DWORD  dwSampleSize;
	RECT   rcFrame;
} AVIStreamHeader;

fccType
Contains a four-character code that specifies the type of the data contained in the stream.  The following standard AVI values for video and audio are defined:

 ‘vids’
Indicates the stream contains video data.  The stream format chunk contains a BITMAPINFO structure that can include palette information.
‘auds’
Indicates the stream contains audio data.  The stream format chunk contains a WAVEFORMATEX or PCMWAVEFORMAT structure.
fccHandler
Optionally, contains a four-character code that identifies a specific data handler.  The data handler is the preferred handler for the stream.
dwFlags
Specifies any applicable flags.  The bits in the high-order word of these flags are specific to the type of data contained in the stream.  The following standard flags are defined:
AVISF_DISABLED
Indicates this stream should not be enabled by default.
AVISF_VIDEO_PALCHANGES
Indicates this video stream contains palette changes.  This flag warns the playback software that it will need to animate the palette.
dwPriority
Specifies prioriyt of a stream type.  For example, in a file with multiple audio streams, the one with the highest priority might be the default stream.
dwInitialFrames
Specifies how far audio data is skewed ahead of the video frames in interleaved files.  Typically, this is about 0.75 seconds.
dwScale
Used together with dwRate to specify the time scale that this stream will use.  Dividing dwRate by dwScale gives the number of samples per second.  For video streams, this rate should be the frame rate.  For audio streams, this rate should correspond to the time needed for nBlockAlign bytes of audio, which for PCM audio simply reduces to the sample rate.
dwRate
See dwScale.
dwStart
Specifies the starting time of the AVI file.  The units are defined by the dwRate and dwScale members in the main file header.  Usually, this is zero, but it can specify a delay time for a stream that does not start concurrently with the file.
dwLength
Specifies the length of this stream.  The units are defined by the dwRate and dwScale members of the stream’s header.
dwSuggestedBufferSize
Specifies how large a buffer should be used to read this stream.  Typically, this contains a value corresponding to the largest chunk present in the stream.  Using the correct buffer size make playback more efficient.  Use zero if you do not know the correct buffer size.
dwQuality
Specifies an indicator of the quality of the data in the stream.  Quality is represented as a number between 0 and 10000.  For compressed data, this typically represents the value of the quality parameter passed to the compression software.  If set to –1, drivers use the default quality value.
dwSampleSize
Specifies the size of a single sample of data.  This is set to zero if the samples can vary in size.  If this number is non-zero, then multiple samples of data can be grouped into a single chunk within the file.  If it is zero, each sample of data (such as a video frame) must be in a separate chunk.  For video streams, this number is typically zero, although it can be non-zero if all video frames are the same size.  For audio streams, this number should be the same as the nBlockAlign member of the WAVEFORMATEX structure describing the audio.
rcFrame
Specifies the destination rectangle for a text or video stream within the movie rectangle specified by the dwWidth and dwHeight members of the MainAVIHeader structure.  The rcFrame member is typically used in support of multiple video streams.  Set this rectangle to the coordinates corresponding to the movie rectangle to update the whole movie rectangle.  Units for this member are pixels.  The upper-left corner of the destination rectangle to relative to the upper-left corner of the movie rectangle.

2.6.3	BITMAPINFOHEADER structure
The BITMAPINFOHEADER structure contains information for the video stream of an AVI RIFF file.  This structure has the following members:

typedef struct tagBITMAPINFOHEADER {
	DWORD  biSize;
	LONG   biWidth;
	LONG   biHeight;
	WORD   biPlanes;
	WORD   biBitCount;
	DWORD  biCompression;
	DWORD  biSizeImage;
	LONG   biXPelsPerMeter;
	LONG   biYPelsPerMeter;
	DWORD  biClrUsed;
	DWORD  biClrImportant;
} BITMAPINFOHEADER;

Information about the compression format is specified in the biCompression and biBitCount members.  The biCompression member specifies the type of compression used or requested.  Both existing and new compression formats use this member.

The biBitCount member specifies the number of bits per pixel.  Some compression formats need this information to properly decode the colors in the pixel.

When the value in the biBitCount member is set to less than or equal to eight, video drivers can assume the bitmap uses a palette or color table defined in the BITMAPINFO data structure.  This data structure has the following members:

typedef struct tagBITMAPINFO {
	BITMAPINFOHEADER bmiHeader;
	RGBQUAD          bmiColors[1];
} BITMAPINFO;

When the value in the biBitCount member is set to greater than eight, video drivers can assume bitmaps are true color and they do not use a color table.  For more information about these data structures, see the Microsoft Windows Programmer’s Reference.

2.6.4	WAVEFORMATEX structure
The WAVEFORMATEX structure contains information for the audio stream(s) of an AVI RIFF file.  This structure has the following members:

typedef struct waveformat_extended_tag {
	WORD  wFormatTag;      /* format type */
	WORD  nChannels;       /* number of channels (i.e. mono, stereo...) */
	DWORD nSamplesPerSec;  /* sample rate */
	DWORD nAvgBytesPerSec; /* for buffer estimation */
	WORD  nBlockAlign;     /* block size of data */
	WORD  wBitsPerSample;  /* Number of bits per sample of mono data */
	WORD  cbSize;          /* The count in bytes of the extra size */
} WAVEFORMATEX;

wFormatTag
Defines the type of WAVE file.
nChannels
Number of channels in the wave, 1 for mono, 2 for stereo.
nSamplesPerSec
Frequency of the sample rate of the wave file.  Examples are 11025, 22050, or 44100.  This rate is also used by the sample size entry in the fact chunk to determine the length in time of the data
nAvgBytesPerSec
Average data rate.  Playback software can estimate the buffer size using the nAvgBytesPerSec value.
nBlockAlign
The block alignment (in bytes) of the data.  Playback software needs to process a multiple of nBlockAlign bytes of data at a time, so that the value of nBlockAlign can be used for buffer alignment.
wBitsPerSample
This is the number of bits per sample per channel data.  Each channel is assumed to have the same sample resolution.  If this field is not needed, then it should be set to zero.
cbSize
The size (in bytes) of the extra information in the WAVE format header, not including the size of the WAVEFORMATEX structure.  As an example, in the IMA ADPCM format, cbSize is calculated as sizeof(IMAADPCMWAVEFORMAT) - sizeof(WAVEFORMATEX) which yields two.