Click here to Skip to main content
15,891,607 members
Articles / Desktop Programming / MFC
Article

A simple interface to the Video for Windows API for creating AVI movies from individual images

Rate me:
Please Sign up or sign in to vote.
3.54/5 (18 votes)
19 May 2003 215K   4.3K   68   38
A simple interface to the Video for Windows API for creating AVI movies from individual images.

Introduction

This article describes a simple interface to the Video for Windows API for creating AVI movies from individual images. The idea for this code comes from a Microsoft sample that was very unfriendly to use. With that in mind, I created this code to easily create an AVI from individual images.

The steps are:

  1. include "aviUtil.h".
  2. Call START_AVI("foo.avi"); // you must include the .avi extention.
  3. Call ADD_FRAME_FROM_DIB_TO_AVI(yourDIB, "DIB", 30); // the dib is passed in as a HANDLE which can be obtained by loading the image with a Image library. (I used CxImage which is available on this site). Put this call in a while or for loop to add all the images you want to the AVI.
  4. Call STOP_AVI(); //this closes the avi and video.

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


Written By
Web Developer
United States United States
I enjoy working with C#, Java, Perl and C++

Comments and Discussions

 
QuestionADD_FRAME_FROM_DIB_TO_AVI ? Pin
william_li15-Nov-04 19:49
william_li15-Nov-04 19:49 
QuestionADD_FRAME_FROM_ .. buffer? Pin
mound15-Jun-04 8:13
mound15-Jun-04 8:13 
AnswerRe: ADD_FRAME_FROM_ .. buffer? Pin
Rod VanAmburgh15-Jun-04 15:32
Rod VanAmburgh15-Jun-04 15:32 
GeneralRe: ADD_FRAME_FROM_ .. buffer? Pin
mound16-Jun-04 8:50
mound16-Jun-04 8:50 
GeneralRe: ADD_FRAME_FROM_ .. buffer? Pin
Rod VanAmburgh16-Jun-04 19:27
Rod VanAmburgh16-Jun-04 19:27 
GeneralRe: ADD_FRAME_FROM_ .. buffer? Pin
mound17-Jun-04 4:20
mound17-Jun-04 4:20 
GeneralRe: ADD_FRAME_FROM_ .. buffer? Pin
mound17-Jun-04 9:53
mound17-Jun-04 9:53 
GeneralRe: ADD_FRAME_FROM_ .. buffer? Pin
Rod VanAmburgh18-Jun-04 17:22
Rod VanAmburgh18-Jun-04 17:22 
CBitmap has a few quirks. For a sanity check try CBitmap::LoadBitmap( LPCTSTR lpszResourceName ) and see if your handle is valid.

Here is something ugly I had to do once. Notice how you must initialize CBitmap!

int w = 40;
int h = 80;
RECT rectC;
wnd->GetClientRect(&rectC);
CDC* wDc = wnd->GetDC();
CDC bitmapDc;
bitmapDc.CreateCompatibleDC(wDc);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(wDc, w, h);
CBitmap* oldBitmap = (CBitmap*) bitmapDc.SelectObject(&bitmap);
bitmapDc.StretchBlt(0, 0, w, h, wDc, 20, 315, w, h, SRCCOPY);

CxImage* img = new CxImage();
img->CreateFromHBITMAP((HBITMAP) bitmap);
//img->CreateFromHANDLE(hdib); // no
img->SetJpegQuality(255);
img->Save("foo.jpg", CXIMAGE_FORMAT_JPG);
delete img;


Smile | :) Rod
GeneralRe: ADD_FRAME_FROM_ .. buffer? Pin
mound22-Jun-04 8:03
mound22-Jun-04 8:03 
GeneralCXIMAGE to AVI... Pin
sherrinmultimedia20-Oct-03 3:57
sherrinmultimedia20-Oct-03 3:57 
GeneralRe: CXIMAGE to AVI... Pin
Ted Ferenc20-Oct-03 4:18
Ted Ferenc20-Oct-03 4:18 
GeneralRe: CXIMAGE to AVI... Pin
sherrinmultimedia20-Oct-03 4:48
sherrinmultimedia20-Oct-03 4:48 
GeneralRe: CXIMAGE to AVI... Pin
vanamburghrod@wmconnect.com20-Oct-03 15:57
sussvanamburghrod@wmconnect.com20-Oct-03 15:57 
GeneralRe: CXIMAGE to AVI... Pin
sherrinmultimedia21-Oct-03 2:42
sherrinmultimedia21-Oct-03 2:42 
GeneralRe: CXIMAGE to AVI... Pin
sherrinmultimedia21-Oct-03 3:36
sherrinmultimedia21-Oct-03 3:36 
GeneralRe: CXIMAGE to AVI... Pin
RoyalVN6-Apr-05 21:45
RoyalVN6-Apr-05 21:45 
GeneralAudio Pin
srinivas vaithianathan27-May-03 6:24
srinivas vaithianathan27-May-03 6:24 

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.