Detailed explanation of AVI File Format]

Source: Internet
Author: User
Tags microsoft video

Avi is the abbreviation of audio video interleaved. It is a digital audio and video file format developed by Microsoft to comply with Riff file specifications, it was originally used in Microsoft Video for Windows (VFW for short) environments and is now directly supported by most operating systems such as Windows 95/98 and OS/2. The AVI format allows video and audio to be played in parallel and supports 256-color and RLE compression, but the AVI file is not limited to compression standards. Therefore, the AVI file format is only used as the standard on the control interface, non-compatible. AVI files generated using different compression algorithms must be decompressed to play out. Commonly used Avi play driver, mainly Microsoft Video for Windows or Windows 95/98 Video 1, as well as Intel's Indeo video.

Before introducing the AVI file, let's take a look at the structure of the riff file. AVI files use the riff file structure. Riff (resource Interchange File Format) is a file format defined by Microsoft to manage multimedia data in windows, waveform audio wave, Midi, and digital video Avi are stored in this format. The basic unit for constructing a riff file is called a chunk. Each data block contains three parts,

1. 4-byte data block mark (or data block ID)

2. Data Block Size

3. Data

The entire riff file can be regarded as a data block. Its data block ID is Riff, which is called riff block. Only one riff block is allowed in a riff file. A riff block contains a series of sub-blocks. One of the block IDS is "list", which is called list. A list block can contain a series of sub-blocks, however, all sub-blocks except list blocks cannot contain sub-blocks.

Riff and list blocks have one more data field called form type and list type than normal data blocks, which are composed of the following:

1. 4-byte chunk ID)

2. Data Block Size

3. 4-byte format or list type

4. Data

Next we will look at the structure of the AVI file. AVI files are currently the most complex riff files used. They can simultaneously store audio and video data during synchronization. The format of the AVI riff block is Avi, which contains three child blocks, as described below:

1. Information block. A list block with ID "hdrl" defines the data format of the AVI file.

2. Data Block: A list block with the ID of "movi", containing Avi audio and video sequence data.

3. Index block: the sub-block with the ID of "idxl". It defines the index data of the "movi" list block and is an optional block.

Shows the structure of the AVI file. The following describes the construction of each sub-block of the AVI file.

1. Information block. The information block contains two subblocks: A subblock with ID avih and a list block with ID strl.


The content of the "avih" sub-block can be defined by the following structure:

Typedef struct
{
DWORD dwmicrosecperframe; // display the time NS required for each worker, defining the display rate of AVI
DWORD dwmaxbytespersec; // maximum data transmission rate
DWORD dwpaddinggranularity; // The length of the record block must be a multiple of this value, usually 2048
DWORD dwflages; // special attributes of the AVI file, such as whether the index block is included or whether audio/video data is cross-stored
DWORD dwtotalframe; // the total number of workers in the file
DWORD dwinitialframes; // specifies the number of shards required before playback.
DWORD dwstreams; // data stream types contained in the file
DWORD dwsuggestedbuffersize; // recommended buffer size,
// It is usually the sum of the data needed to store a pair of images and synchronize sounds
DWORD dwwidth; // Image Width
DWORD dwheight; // Image Height
DWORD dwreserved [4]; // reserved value
} Mainaviheader;


"Strl" list blocks are used to record AVI data streams. Each Data Stream occupies three sub-blocks in this list. Their IDs are "strh", "STRF ", "strd ";
The "strh" sub-block is defined by the following structure.

Typedef struct
{
Fourcc fcctype; // 4 bytes, which indicates the type of data stream vids indicates the video data stream
// Auds audio data stream
Fourcc fcchandler; // 4-byte, indicating the driver code for data stream Decompression
DWORD dwflags; // data stream attributes
Word wpriority; // playback priority of the data stream
Word wlanguage; // audio language code
DWORD dwinitalframes; // specifies the number of shards required before playback.
DWORD dwscale; // data volume. The video size per region or the audio sampling size
DWORD dwrate; // dwscale/dwrate = number of samples per second
DWORD dwstart; // the position where the stream starts to play, in dwscale.
DWORD dwlength; // data stream data volume, in dwscale
DWORD dwsuggestedbuffersize; // recommended buffer size
DWORD dwquality; // extract the quality parameter. The larger the value, the better the quality.
DWORD dwsamplesize; // audio sampling size
Rect rcframe; // The rectangle occupied by the video image
} Avistreamheader;


The structure of the "STRF" sub-block is determined by the type of the "strh" sub-block. If the strh sub-block is a video data stream, the content of the STRF sub-block is a bimapinfo structure unrelated to the Windows Device, as follows:

Typedef struct tagbitmapinfo
{
Bitmapinfoheader bmiheader;
Rgbquad bmicolors [1]; // color table
} Bitmapinfo;

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;


If the strh sub-block is an audio data stream, the content of the STRF sub-block is a waveformat structure, as shown below:

Typedef struct
{
Word wformattag;
Word nchannels; // number of audio channels
DWORD nsamplespersec; // Sampling Rate
DWORD navgbytespersec; // data volume per second in the wave sound
Word nblockalign; // alignment mark of data blocks
Word bisize; // the size of this structure
} Waveformat


The "strd" sub-block follows the STRF sub-block and stores the parameters used by the compression driver. They do not exist and do not have a fixed structure.

"Strl" list block-defined Avi Data Streams link the data stream header structure in the "hdrl" list block with the data in the "movi" list block in sequence, the first data stream header structure is used for data stream 0, the second is used for data stream 1, and so on.

The data block stores video and audio data streams, and the data can be directly stored in the "movi" list block. Audio and video data in data blocks are stored in different word blocks. The structure is described as follows,

Audio Block
"## WB"
Wave Data Streams
The Dib data is stored in the video sub-block, which can be compressed or uncompressed,
"## DB"
RGB data streams
"# DC"
Compressed image data stream

(If the first stream is audio, the 4-digit code is '00wb '; if the second stream is video, the 4-digit code is '00db' or '00dc ')..... (the original online statement may be 01db or 01dc)

As you can see, the image data of the AVI file can be compressed or non-compressed. Different encoding formats can also be used for compression. You may have encountered some problems that cannot be identified by Avi, because the encoding method is different. If no corresponding decoding is available, you cannot identify video data. There are many Avi encoding methods, such as MPEG2, MPEG4, and DivX.

Index block: The index quickly contains the index of the data block in the file, which can improve the read and write speed of AVI files, including a set of aviindexentry structure data. As shown below, this block is not required and may not exist.

Typedef struct
{
DWORD ckid; // mark the subblock of the record data block
DWORD dwflags; // indicates the attributes of the sub-block referred to by the chid.
DWORD dwchunkoffset; // relative position of the sub-block
DWORD dwchunklength; // sub-block Length
};

Detailed explanation of AVI File Format]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.