Question

I need some help creating an avi File out of Bitmaps. The Problem is that in the End i get a corrupted avi File. If I read it with a HEX_Editor the whole avi Header is 0...

I use Borland C++ Builder 6 and Windows 7 64bit

AVIINFO Struct:

typedef struct
{
  PAVISTREAM aviStream;
  PAVISTREAM aviStreamCompressed;
  PAVIFILE aviFile;
  AVISTREAMINFO avistInfo;
  AVICOMPRESSOPTIONS avistComprOpts;
  unsigned long framenumber;    // which frame will be added next
} AVIINFO, *PAVIINFO;

pstBmpInfo is already filled like this:

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;
}

this is how I write to the File:

pucBitmapDataBuffer keeps the 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++;
                }
.
.
.
.

I don't know exactly how to fill the AVICOMPRESSOPTIONS, or if the funcions I'm using are correct...

PS: This my first Post here, if u need more Information please let me know!

Was it helpful?

Solution

Some time ago, but here is the solution:

If streaming is finished, you have to close the Stream by using AVIStreamRelease(). Only then the Header will be generated and written to the File.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top