During this time, we were engaged in video synthesis, So we planned to first understand the AVI Video Format and introduce a lot of Google content, but it was a tragedy, today, most people like copy. The content basically comes from the same article. It does not help me very much. We wanted to analyze the structure of AVI by looking at the source code of AVI synthesis. However, in windows, the program basically calls DirectShow and the format methods are encapsulated.
You can only analyze it yourself.
Before you start, first look at the AVI file format diagram:
Next we will analyze the following data (this data captures the file header of a video file ):
[0 1 2 3 4 4 5 6 7 8 9 10 11 12 13 14 15 0123456789012345]
000000000:
52 49 46 46 DC 6C 57 09
41 56 49 20 4C 49 53 54 | riff. LW. Avi list |
000000016:
CC 41 00 00 68 64 72 6c
61 76 69 68 38 00 00 00 |. A... hdrlavih8... |E
000000032:
50 C3 00 00 00 B0 04 00 00 00 00 10 00 00 00 | P ...... |C
000000048:
A8 02 00 00 00 00 00
01 00 00 00 00 84 03 00 | ......... |
000000064:
40 01 00 00 F0 00 00 00 00 00 00 00 00 | @ ...... |
000000080: 00 00 00 00 00 00 00 00 4C 49 53 54 74 40 00 00 | ...... listt @... |
000000096: 73 74 72 6C 73 74 72 68 38 00 00
76 69 64 73 | strlstrh8... vids |
000000112: 00 00 00 00 00 00 00 00 00 00 00 | ...... |
000000128: 64 00 00 00 D0 07 00 00 00 00 00 00 A8 02 00 00 | D ...... |
000000144: 00 84 03 00 10 27 00 00 00 00 00 00 00 |... '... |
000000160: 40 01 F0 00 73 74 72 66 28 00 00 00 00 00 | @... STRF (... |
000000176: 40 01 00 00 F0 00 00 00 01 00 18 00 00 00 00 | @ ...... |
000000192: 00 84 03 00 00 00 00 00 00 00 00 00 00 | ...... |
000000208: 00 00 00 69 6e 64 78 F8 3f 00 00 04 00 00 00 | ...... indx .?...... |
000000224: 01 00 00 00 30 30 64 62 00 00 00 00 00 00 | ...... 00db ...... |
000000240: 00 00 00 00 0C 44 00 00 00 00 00 00 00 |... d... @... |
.
.
000017408:
4c 49 53 54 38 F9 56 09
6D 6f 76 69 69 78 30 30 | list8.v. moviix00 |
000017424: F8 3f 00 00 02 00 01 A8 02 00 00
30 30 64 62 | .?.......... 00db |
"Avih" sub-block:
Typedefstruct_avimainheader {
Fourcc FCC; // It Must Be 'avih'
Dword cb; // the size of the data structure, excluding the initial 8 bytes (fcc and CB) structsize
DWORD dwmicrosecperframe; // video frame interval (in milliseconds)
DWORD dwmaxbytespersec; // maximum data rate of the AVI file
DWORD dwpaddinggranularity; // data filling Granularity
DWORD dwflags; // global tag of the AVI file, such as whether the index block is contained
DWORD dwtotalframes; // total number of frames
DWORD dwinitialframes; // specify the initial number of frames for the interactive format (the non-interactive format should be set to 0)
DWORD dwstreams; // Number of streams contained in this file
DWORD dwsuggestedbuffersize; // we recommend that you read the cache size of this file (the maximum block size should be supported)
DWORD dwwidth; // video image width (in pixels)
DWORD dwheight; // video image height (in pixels)
DWORD dwreserved [4]; // Reserved
} Avimainheader;
-
[0 1 2 3 4 4 5 6 7 8 9 10 11 12 13 14 15 0123456789012345]
-
000000000: 52 49 46 46
DC 6C 57 09 41 56 49 20
4c 49 53 54| Riff. LW. Avi list | riff
Filesize filetype
List
-
000000016: CC 41 00 00
68 64 72 6C 61 76 69 68
38 00 00 00 |. A... hdrlavih8... | Listsize
ListtypeAvih
Structure Size
-
000000032: 50 C3 00 00
00 B0 04 00 00 00 00 00
10 00 00 00 | P ...... | Inter-Frame Time
Maximum data rate filling Granularity
Global tag
-
000000048: A8 02 00 00
00 00 00 00 01 00 00 00
00 84 03 00 | ...... | Total Frames
Interaction Frame Count stream count
Suggested Cache
-
000000064: 40 01 00 00
F0 00 00 00 00 00 00 00 00 00 00 | @ ...... | Width
Height Retained
-
000000080: 00 00 00 00 00 00 00
"Strh" sub-block:
Typedefstruct_avistreamheader {
Fourcc FCC; // The value must be 'strh'
Dword cb; // size of the data structure, excluding the first 8 bytes (fcc and CB)
Fourcc fcctype; // stream type: 'auds '(audio stream), 'vids' (Video Stream ),
// 'Mids '(MIDI stream) and 'txts' (Text Stream)
Fourcc fcchandler; // specifies the stream processor, which is a decoder for audio and video.
DWORD dwflags; // flag: can this stream be output? Does the palette change?
Word wpriority; // stream priority (when multiple streams of the same type have the highest priority, the default stream is used)
Word wlanguage;
DWORD dwinitialframes; // specify the initial number of frames for the interaction format
DWORD dwscale; // The time scale used by the stream
DWORD dwrate;
DWORD dwstart; // stream Start Time
DWORD dwlength; // The stream length. The unit is related to the dwscale and dwrate definitions)
DWORD dwsuggestedbuffersize; // The cache size recommended for reading this stream data
DWORD dwquality; // streaming data quality indicator (0 ~ 10,000)
DWORD dwsamplesize; // sample size
Struct {
Optional int left;
Optional int top;
Optional int right;
Using int bottom;
} Rcframe; // specifies the position of the stream (video stream or text stream) in the main video window.
// The main video window is determined by dwwidth and dwheight in the avimainheader structure.
} Avistreamheader;
-
4c 49 53 54
74 40 00 00
| ...... Listt @... |
ListListsize
-
000000096: 73 74 72 6c
73 74 72 68
38 00 00 00 76 69 64 73 | strlstrh8... vids |
Strl strh Structure Size
Stream type (vids)
-
000000112: 00 00 00 00 00 00 00 00 00 00 00 | ...... |
Stream processor dwflags
Wpriority wlanguage Interaction Frames
-
000000128: 64 00 00 00 D0 07 00 00 00 00 00 00 A8 02 00 00 | D ...... |
-
000000144: 00 84 03 00 10 27 00 00 00 00 00 00 00 |... '... |
-
000000160: 40 01 F0 00
"STRF" sub-block:
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;
73 74 72 66 28 00 00 00 00 00 | @... STRF (... | STRF
000000176: 40 01 00 00 F0 00 00 00 01 00 18 00 00 00 00 | @ ...... |
000000192: 00 84 03 00 00 00 00 00 00 00 00 00 00 | ...... |
000000208: 00 00 00
Index sub-block:
Typedefstruct_avioldindex {
Fourccfcc; // The value must be 'idx1'
Dwordcb; // the size of the data structure, excluding the first 8 bytes (fcc and CB)
Struct_avioldindex_entry {
Dworddwchunkid; // the four-digit code that represents the data block.
Dworddwflags; // indicates whether the data block is a key frame or a 'rec 'list.
Dworddwoffset; // the offset of the data block in the file
Dworddwsize; // size of the data block
} Aindex []; // This is an array! Define an index for each media Block
} Avioldindex;
69 6e 64 78
F8 3f 00 00 04 00 00 |... indx .?...... | Indx
000000224: 01 00 00 00 30 30 64 62 00 00 00 00 00 00 | ...... 00db ...... |
000000240: 00 00 00 00 0C 44 00 00 00 00 00 00 00 |... d... @... |
000017408: 4C 49 53 54
38 F9 56 09 6D 6f 76 69 69 78 30 30 | list8.v. moviix00 | listListsize
Listtype indexblock(Ix00)
000017424: F8 3f 00 00 02 00 01 A8 02 00 00
30 30 64 62 | .?.......... 00db |... 00db (uncompressed video frame)