Video For Windows Wrapper Class (CVFWImageProcessor)

Performs DIB video capture to memory with or without preview mode.

.

Environment: VC6, NT, W2K, Win98, Win95.

One of the main reasons why I wrote this class was to simplify the process of capturing images from a Video For Windows camera device. The Platform SDK Video for Windows (VFW) API did not seem to adequately document the VFW functions in the way that I wanted to implement them. My goal was to capture images from a capture device into a memory DIB. The VFW functions only seemed to be geared around saving captured images directly to disk. I wanted to be able to run image diagnostics on the captured contents without having to reload it from disk after the capture (very inneficient). I also did not want to deal with preview mode and trying to capture from that interface.

Microsoft did not appear to have built an MFC class around the VFW APIs. Instead, they chose to only utilize COM under the Windows Media Technologies to interface to VFW. So, I thought that I would try to develop a simplified class to the VFW APIs. The result is the CVFWImageProcessor class.

VFW APIs utilize a window handle as the point of reference for most of its functions which I encapsulated in the class. Most VFW API calls are dispatched under the windows message queue. In order to capture the DIB to memory instead of to disk, I decided to create a seperate thread that would be used to dispatch VFW message. This would allow me to syncronize the VFW callback functions without relying on the main message queue of my windows appliation.

Most of the work in the CVFWImageProcessor class focusses around the simplification of memory DIB capture. I added some additional member functions as wrappers around already existing VFW APIs. I did not incorporate all VFW APIs, just the ones that I thought were important for my application. I am sure that others may want to add or modify these members.

All of the testing that I performed was with Webcams that had no on-board compression. I am not sure how devices with built-in compression would function under this implementation.

Note that preview mode does not have to be active in order to capture a DIB to memory.

The download package includes a sample windows dialog application that shows how to use some of the features of the class.

I am well aware that there are probably ways that this class can be improved. My main goal was to illustrate a method for doing memory DIB captures with an easy to use class interface.

// Sample source on implemented CVFWImageProcessor class 
// to capture a single DIB frame to memory.

CVFWImageProcessor VFWProc;
PBITMAPINFO pBitmap;
ULONG BitmapSize;

VFWProc.Initialize(); // Intialize first found VFW device.

pBitmap = NULL; // CaptureDIB will automatically 
                // allocate this if it is set to NULL.

// Capture an image from the capture device.
if (VFWProc.CaptureDIB(&pBitmap, 0, &BitmapSize))
{
  // pBitmap captured successfully. Do whatever with it.

  delete pBitmap;    // Delete it when done.
}

VFWProc.Destroy();   // Done using VFW object.

UPDATES - August 29, 2001

The following changes were made:

  1. Removed DebugRelease configuration. This had a reference to GEAR32PD.LIB which is not used by the project.
  2. Removed all commented out sections concerning JPEG capture. JPEG capture is only available when I used the ImageGear package from AccuSoft which I could not redistribute. It was commented out, but was causing some confusion. So I removed it altogether.
  3. Corrected a lockup problem when using functions CVFWImageProcessor::DlgVideoDisplay(), CVFWImageProcessor::DlgVideoFormat(), and CVFWImageProcessor::DlgVideoSource().

Downloads

Download demo project - 19 Kb


About the Author

Ken Varn

Currently developing Digital Video Recorder software for security surveilance under Windows using Visual C++ C#, and Microsoft .NET Framework.

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Email is the most common communication vehicle used by organizations of all shapes and sizes. Among the billions of email messages sent every day are sensitive information, critical requests, and other essential business data. IT staff bear the burden of ensuring the confidentiality, integrity, and availability of the information contained within the communication. This white paper explores the email security landscape, an assessment of the threats organizations face,  and the building blocks of an effective …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds