65.9K
CodeProject is changing. Read more.
Home

AVI2BMP

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.88/5 (12 votes)

Jul 4, 2004

CPOL
viewsIcon

73262

downloadIcon

3059

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.