Click here to Skip to main content
15,867,832 members
Articles / Desktop Programming / MFC
Article

CAviCap and CFrameGrabber - wrappers for AVICap Window

Rate me:
Please Sign up or sign in to vote.
4.86/5 (55 votes)
8 Dec 1999 624.8K   19K   168   126
AVICap wrappers to ease real-time video processing and single frame capture
  • Download demo project - 77 Kb
  • Download source files - 17 Kb

    Introduction

    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 http://support.microsoft.com/support/kb/articles/Q192/1/12.ASP.

    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


    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

     
    Questioncapture video to an AVI file Pin
    EstherG13-Sep-08 21:02
    EstherG13-Sep-08 21:02 
    AnswerRe: capture video to an AVI file Pin
    Yavuz Sevgi29-Jul-09 2:07
    Yavuz Sevgi29-Jul-09 2:07 
    QuestionHow to set capture resolution for AVICAP? Pin
    ja_pryor25-Sep-07 8:27
    ja_pryor25-Sep-07 8:27 
    AnswerRe: How to set capture resolution for AVICAP? Pin
    IssaharNoam29-Sep-09 13:05
    IssaharNoam29-Sep-09 13:05 
    Generalblank screen Pin
    Raides6-May-07 7:57
    Raides6-May-07 7:57 
    GeneralRe: blank screen Pin
    lianaent29-Jun-07 12:03
    lianaent29-Jun-07 12:03 
    Questionusing and implementing my own class Pin
    fodwarning25-Apr-07 23:01
    fodwarning25-Apr-07 23:01 
    General8 bit images Pin
    galinzhelezov10-Mar-07 21:09
    galinzhelezov10-Mar-07 21:09 
    Generalheader file Pin
    Anoopqis7-Nov-06 17:44
    Anoopqis7-Nov-06 17:44 
    GeneralUsman Shabbir Pin
    Usman Shabbir10-Oct-06 21:43
    Usman Shabbir10-Oct-06 21:43 
    QuestionHow can I get the frame into a buffer from the network CAM (cam has a fixed address) Pin
    SuryaAki19-Sep-06 6:01
    SuryaAki19-Sep-06 6:01 
    GeneralI want capture real time Pin
    iran_mehdi9-Jun-06 21:43
    iran_mehdi9-Jun-06 21:43 
    GeneralBug fix & error report Pin
    c++guy18-Apr-06 17:55
    c++guy18-Apr-06 17:55 
    GeneralQuestions about CAviCap!!! help, help!! Pin
    pengzhangjie5-Mar-06 20:00
    pengzhangjie5-Mar-06 20:00 
    QuestionHow can I grab a frame Pin
    Vincent Richomme6-Sep-05 4:55
    Vincent Richomme6-Sep-05 4:55 
    Generalplease , i have an error in dshow.h Pin
    dynamica12330-Aug-05 0:37
    dynamica12330-Aug-05 0:37 
    GeneralCreate a Thread in VC++ Pin
    Kirubanandam23-Aug-05 3:41
    Kirubanandam23-Aug-05 3:41 
    QuestionHow to use thread in VC++? Pin
    Kirubanandam23-Aug-05 3:38
    Kirubanandam23-Aug-05 3:38 
    GeneralProblem with shutting down the application that use CAviCap (under XP) Pin
    bzukovic4-May-05 4:34
    bzukovic4-May-05 4:34 
    Generalvideo combining Pin
    Anonymous13-Feb-05 19:25
    Anonymous13-Feb-05 19:25 
    GeneralCallBack function stops getting called when Video Preview Window fully hidden or minimized Pin
    gbessens3-Nov-04 6:52
    gbessens3-Nov-04 6:52 
    GeneralThanks Pin
    Trollslayer28-Apr-04 23:50
    mentorTrollslayer28-Apr-04 23:50 
    GeneralGuidance Pin
    Chivalrous13-Apr-04 19:29
    Chivalrous13-Apr-04 19:29 
    GeneralGetting Live Stream from Cam In MFC Pin
    muhammadharis13-Apr-04 11:21
    muhammadharis13-Apr-04 11:21 
    GeneralDirectShow utilisation Pin
    fruzzy29-Mar-04 5:55
    fruzzy29-Mar-04 5:55 

    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.