Click here to Skip to main content
Licence CPOL
First Posted 3 Jul 2004
Views 45,927
Downloads 2,052
Bookmarked 27 times

AVI2BMP

By | 3 Jul 2004 | Article
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Danila Markelov



Russian Federation Russian Federation

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionThanks Pinmemberzhishanw0:04 30 Jul '11  
QuestionHelp !!! PinmemberDinterinBebin5:31 29 Aug '07  
GeneralUpdated code PinmemberJArdussi8:03 11 Jul '07  
Generalalthough don't explain well, but it help me, thanks for share Pinmemberikohl2:59 8 Jul '07  
Generalerror while building PinmemberJohotech6:18 19 Jun '07  
When I tried buidling this project inVC++ ide, I got this linking problem
 
avi2bmp.obj : error LNK2019: unresolved external symbol ___security_cookie referenced in function _main
avi2bmp.obj : error LNK2019: unresolved external symbol @__security_check_cookie@4 referenced in function _main
avi2bmp.obj : error LNK2019: unresolved external symbol _memset referenced in function _main
LINK : error LNK2001: unresolved external symbol _WinMainA
./avi2bmp.exe : fatal error LNK1120: 4 unresolved externals
 
Cud you please guide me how to resolve this prb?
 
Thank u
GeneralRe: error while building PinmemberMember 876372423:35 26 Mar '12  
GeneralRe: error while building PinmemberMember 876372421:58 27 Mar '12  
Questionwhy? Pinmemberbyrz5:48 3 Jun '07  
GeneralHmmm PinmemberPatrik Svensson6:41 4 Jul '04  
GeneralRe: Hmmm PinmemberWREY11:18 4 Jul '04  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 4 Jul 2004
Article Copyright 2004 by Danila Markelov
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid