有对AVI文件了解的吗?该怎么处理

有对AVI文件了解的吗?
我把音频数据保存成AVI文件,文件信息头都写了,
KMPlay能播放(但时间没走动,时间滚动轴也没动,可是声音能正常播放),暴风影音播放不了(注:只要格式没错暴风影音就能播放)

这种现象有可能是什么原因呢?

主要代码如下:一个是信息头,一个是写数据

有些参数怎么确定

C/C++ code


//音频头
int add_audio_stream_header(unsigned char *hdr)
{
    unsigned int video_fourcc;

    video_fourcc = FOURCC("U   ");

    PUT_32(hdr, FOURCC("LIST"));
    PUT_32(hdr + 4, 12 - 8 + 64 + 26); //(12-LIST -大小) + strh(56+8) +strf(8+56) + strf(8+)
    PUT_32(hdr + 8, FOURCC("strl"));

    //strh
    PUT_32(hdr + 12, FOURCC("strh"));         
    PUT_32(hdr + 12 + 4, 64 - 8);             //本结构的大小
    PUT_32(hdr + 12 + 8, FOURCC("auds"));     //数据种类
    PUT_32(hdr + 12 + 12, video_fourcc);      //音频加码驱动代号 或 1 
    PUT_32(hdr + 12 + 28, 1);                 //数据量,音频采样大小   和 采样数 的比率会影响音频
    PUT_32(hdr + 12 + 32, 48000<< 2);         //采样数
    PUT_32(hdr + 12 + 40, /*abytes>> 2*/ avi_frame_count);            //数据流的数量 
    PUT_32(hdr + 12 + 44, 48000 << 1);             //建议缓冲区的大小
    PUT_32(hdr + 12 + 52, 1);                      //音频采样大小 

    //strf
    PUT_32(hdr + 12 + 64, FOURCC("strf")); 
    PUT_32(hdr + 12 + 64 + 4, 26 - 8);                    // ? 24 ???  
    PUT_16(hdr + 12 + 64 + 8, 85);                        //音解码驱动代号 有影响
    PUT_16(hdr + 12 + 64 + 10, 2);                        //声道数
    PUT_32(hdr + 12 + 64 + 12, 4);                                        //采样率
    PUT_32(hdr + 12 + 64 + 16, 19200/*AVI_AUDIO_SAMPLE << 2*/);             //WAVE声音中每秒的数据量 
    PUT_16(hdr + 12 + 64 + 20, 1/*4*/);                    //数据块的对齐标志
    PUT_16(hdr + 12 + 64 + 22, 16);                        //此结构的大小 16
    return 12 + 64 + 26;
}

//写数据
void write_frame(unsigned char *data, int length, unsigned int fourcc, int key) //2
{
    unsigned char hdr[16];
    unsigned int offset;

    if( NULL == avifd )
        return;
    
    /* Write the AVI index record */     //索引    
         PUT_32(hdr, fourcc);
    PUT_32(hdr + 4, key ? 0x10 : 0);

    //offset = fseek(avifd, 0, SEEK_CUR);  //
    //@@@@
    fseek(avifd, 0, SEEK_CUR);
    offset = ftell(avifd); 
    //@@@@

    PUT_32(hdr + 8, offset - 1024 - 8);  //offset = 当前文件的位置
    PUT_32(hdr + 12, length);

    fwrite( hdr, 1, 16,idxfd );          //写索引

    /* Write the frame data to the AVI file */

    PUT_32(hdr + 4, length);
    fwrite( hdr, 1, 8,avifd );
    fwrite( data, 1, (length + 1) & ~0x1 ,avifd );/* word-align with junk */ //zhengshu bei

}




------解决方案--------------------
是不是文件格式没对,还是信息不全

找些avi格式资料看看

http://www.xici.net/b571992/d31844976.htm
------解决方案--------------------
不懂,友情帮顶
------解决方案--------------------
应该还要在文件尾写index吧
------解决方案--------------------
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;