Click here to Skip to main content
11,934,443 members (55,717 online)
Click here to Skip to main content
Add your own
alternative version


167 bookmarked

CAviCap and CFrameGrabber - wrappers for AVICap Window

, 8 Dec 1999
Rate this:
Please Sign up or sign in to vote.
AVICap wrappers to ease real-time video processing and single frame capture
  • Download demo project - 77 Kb
  • Download source files - 17 Kb


    AVICap window class provides applications with a message-based interface to access video and waveform-audio acquisition hardware and to control the process of streaming video capture to disk. Unfortunately, it has a few serious limitations:

    • All of setup operations for format, source and video standard are implemented within driver dialogs.
    • Program control is complicated and without of any warranties of true results.
    • Capture conditions are strongly related to WM_VISIBLE flag of AVICap window.
    • There is no capability of window stretching.
    • Most of capture drivers have internal buffers queue (fifo), so they can't provide satisfactory time accuracy when user application needs to grab a single frame. They simply return last frame from buffers queue.

    In short, AVICap window is really good enough to control the process of streaming video capture to disk, but in most cases useless for real-time video processing. For resolving this problem, a wrapper for AVICap windows in order to work with real-time video was written. This class was initially described on CodeGuru. After this, i've received a lot of questions about AviCap class implementation and usage. I've understood that for those programmers who are not so familiar with VfW tricks, CAviCap class is not quite understandable and hence is not so useful. I will try to answer most frequent questions about CAviCap implementation in this article. Also, a new wrapper for AVIcap window will be presented. This class has a very simple interface and intended for programmers who is just starting to play with VfW.

    Video Capture Software Components

    Avicap32.dll exports capCreateCaptureWindow function which is used for creating AVICap window. Because capture drivers are fundamentally 16-bit DLLs, Avicap32.dll does not call capture driver indirectly. It translates drivers call to 16-bit Avicap.dll & mmsystem.dll which deal with capture drivers. Windows 98 also includes a software layer that translates VfW 1.1 interfaces into WDM video capture interfaces. This translation software works only for video capture devices on external busses (USB and 1394) in Windows 98. See additional information about USB and WDM under Windows 98 at

    One more way to capture gives DirectShow interface. It encapsulates standard AviCap window and also gives independent interface to WDM drivers for USB devices. See DirectShow SDK for more information.

    CAviCap class implementation.

    The CAviCap class provides the functionality of a AVICap window class, along with members for managing the window, excepting streaming operation. Internally, this class was implemented by usual for MFC way("dynamic subclass"). Most of public methods are helpers for WM_CAP_XXXX messaging, but a few methods give enhanced control for programmers. File "cavicap.h" contains all necessary functions descriptions.

    To use this class in your application:

    1. Create CAviCap class object.
    2. Call the Create member function to create an AVICap window. Note, if you will create invisible window, StartPreview method will not work, because AVICap disables control timer for hidden/minimized capture window. If you need invisible capture window, you must control the capture using GrabOneFrame member function.
    3. Call GetDriversList method to determine available drivers list.
    4. Call ConnectWithDriver method. According to m_DoQuickConnection flag, connections carries out with/without testing driver parameters. Usually, such testing can be very slow and also can "freeze" a driver not fully compatible with VfW 1.1. It seems to me, the best approach is to test driver once during software setup/installation.

      Note: Some drivers can splash Message box during testing. Also, the list of "public formats" from driver dialog can be appreciably different from list that you can get using EnumValidFrameSize method. This is a really strange fact, but, sometimes, it can be very useful.

    5. Set up required frame size and color resolution using SetFrameSize and SetBitResolution or with SetFormat methods.
    6. Install your own callback function using SetFrameCallBack if you need direct access to image data. Capture driver will call your function every time when new frame is captured in response to internal timer event or GrabOneFrame member function call. Driver passes a VIDEOHDR struct pointer to callback function. The struct member lpData point to image data buffer.
    7. Start preview using StartPreview for sequential capturing with interval defined by SetPreviewRate, or control the capture by just calling GrabOneFrame member function.

      See demo project "AviCapTest" for information about the usage of other methods.

    CFrameGrabber class implementation.

    This simple wrapper intended for single-frame capturing. Although, class does not support a lot of AVICap window functionality, such as file streaming, previewing, callback notification, it can be used for most application tasks.

    To use this class in your application:

    1. Create CFrameGrabber class object.
    2. Call the Create member function to create an AVICap window. By default, invisible child windows will be created, and connection with default capture driver will be established. Function returns "FALSE", if no capture driver found.
    3. If window is successfully created, object is ready to use.
    4. Call GetDIB member function to capture, get device-independent bitmap(DIB). It's possible to call GetImageBitsBuffer, which return image buffer pointer. In order to get a new image, call these functions after not less then 20 ms.
    5. You can determine current frame size and bits resolution with GetImageSize and GetImageBitsResolution member function.
    6. VideoFormatDialog and VideoSourceDialog allows to call standard driver dialogs.

    Demo programs

    Included are two demo programs in common workspace file. Projects were compiled and tested with MSVC++ 5.0 & 6.0. AviCapTest.exe uses CAviCap class for capturing and FrameGrabberTest.exe is based on FrameGrabber class. These demo programs connect with default capture driver installed on computer. Additionally, AviCapTest performs full testing of driver. Some of "standard" and "enhanced" commands of these classes are combined in menu. Both projects also include an examples of simple image processing.

  • 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


    About the Author

    Vadim Gorbatenko
    Russian Federation Russian Federation
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    Questioncapture video to an AVI file Pin
    EstherG13-Sep-08 22:02
    memberEstherG13-Sep-08 22:02 
    AnswerRe: capture video to an AVI file Pin
    Yavuz Sevgi29-Jul-09 3:07
    memberYavuz Sevgi29-Jul-09 3:07 
    QuestionHow to set capture resolution for AVICAP? Pin
    ja_pryor25-Sep-07 9:27
    memberja_pryor25-Sep-07 9:27 
    AnswerRe: How to set capture resolution for AVICAP? Pin
    IssaharNoam29-Sep-09 14:05
    memberIssaharNoam29-Sep-09 14:05 
    Generalblank screen Pin
    Raides6-May-07 8:57
    memberRaides6-May-07 8:57 
    GeneralRe: blank screen Pin
    lianaent29-Jun-07 13:03
    memberlianaent29-Jun-07 13:03 
    Questionusing and implementing my own class Pin
    fodwarning26-Apr-07 0:01
    memberfodwarning26-Apr-07 0:01 
    General8 bit images Pin
    galinzhelezov10-Mar-07 22:09
    membergalinzhelezov10-Mar-07 22:09 
    Generalheader file Pin
    Anoopqis7-Nov-06 18:44
    memberAnoopqis7-Nov-06 18:44 
    GeneralUsman Shabbir Pin
    Usman Shabbir10-Oct-06 22:43
    memberUsman Shabbir10-Oct-06 22:43 
    QuestionHow can I get the frame into a buffer from the network CAM (cam has a fixed address) Pin
    SuryaAki19-Sep-06 7:01
    memberSuryaAki19-Sep-06 7:01 
    GeneralI want capture real time Pin
    iran_mehdi9-Jun-06 22:43
    memberiran_mehdi9-Jun-06 22:43 
    GeneralBug fix & error report Pin
    c++guy18-Apr-06 18:55
    memberc++guy18-Apr-06 18:55 
    GeneralQuestions about CAviCap!!! help, help!! Pin
    pengzhangjie5-Mar-06 21:00
    memberpengzhangjie5-Mar-06 21:00 
    QuestionHow can I grab a frame Pin
    Vincent Richomme6-Sep-05 5:55
    memberVincent Richomme6-Sep-05 5:55 
    Generalplease , i have an error in dshow.h Pin
    dynamica12330-Aug-05 1:37
    memberdynamica12330-Aug-05 1:37 
    GeneralCreate a Thread in VC++ Pin
    Kirubanandam23-Aug-05 4:41
    memberKirubanandam23-Aug-05 4:41 
    QuestionHow to use thread in VC++? Pin
    Kirubanandam23-Aug-05 4:38
    memberKirubanandam23-Aug-05 4:38 
    GeneralProblem with shutting down the application that use CAviCap (under XP) Pin
    Babayaro4-May-05 5:34
    sussBabayaro4-May-05 5:34 
    Generalvideo combining Pin
    Anonymous13-Feb-05 20:25
    sussAnonymous13-Feb-05 20:25 
    GeneralCallBack function stops getting called when Video Preview Window fully hidden or minimized Pin
    gbessens3-Nov-04 7:52
    membergbessens3-Nov-04 7:52 
    GeneralThanks Pin
    Trollslayer29-Apr-04 0:50
    memberTrollslayer29-Apr-04 0:50 
    GeneralGuidance Pin
    Chivalrous13-Apr-04 20:29
    memberChivalrous13-Apr-04 20:29 
    GeneralGetting Live Stream from Cam In MFC Pin
    itsharis99913-Apr-04 12:21
    sussitsharis99913-Apr-04 12:21 
    GeneralDirectShow utilisation Pin
    fruzzy29-Mar-04 6:55
    sussfruzzy29-Mar-04 6:55 
    GeneralRe: DirectShow utilisation Pin
    Anonymous2-Oct-04 0:18
    sussAnonymous2-Oct-04 0:18 
    GeneralRe: DirectShow utilisation Pin
    EmoBemo9-Dec-09 5:47
    memberEmoBemo9-Dec-09 5:47 
    GeneralFlickering Pin
    hurr1can310-Mar-04 11:01
    memberhurr1can310-Mar-04 11:01 
    QuestionHow to select wavein device? Pin
    tang_zibo1-Feb-04 3:05
    membertang_zibo1-Feb-04 3:05 
    GeneralMCIWndCreate error Pin
    George Dum15-Jan-04 5:59
    sussGeorge Dum15-Jan-04 5:59 
    Questionhow to transfort the captured images through network ? Pin
    msh490923-Dec-03 7:15
    membermsh490923-Dec-03 7:15 
    GeneralExtracting JPEG stream Pin
    Ivoryping27-Jul-03 22:17
    memberIvoryping27-Jul-03 22:17 
    GeneralMouse event on Video Window Pin
    chamana25-Jul-03 17:05
    memberchamana25-Jul-03 17:05 
    GeneralRe: Mouse event on Video Window Pin
    alpy6-Feb-06 5:02
    memberalpy6-Feb-06 5:02 
    GeneralMulti-Cam Pin
    Gabbad7-Jul-03 10:31
    memberGabbad7-Jul-03 10:31 
    Questionhow can i add the bitmap and opengl on the video file Pin
    muhammad fahad4-Jul-03 16:28
    membermuhammad fahad4-Jul-03 16:28 
    AnswerRe: how can i add the bitmap and opengl on the video file Pin
    Atif Bashir3-Sep-03 2:06
    memberAtif Bashir3-Sep-03 2:06 
    Questionhow can i add the bitmap on the video file Pin
    muhammad fahad4-Jul-03 16:24
    membermuhammad fahad4-Jul-03 16:24 
    Generalcamera gets switched off while the window is dragged Pin
    barby21-Jun-03 20:28
    memberbarby21-Jun-03 20:28 
    Generalsaving video capture Pin
    barby19-Jun-03 23:33
    memberbarby19-Jun-03 23:33 
    GeneralRe: saving video capture Pin
    Atif Bashir3-Sep-03 1:58
    memberAtif Bashir3-Sep-03 1:58 
    GeneralRe: saving video capture Pin
    svsatish_se24-Feb-06 4:22
    membersvsatish_se24-Feb-06 4:22 
    Generalcrash Pin
    alan9318-May-03 10:34
    memberalan9318-May-03 10:34 
    GeneralRe: crash Pin
    alan9318-May-03 10:37
    memberalan9318-May-03 10:37 
    GeneralGet video from camera Pin
    amiraklim25-Apr-03 12:46
    memberamiraklim25-Apr-03 12:46 
    QuestionHow Can I find code/help to convert 12-bit raw RGB to YUV Format? Pin
    Atif Bashir1-Apr-03 5:07
    memberAtif Bashir1-Apr-03 5:07 
    QuestionHow can I get video frames streaming in RGB(Raw Format) from USB camera ? Pin
    RennyAshay12-Mar-03 2:23
    memberRennyAshay12-Mar-03 2:23 
    AnswerRe: How can I get video frames streaming in RGB(Raw Format) from USB camera ? Pin
    Atif Bashir3-Sep-03 2:09
    memberAtif Bashir3-Sep-03 2:09 
    QuestionHow can I get video frames streaming in RGB(Raw Format) from USB camera ? Pin
    RennyAshay12-Mar-03 2:22
    memberRennyAshay12-Mar-03 2:22 
    GeneralSave as AVI file Pin
    johnnyrabb12-Feb-03 2:37
    memberjohnnyrabb12-Feb-03 2:37 

    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.

    | Advertise | Privacy | Terms of Use | Mobile
    Web04 | 2.8.151126.1 | Last Updated 9 Dec 1999
    Article Copyright 1999 by Vadim Gorbatenko
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid