【问题标题】:Bitmaps to Avi using Video for Windows, C位图到 Avi 使用 Video for Windows, C
【发布时间】:2013-02-11 16:53:14
【问题描述】:

我需要一些帮助来创建位图的 avi 文件。 问题是最后我得到了一个损坏的 avi 文件。如果我用 HEX_Editor 阅读它 整个 avi Header 为 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:这是我的第一篇文章,如果您需要更多信息,请告诉我!

【问题讨论】:

  • 在您的代码中,您关闭了文件,我认为您正在重新打开文件。当您重新打开文件时,您是否可以检查您是否以 O_APPEND 模式而不是 O_WRITE 模式打开?
  • 嘿,谢谢你的回复!你指的是哪个文件? “FileSource”读取位图(包括标题和数据),在将其写入流后,我关闭文件并转到目录“DirSource”中的下一个位图。我像这样打开每个位图: FileSource = fopen(sourcepathbuffer, "rb") "sourcepathbuffer" contains the Path and Filename
  • 您正在逐帧将 BMP 写入 AVIStream。我的问题与流有关。您是否关闭并重新打开流?如果是这样,请在O_APPEND模式下打开AVI流。
  • 不,我只在程序退出时发生错误时关闭流,然后使用 AVIStreamRelease() 关闭它。此外,我找不到任何功能或标志来以 O_APPEND 模式打开流..

标签: c windows bitmap video-streaming avi


【解决方案1】:

前段时间,但这里是解决方案:

如果流式传输完成,您必须使用 AVIStreamRelease() 关闭 Stream。 只有这样 Header 才会生成并写入文件。

【讨论】:

    猜你喜欢
    • 2015-07-01
    • 2012-11-24
    • 1970-01-01
    • 2013-05-12
    • 2012-02-05
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多