typedef int INT;
typedef long DWORD;
typedef long FOURCC;
typedef unsigned char byte;

//自定义的结构用于记载文件指针，图像高宽大小以及已插入的帧个数
typedef struct {
	FILE *file;
	long totalframes;
	long width;
	long height;
	long biSize;
	long index;	
} AVIMESSAGE;

//自定义的结构用于记载文件指针，图像高宽大小以及帧索引数据
typedef struct {
	FILE *file;
	long totalframes;
	long width;
	long height;
	long biSize;
	long *index;
	long dwScale;
	long dwRate;	
} AVIREADMESSAGE;

typedef struct rect
{
         short int left;
         short int top;
         short int right;
         short int bottom;
}RECT;  

typedef struct
{
    short    bfType;
    long   bfSize;
    short    bfReserved1;
    short    bfReserved2;
    long   bfOffBits;
} BITMAPFILEHEADER;

#ifndef _BITMAPINFOHEADER_
#define _BITMAPINFOHEADER_
typedef struct
{
    int 	biSize;
    int  	biWidth;
    int  	biHeight;
    short 	biPlanes;
    short 	biBitCount;
    int 	biCompression;
    int 	biSizeImage;
    int  	biXPelsPerMeter;
    int  	biYPelsPerMeter;
    int 	biClrUsed;
    int 	biClrImportant;
} BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
typedef struct {
	BITMAPINFOHEADER bmiHeader;
	int	bmiColors[1];
} BITMAPINFO, *LPBITMAPINFO;
#define BI_RGB 0
#endif


#ifndef mmioFOURCC
#define mmioFOURCC( ch0, ch1, ch2, ch3 )				\
	( (long)(unsigned char)(ch0) | ( (long)(unsigned char)(ch1) << 8 ) |		\
	( (long)(unsigned char)(ch2) << 16 ) | ( (long)(unsigned char)(ch3) << 24 ) )
#endif

#ifndef aviTWOCC
#define aviTWOCC(ch0, ch1) ((short)(unsigned char)(ch0) | ((short)(unsigned char)(ch1) << 8))
#endif

#define ICTYPE_VIDEO	mmioFOURCC('v', 'i', 'd', 'c')
#define ICTYPE_AUDIO	mmioFOURCC('a', 'u', 'd', 'c')

#define AVIF_HASINDEX 16
typedef struct _AVISTREAMINFOA {
    long	fccType;
    long	fccHandler;
    long	dwFlags;        /* AVIIF_* */
    long	dwCaps;
    short	wPriority;
    short	wLanguage;
    long	dwScale;
    long	dwRate;		/* dwRate / dwScale == samples/second */
    long	dwStart;
    long	dwLength;	/* In units above... */
    long	dwInitialFrames;
    long	dwSuggestedBufferSize;
    long	dwQuality;
    long	dwSampleSize;
    RECT	rcFrame;
    long	dwEditCount;
    long	dwFormatChangeCount;
    char	szName[64];
} AVISTREAMINFOA, * LPAVISTREAMINFOA, *PAVISTREAMINFOA;

typedef struct _AVISTREAMINFOW {
    long	fccType;
    long	fccHandler;
    long	dwFlags;
    long	dwCaps;
    short	wPriority;
    short	wLanguage;
    long	dwScale;
    long	dwRate;		/* dwRate / dwScale == samples/second */
    long	dwStart;
    long	dwLength;	/* In units above... */
    long	dwInitialFrames;
    long	dwSuggestedBufferSize;
    long	dwQuality;
    long	dwSampleSize;
    RECT	rcFrame;
    long	dwEditCount;
    long	dwFormatChangeCount;
    short	szName[64];
} AVISTREAMINFOW, * LPAVISTREAMINFOW, *PAVISTREAMINFOW;


typedef struct _AVIFILEINFOW {
    long               dwMaxBytesPerSec;
    long               dwFlags;
    long               dwCaps;
    long               dwStreams;
    long               dwSuggestedBufferSize;
    long               dwWidth;
    long               dwHeight;
    long               dwScale;        
    long               dwRate;
    long               dwLength;
    long               dwEditCount;
    short               szFileType[64];
} AVIFILEINFOW, * LPAVIFILEINFOW, *PAVIFILEINFOW;

typedef struct _AVIFILEINFOA {
    long               dwMaxBytesPerSec;
    long               dwFlags;
    long               dwCaps;
    long               dwStreams;
    long               dwSuggestedBufferSize;
    long               dwWidth;
    long               dwHeight;
    long               dwScale;        
    long               dwRate;
    long               dwLength;
    long               dwEditCount;
    char		szFileType[64];
} AVIFILEINFOA, * LPAVIFILEINFOA, *PAVIFILEINFOA;


typedef struct _avimainheader {
    FOURCC fcc;   // 必须为‘avih’
    DWORD  cb;    // 本数据结构的大小，不包括最初的8个字节（fcc和cb两个域）
    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;

typedef struct _avistreamheader {
     FOURCC fcc;  // 必须为‘strh’
     DWORD  cb;   // 本数据结构的大小，不包括最初的8个字节（fcc和cb两个域）
     FOURCC fccType;    // 流的类型：‘auds’（音频流）、‘vids’（视频流）、
                   //‘mids’（MIDI流）、‘txts’（文字流）
     FOURCC fccHandler; // 指定流的处理者，对于音视频来说就是解码器
     DWORD  dwFlags;    // 标记：是否允许这个流输出？调色板是否变化？
     DWORD  dwPriority;  // 流的优先级（当有多个相同类型的流时优先级最高的为默认流）
     DWORD  dwInitialFrames; // 为交互格式指定初始帧数
	 DWORD  dwScale;   // 这个流使用的时间尺度
     DWORD  dwRate;
     DWORD  dwStart;   // 流的开始时间
     DWORD  dwLength;  // 流的长度（单位与dwScale和dwRate的定义有关）
     DWORD  dwSuggestedBufferSize; // 读取这个流数据建议使用的缓存大小
     DWORD  dwQuality;    // 流数据的质量指标（0 ~ 10,000）
     DWORD  dwSampleSize; // Sample的大小
     struct {
         short int left;
         short int top;
         short int right;
         short int bottom;
	 }  rcFrame;  // 指定这个流（视频流或文字流）在视频主窗口中的显示位置
             // 视频主窗口由AVIMAINHEADER结构中的dwWidth和dwHeight决定
} AVISTREAMHEADER;


typedef struct {
    long	fccType;		/* stream type, for consistency */
    long	fccHandler;		/* compressor */
    long	dwKeyFrameEvery;	/* keyframe rate */
    long	dwQuality;		/* compress quality 0-10,000 */
    long	dwBytesPerSecond;	/* unsigned chars per second */
    long	dwFlags;		/* flags... see below */
    void*	lpFormat;		/* save format */
    long	cbFormat;
    void*	lpParms;		/* compressor options */
    long	cbParms;
    long	dwInterleaveEvery;	/* for non-video streams only */
} AVICOMPRESSOPTIONS, *LPAVICOMPRESSOPTIONS,*PAVICOMPRESSOPTIONS;



// FLAGS for dwFlags element of COMPVARS structure:

