1
我需要一些帮助创建一个AVI文件的位图。 问题是,在最后我得到一个损坏的AVI文件。如果我有一个HEX_Editor 整个AVI标头为0 ...Bitmaps to Avi使用视频的Windows,C
读它,我使用Borland C++ Builder的6和64位Windows 7
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,或者如果我使用的funcions是正确的......
PS:这是我的第一篇文章在这里,如果你需要更多的信息,请让我知道!
在您的代码中,您关闭了该文件,并且我认为您将再次打开该文件。当您重新打开该文件时,是否可以检查是否以O_APPEND模式而不是O_WRITE模式打开? – Ganesh 2013-02-11 17:13:17
嘿,谢谢你的回复!你的意思是哪个文件? “FileSource”在写入流后关闭文件并转到目录“DirSource”中的下一个位图后,读取位图(Headers和Data)。我打开每个位图,如下所示: FileSource = fopen(sourcepathbuffer,“rb”) “sourcepathbuffer”包含路径和文件名称 – Cittles 2013-02-12 09:15:02
您正逐帧将BMP写入AVIStream。我的问题与流有关。你关闭并重新打开流?如果是这样,请在'O_APPEND'模式下打开'AVI'流。 – Ganesh 2013-02-12 16:31:48