百思不得其解之余,还只自己分析吧。
开始之前,先看看avi的文件格式图:
[ 0 1 2 3 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 00 10 00 00 00 |P...............| c
000000048: A8 02 00 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 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 00 76 69 64 73 |strlstrh8...vids|
000000112: 00 00 00 00 00 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 00 00 00 |.....'..........|
000000160: 40 01 F0 00 73 74 72 66 28 00 00 00 28 00 00 00 |@...strf(...(...|
000000176: 40 01 00 00 F0 00 00 00 01 00 18 00 00 00 00 00 |@...............|
000000192: 00 84 03 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000000208: 00 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 00 00 |....00db........|
000000240: 00 00 00 00 0C 44 00 00 00 00 00 00 00 40 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 00 01 A8 02 00 00 30 30 64 62 |.?..........00db|
"avih"子块:
typedefstruct_avimainheader{
FOURCC fcc;//必须为‘avih’
DWORD cb;//本数据结构的大小,不包括最初的8个字节(fcc和cb两个域)structsize
DWORD dwMicroSecPerFrame;//视频帧间隔时间(以毫秒为单位)
DWORD dwMaxBytesPerSec;//这个AVI文件的最大数据率
DWORD dwPaddingGranularity;//数据填充的粒度
DWORD dwFlags;//AVI文件的全局标记,比如是否含有索引块等
DWORD dwTotalFrames;//总帧数
DWORD dwInitialFrames;//为交互格式指定初始帧数(非交互格式应该指定为0)
DWORD dwStreams;//本文件包含的流的个数
DWORD dwSuggestedBufferSize;//建议读取本文件的缓存大小(应能容纳最大的块)
DWORD dwWidth;//视频图像的宽(以像素为单位)
DWORD dwHeight;//视频图像的高(以像素为单位)
DWORD dwReserved[4];//保留
}AVIMAINHEADER;
"strh"子块:
typedefstruct_avistreamheader{
FOURCC fcc;//必须为‘strh’
DWORD cb;//本数据结构的大小,不包括最初的8个字节(fcc和cb两个域)
FOURCC fccType;//流的类型:‘auds’(音频流)、‘vids’(视频流)、
//‘mids’(MIDI流)、‘txts’(文字流)
FOURCC fccHandler;//指定流的处理者,对于音视频来说就是解码器
DWORD dwFlags;//标记:是否允许这个流输出?调色板是否变化?
WORD wPriority;//流的优先级(当有多个相同类型的流时优先级最高的为默认流)
WORD wLanguage;
DWORD dwInitialFrames;//为交互格式指定初始帧数
DWORD dwScale;//这个流使用的时间尺度
DWORD dwRate;
DWORD dwStart;//流的开始时间
DWORD dwLength;//流的长度(单位与dwScale和dwRate的定义有关)
DWORD dwSuggestedBufferSize;//读取这个流数据建议使用的缓存大小
DWORD dwQuality;//流数据的质量指标(0~10,000)
DWORD dwSampleSize;//Sample的大小
struct{
shortint left;
shortint top;
shortint right;
shortint bottom;
}rcFrame;//指定这个流(视频流或文字流)在视频主窗口中的显示位置
//视频主窗口由AVIMAINHEADER结构中的dwWidth和dwHeight决定
}AVISTREAMHEADER;
4C 49 53 54 74 40 00 00 |........LISTt@..| LIST listSize
"strf"子块:
typedef struct tagBITMAPINFO
{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1]; //颜色表
}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 28 00 00 00 |@...strf(...(...| strf
000000176: 40 01 00 00 F0 00 00 00 01 00 18 00 00 00 00 00 |@...............|
000000192: 00 84 03 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000000208: 00 00 00 00
Index子块:
typedefstruct_avioldindex{
69 6E 64 78 F8 3F 00 00 04 00 00 00 |....indx.?......| indx
000000224: 01 00 00 00 30 30 64 62 00 00 00 00 00 00 00 00 |....00db........|
000000240: 00 00 00 00 0C 44 00 00 00 00 00 00 00 40 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 00 01 A8 02 00 00 30 30 64 62 |.?..........00db| .... 00db ( uncompressed video frame )