Http://blog.csdn.net/becomly/article/details/6283004
Http://blog.csdn.net/easecom/article/details/4508094
VI (abbreviation of audio video interleaved) is a type of riff (short for resource Interchange File Format) file format. It is mostly used in audio/video capturing, editing, playback, and other applications. Normally, an AVI file can contain multiple different types of media streams (in typical cases, there is an audio stream and a video stream ), however, AVI files containing a single audio stream or a single video stream are also valid. Avi is the most basic and commonly used media file format in windows.
First, we will introduce the riff file format. The riff file uses the four-character code fourcc (four-character code) to characterize the data type, such as 'riff', 'av', and 'LIST. Note: In Windows, the byte sequence is little-Endian. Therefore, the actual DWORD Value of a four-character code 'abcd' should be 0x64636261. In addition, it is legal that the four-digit code contains spaces like 'av.
The riff file first contains a file header structure.
The first four bytes are a four-byte code 'riff', which indicates that this is a riff file, followed by four bytes to indicate the size of the riff file; then there is a four-digit code indicating the specific type of the file (such as avi and wave), and finally the actual data. Note that the calculation method of the file size value is: actual Data Length + 4 (size of the file type field); that is, the file size does not include the size of the 'riff' domain and the "file size" domain.
In the actual data of the riff file, the list and chunk are usually used for organization. The list can be nested with sublists and blocks. Here, the list structure is: 'LIST' listsize listtype listdata -- 'LIST' is a four-byte code, indicating that this is a list; listsize occupies 4 bytes and records the size of the entire list; listtype is also a four-digit code, indicating the specific type of the List; listdata is the actual list data. Note that the calculation method of the listsize value is: the actual length of the list data + 4 (the size of the listtype field); that is, the listsize value does not include the size of the 'LIST' and listsize fields. Next, let's look at the block structure: ckid cksize ckdata -- ckid is a four-byte code that represents the block type. cksize occupies 4 bytes and records the size of the entire block. ckdata is the actual block data. Note that the cksize value refers to the actual block data length, excluding the size of the ckid and cksize fields. (Note: In the following content, a list is represented in the form of list (listtype (listdata), and a block is represented in ckid (ckdata, for example, the elements in [optional element] are represented as optional .)
Next we will introduce the AVI file format. The AVI file type is represented by a four-character code 'avi. The structure of the entire AVI file is: a riff header + two lists (one for describing the media stream format, one for saving media stream data) + an optional index block. The structure of the AVI file is roughly as follows:
Riff ('avi' list ('hdrl' avih '(Master Avi information header data) List ('strl' 'strh' (Stream header information data) 'strf' (Stream format information data) ['strd' (optional additional header information data)] ['strn' (name of an optional stream)]...) list ('movi' {subchunk | list ('rec 'subchunk1 subchunk2 ...)...}...) ['idx1' (optional Avi index block data)])
[email protected]:~/download$ hexdump -n 256 -C "[H264 [email protected] 480P AC3 1M] Animal.2005.avi"00000000 52 49 46 46 18 75 c7 2b 41 56 49 20 4c 49 53 54 |RIFF.u.+AVI LIST|00000010 72 22 00 00 68 64 72 6c 61 76 69 68 38 00 00 00 |r"..hdrlavih8...|00000020 ec a2 00 00 00 00 00 00 00 00 00 00 10 01 00 00 |................|00000030 eb 0b 02 00 00 00 00 00 02 00 00 00 00 00 00 00 |................|00000040 80 02 00 00 50 01 00 00 00 00 00 00 00 00 00 00 |....P...........|00000050 00 00 00 00 00 00 00 00 4c 49 53 54 94 10 00 00 |........LIST....|00000060 73 74 72 6c 73 74 72 68 38 00 00 00 76 69 64 73 |strlstrh8...vids|00000070 78 32 36 34 00 00 00 00 00 00 00 00 00 00 00 00 |x264............|00000080 7d 00 00 00 b5 0b 00 00 00 00 00 00 eb 0b 02 00 |}...............|00000090 c7 03 01 00 10 27 00 00 00 00 00 00 00 00 00 00 |.....‘..........|000000a0 80 02 50 01 73 74 72 66 28 00 00 00 28 00 00 00 |..P.strf(...(...|000000b0 80 02 00 00 50 01 00 00 01 00 10 00 48 32 36 34 |....P.......H264|000000c0 00 b0 13 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|000000d0 00 00 00 00 4a 55 4e 4b 18 10 00 00 00 00 00 00 |....JUNK........|000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
[email protected]:~/download$ hexdump -s 4340 -n 256 -C "[H264 [email protected] 480P AC3 1M] Animal.2005.avi"
000010f4 4c 49 53 54 7e 10 00 00 73 74 72 6c 73 74 72 68 |LIST~...strlstrh|
00001104 38 00 00 00 61 75 64 73 00 00 00 00 00 00 00 00 |8...auds........|
00001114 00 00 00 00 01 00 00 00 01 00 00 00 60 6d 00 00 |............`m..|
00001124 00 00 00 00 00 09 56 09 b0 36 00 00 ff ff ff ff |......V..6......|
00001134 01 00 00 00 79 00 74 00 6d 00 6d 00 73 74 72 66 |....y.t.m.m.strf|
00001144 12 00 00 00 00 20 06 00 80 bb 00 00 60 6d 00 00 |..... ......`m..|
00001154 01 00 00 00 00 00 4a 55 4e 4b 18 10 00 00 00 00 |......JUNK......|
00001164 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000011f4
[email protected]:~/download$ hexdump -s 156 -n 256 -C "[H264 [email protected] 480P AC3 1M] Animal.2005.avi"
0000009c 00 00 00 00 80 02 50 01 73 74 72 66 28 00 00 00 |......P.strf(...|
000000ac 28 00 00 00 80 02 00 00 50 01 00 00 01 00 10 00 |(.......P.......|
000000bc 48 32 36 34 00 b0 13 00 00 00 00 00 00 00 00 00 |H264............|
000000cc 00 00 00 00 00 00 00 00 4a 55 4e 4b 18 10 00 00 |........JUNK....|
000000dc 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
0000019c
[email protected]:~/download$ hexdump -s 100 -n 256 -C "[H264 [email protected] 480P AC3 1M] Animal.2005.avi"
00000064 73 74 72 68 38 00 00 00 76 69 64 73 78 32 36 34 |strh8...vidsx264|
00000074 00 00 00 00 00 00 00 00 00 00 00 00 7d 00 00 00 |............}...|
00000084 b5 0b 00 00 00 00 00 00 eb 0b 02 00 c7 03 01 00 |................|
00000094 10 27 00 00 00 00 00 00 00 00 00 00 80 02 50 01 |.‘............P.|
000000a4 73 74 72 66 28 00 00 00 28 00 00 00 80 02 00 00 |strf(...(.......|
000000b4 50 01 00 00 01 00 10 00 48 32 36 34 00 b0 13 00 |P.......H264....|
000000c4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000000d4 4a 55 4e 4b 18 10 00 00 00 00 00 00 00 00 00 00 |JUNK............|
000000e4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000164
[email protected]:~/download$ hexdump -s 730200168 -n 256 -C "[H264 [email protected] 480P AC3 1M] Animal.2005.avi"
2b85f868 69 64 78 31 b0 7c 41 00 30 31 77 62 10 00 00 00 |idx1.|A.01wb....|
2b85f878 04 00 00 00 b0 36 00 00 30 30 64 63 00 00 00 00 |.....6..00dc....|
2b85f888 bc 36 00 00 00 00 00 00 30 31 77 62 10 00 00 00 |.6......01wb....|
2b85f898 c4 36 00 00 90 04 00 00 30 30 64 63 00 00 00 00 |.6......00dc....|
2b85f8a8 5c 3b 00 00 00 00 00 00 30 31 77 62 10 00 00 00 |\;......01wb....|
2b85f8b8 64 3b 00 00 90 04 00 00 30 30 64 63 10 00 00 00 |d;......00dc....|
2b85f8c8 fc 3f 00 00 fd 00 00 00 30 31 77 62 10 00 00 00 |.?......01wb....|
2b85f8d8 02 41 00 00 90 04 00 00 30 30 64 63 00 00 00 00 |.A......00dc....|
2b85f8e8 9a 45 00 00 15 00 00 00 30 31 77 62 10 00 00 00 |.E......01wb....|
2b85f8f8 b8 45 00 00 90 04 00 00 30 30 64 63 00 00 00 00 |.E......00dc....|
2b85f908 50 4a 00 00 12 00 00 00 30 31 77 62 10 00 00 00 |PJ......01wb....|
2b85f918 6a 4a 00 00 90 04 00 00 30 30 64 63 00 00 00 00 |jJ......00dc....|
2b85f928 02 4f 00 00 12 00 00 00 30 31 77 62 10 00 00 00 |.O......01wb....|
2b85f938 1c 4f 00 00 8f 04 00 00 30 30 64 63 00 00 00 00 |.O......00dc....|
2b85f948 b4 53 00 00 15 00 00 00 30 31 77 62 10 00 00 00 |.S......01wb....|
2b85f958 d2 53 00 00 90 04 00 00 30 30 64 63 00 00 00 00 |.S......00dc....|
The standard type code is defined as follows: 'db' (non-compressed video frame), 'dc' (compressed video frame), and 'pc' (use a new color palette) and 'wb '(audio reduction video ). For example, if the first stream 0 is audio, the four character code representing the audio data block is '00wb ', and the second stream (Stream 1) is video, the four-digit code representing the video data block is '00db' or '00dc '. For video data, a new palette can be defined in the middle of the Avi Data Sequence. Each changed palette data block is characterized by 'xxpc, the new palette is defined using a Data Structure avipalchange. (Note: If the color of a stream may change midway through, you should include an avisf_video_palchanges mark in the description of the stream format, that is, dwflags of the avistreamheader structure .) In addition, the data block of a text stream can use arbitrary type code table.
Finally, the index block that follows the 'hdrl' list and 'movi' list is an optional index block for the AVI file. This index block is used to index each media block in the AVI file, and records their offset in the file (which may be relative to the 'movi' list or start with the AVI file ). The index block is characterized by a four-character code 'idx1'. The index information is defined by avioldindex using a data structure.
Typedef struct _ avioldindex {
Fourcc FCC; // The value must be 'idx1'
Dword cb; // size of the data structure, excluding the first 8 bytes (fcc and CB)
Struct _ avioldindex_entry {
DWORD dwchunkid; // the four-digit code representing the data block
DWORD dwflags; // indicates whether the data block is a key frame or a 'rec 'list.
DWORD dwoffset; // the offset of the data block in the file
DWORD dwsize; // size of the data block
} Aindex []; // This is an array! Define an index for each media Block
} Avioldindex;
NOTE: If an AVI file package contains an index block, an avif_hasindex mark should be included in the description of the master Avi information header, that is, dwflags of the avimainheader structure.
AA