Click here to Skip to main content
15,890,741 members
Articles / Desktop Programming / MFC

AVI2BMP

Rate me:
Please Sign up or sign in to vote.
1.88/5 (16 votes)
3 Jul 2004CPOL 72.6K   3.1K   29   10
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!

C++
// 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThanks Pin
zhishanw30-Jul-11 0:04
zhishanw30-Jul-11 0:04 
QuestionHelp !!! Pin
DinterinBebin29-Aug-07 5:31
DinterinBebin29-Aug-07 5:31 
GeneralUpdated code Pin
JArdussi11-Jul-07 8:03
JArdussi11-Jul-07 8:03 
Generalalthough don't explain well, but it help me, thanks for share Pin
ikohl8-Jul-07 2:59
ikohl8-Jul-07 2:59 
Generalerror while building Pin
Johotech19-Jun-07 6:18
Johotech19-Jun-07 6:18 
GeneralRe: error while building Pin
Member 876372426-Mar-12 23:35
Member 876372426-Mar-12 23:35 
GeneralRe: error while building Pin
Member 876372427-Mar-12 21:58
Member 876372427-Mar-12 21:58 
Questionwhy? Pin
byrz3-Jun-07 5:48
byrz3-Jun-07 5:48 
GeneralHmmm Pin
Patrik Svensson4-Jul-04 6:41
Patrik Svensson4-Jul-04 6:41 
GeneralRe: Hmmm Pin
WREY4-Jul-04 11:18
WREY4-Jul-04 11:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.