Click here to Skip to main content
Click here to Skip to main content

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

    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

    Share

    About the Author

    Vadim Gorbatenko

    Russian Federation Russian Federation
    No Biography provided

    Comments and Discussions

     
    Questioncapture video to an AVI file PinmemberEstherG13-Sep-08 22:02 
    AnswerRe: capture video to an AVI file PinmemberYavuz Sevgi29-Jul-09 3:07 
    QuestionHow to set capture resolution for AVICAP? Pinmemberja_pryor25-Sep-07 9:27 
    AnswerRe: How to set capture resolution for AVICAP? PinmemberIssaharNoam29-Sep-09 14:05 
    Generalblank screen PinmemberRaides6-May-07 8:57 
    GeneralRe: blank screen Pinmemberlianaent29-Jun-07 13:03 
    Questionusing and implementing my own class Pinmemberfodwarning26-Apr-07 0:01 
    General8 bit images Pinmembergalinzhelezov10-Mar-07 22:09 
    Generalheader file PinmemberAnoopqis7-Nov-06 18:44 
    GeneralUsman Shabbir PinmemberUsman Shabbir10-Oct-06 22:43 
    QuestionHow can I get the frame into a buffer from the network CAM (cam has a fixed address) PinmemberSuryaAki19-Sep-06 7:01 
    GeneralI want capture real time Pinmemberiran_mehdi9-Jun-06 22:43 
    GeneralBug fix & error report Pinmemberc++guy18-Apr-06 18:55 
    GeneralQuestions about CAviCap!!! help, help!! Pinmemberpengzhangjie5-Mar-06 21:00 
    QuestionHow can I grab a frame PinmemberVincent Richomme6-Sep-05 5:55 
    Generalplease , i have an error in dshow.h Pinmemberdynamica12330-Aug-05 1:37 
    GeneralCreate a Thread in VC++ PinmemberKirubanandam23-Aug-05 4:41 
    QuestionHow to use thread in VC++? PinmemberKirubanandam23-Aug-05 4:38 
    GeneralProblem with shutting down the application that use CAviCap (under XP) PinsussBabayaro4-May-05 5:34 
    Generalvideo combining PinsussAnonymous13-Feb-05 20:25 
    GeneralCallBack function stops getting called when Video Preview Window fully hidden or minimized Pinmembergbessens3-Nov-04 7:52 
    GeneralThanks PinmemberTrollslayer29-Apr-04 0:50 
    GeneralGuidance PinmemberChivalrous13-Apr-04 20:29 
    GeneralGetting Live Stream from Cam In MFC Pinsussitsharis99913-Apr-04 12:21 
    GeneralDirectShow utilisation Pinsussfruzzy29-Mar-04 6:55 

    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.

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