Avi is an audio video
Interleaved) is a digital audio and video file format developed by Microsoft to comply with Riff file specifications. It was originally used in Microsoft
The video for Windows (VFW for short) environment has been
95/98 and OS/2 are directly supported by most operating systems. The AVI format allows video and audio to be played in a staggered manner, and supports 256-color and RLE compression. However, the AVI file is not limited to compression standards,
Therefore, the AVI file format is only used as the standard on the control interface and is not compatible. Different compression methods are used.AlgorithmThe generated AVI file can be played out only by using the corresponding decompression algorithm. Common AVI broadcasts
ReleaseDriverProgramMicrosoft Video for Windows or Windows 95/98 Video 1 and Intel's Indeo video.
Before introducing the AVI file, let's take a look at the structure of the riff file. The AVI file adopts the riff file structure, Riff (resource Interchange
File
Format, resource Interchange File Format) is a file format defined by Microsoft to manage multimedia data in Windows environments, waveform audio wave, Midi and digital video Avi
All 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. The riff block contains a series
The ID of a block 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.
Block.
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 with Avi because of encoding.
The encoding method is different. Without corresponding decoding, you cannot identify the 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
};