Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

AVI2BMP

0.00/5 (No votes)
3 Jul 2004 1  
Converter for AVI file to BMP file(s).

Introduction

This is a very small console program to convert video in AVI format into a BMP file or files. I guess that's all that I can tell about this program. Oh, one thing more. I use some pragma directives to reduce the size of the program. That's all.

Using the code

OK! In my program, I use the standard way to extract a frame from an AVI file and save it into a BMP file. There's nothing special or secret in it. Just the standard Win32 API and VFW API. That's all!

// Some steps:
char   AVIFileName[_SIZE]={0};
AVIFILE   aviFile;
PAVISTREAM  aviStream;
AVISTREAMINFO  aviStreamInfo;

AVIFileInit();
AVIFileOpen(&aviFile,AVIFileName,OF_READ,NULL);
AVIFileGetStream(aviFile,&aviStream,streamtypeVIDEO,0);
AVIFileRelease(aviFile);
AVIStreamInfo(aviStream,&aviStreamInfo,sizeof(aviStreamInfo));

// OK! Now we can extract any frame from AVI stream!

BITMAPFILEHEADER BMPFileHeader;
LPBITMAPINFOHEADER lpbi;
PGETFRAME  pgf;

pgf=AVIStreamGetFrameOpen(aviStream,NULL); 
lpbi=(LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf,fr);
BMPFileHeader.bfType=0x4d42;
BMPFileHeader.bfSize=(DWORD)(sizeof(BITMAPFILEHEADER)+lpbi->biSize+
  lpbi->biClrUsed*sizeof(RGBQUAD)+lpbi->biSizeImage);
BMPFileHeader.bfReserved1=0;
BMPFileHeader.bfReserved2=0;
BMPFileHeader.bfOffBits=(DWORD)sizeof(BITMAPFILEHEADER)+lpbi->biSize+
  lpbi->biClrUsed*sizeof(RGBQUAD);

// Than create file to save frame and write BMP sections into it!

WriteFile(hFile,(LPVOID)&BMPFileHeader,sizeof(BITMAPFILEHEADER),
  (LPDWORD)&lpNumberOfBytesWritten,NULL);
WriteFile(hFile,(LPVOID)lpbi,sizeof(BITMAPFILEHEADER)+lpbi->biSize+
  lpbi->biClrUsed*sizeof(RGBQUAD)+lpbi->biSizeImage,
  (LPDWORD)&lpNumberOfBytesWritten,NULL);

// And in the end make some clean!

AVIStreamGetFrameClose(pgf);

// We can save one more frame or finish or work.

AVIFileExit();

History

OK! I want to correct some error handlers, but may be next time.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here