我需要一些帮助来创建位图的 avi 文件。问题是最后我得到了一个损坏的 avi 文件。如果我用 HEX_Editor 阅读它,整个 avi 标题是 0...
我使用 Borland C++ Builder 6 和 Windows 7 64bit
AVIINFO 结构:
typedef struct
{
PAVISTREAM aviStream;
PAVISTREAM aviStreamCompressed;
PAVIFILE aviFile;
AVISTREAMINFO avistInfo;
AVICOMPRESSOPTIONS avistComprOpts;
unsigned long framenumber; // which frame will be added next
} AVIINFO, *PAVIINFO;
pstBmpInfo 已经像这样填充了:
biSize = 40
biWidth = 800
biHeight = 600
biPlanes = 1
biBitcount = 24
biSizeImage = 1440000
others are 0
int initAvi(AVIINFO *aviInfo, BMPINFOHEADER *pstBmpInfo)
{
/* AVIFile Library initialisieren */
AVIFileInit();
/* File erstellen */
if (AVIFileOpen(&(aviInfo->aviFile), "avistream.avi", OF_CREATE|OF_WRITE, NULL) != 0)
{
printf("Error creating AVIFile...\n%s\n", strerror(errno));
return -1;
}
memset(&(aviInfo->avistInfo), 0, sizeof(aviInfo->avistInfo));
memset(&(aviInfo->avistComprOpts), 0, sizeof(aviInfo->avistComprOpts));
/* AVISTREAMINFO Optionen setzen */
aviInfo->avistInfo.fccType = streamtypeVIDEO;
aviInfo->avistInfo.fccHandler = mmioFOURCC('M','S','V','C');
aviInfo->avistInfo.dwRate = STREAM_FPS; // 10
aviInfo->avistInfo.dwScale = 1;
aviInfo->avistInfo.dwSuggestedBufferSize = pstBmpInfo->biSizeImage;
aviInfo->avistInfo.rcFrame.bottom = pstBmpInfo->biHeight;
aviInfo->avistInfo.rcFrame.right = pstBmpInfo->biWidth;
aviInfo->avistInfo.dwQuality = -1; // default quality
/* Stream erstellen */
if (AVIFileCreateStream(aviInfo->aviFile ,&(aviInfo->aviStream), &(aviInfo->avistInfo)) != 0)
{
printf("Error creating Stream...\nErrorcode: %s\n", strerror(errno));
return -1;
}
/* AVICOMPRESSOPTIONS Optionen setzen */
aviInfo->avistComprOpts.fccType = streamtypeVIDEO;
aviInfo->avistComprOpts.fccHandler = mmioFOURCC('M','S','V','C');
/* */
if (AVIMakeCompressedStream(&(aviInfo->aviStreamCompressed), aviInfo->aviStream,
&(aviInfo->avistComprOpts), NULL) != AVIERR_OK)
{
printf("Error creating compressed Stream...\nErrorcode: %s\n", strerror(errno));
return -1;
}
/* Streamformat für Bitmaps */
if (AVIStreamSetFormat(aviInfo->aviStreamCompressed, 0, pstBmpInfo, sizeof(*pstBmpInfo)) != 0)
{
printf("Error setting new Streamformat...\nErrorcode: %s\n", strerror(errno));
return -1;
}
aviInfo->framenumber = 0;
return 0;
}
这就是我写入文件的方式:
pucBitmapDataBuffer 保存 Bitmapdata
.
.
.
.
if ((AVIStreamWrite(aviInfo->aviStreamCompressed, aviInfo->framenumber, 1, pucBitmapDataBuffer,
sizeof(pucBitmapDataBuffer), AVIIF_KEYFRAME, NULL, NULL)) != 0)
{
streamErrorCnt++;
printf("Could not write Data to Stream...\n%s", strerror(errno));
aviInfo->framenumber++;
free(pucBitmapDataBuffer);
fclose(FileSource);
stDirEp = readdir(DirSource);
continue; // get next BMP
}
else
{
streamErrorCnt = 0;
aviInfo->framenumber++;
}
.
.
.
.
我不知道如何填写 AVICOMPRESSOPTIONS,或者我使用的功能是否正确......
PS:这是我在这里的第一篇文章,如果您需要更多信息,请告诉我!