Visual C + + programming to implement camera video capture

Source: Internet
Author: User
Tags filter

Objective

DirectShow is a Microsoft-provided development package for streaming media processing on Windows platforms, published with the DirectX development package. DirectShow provides a powerful support for capturing and playback of multimedia streaming. Using DirectShow to develop the application, we can easily capture data from the acquisition card that supports the WDM drive model, and do the corresponding post-processing and even store it in the file.

DirectShow is COM based, and in order to write a DirectShow application, you need to understand the basics of COM client programming. DirectShow provides a large number of interfaces, but it is not easy to find in the programming, if you can build a video capture class to encapsulate some of the commonly used actions, then it is more convenient.

Programming Ideas

To make it easier to build a video capture application, DirectShow provides an object called Capture Graph builder, Capture graph Builder provides the IcaptureGraphBuilder2 interface, The interface can establish and control capture Graph.

To establish a video capture program, you must first obtain and initialize the IcaptureGraphBuilder2 interface, and then select an appropriate video capture device. After selecting a good device, create capture filter for the device, and then call AddFilter to add capture filter to filter Graph.

If you just want to use the camera for real-time monitoring, just call Icapturegraphbuilder2::renderstream on the above basis:

ICaptureGraphBuilder2 *pBuild; // Capture Graph Builder
//省略初始化部分代码
IBaseFilter *pCap; // Video capture filter.
//省略初始化和添加到Filter Graph部分代码
pBuild-> RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pCap, NULL, NULL);

DirectShow provides a way to capture a static image: Using the sample grabber filter. Follow these three steps in turn:

The first step is to define a class that implements the callback interface for sample grabber ISAMPLEGRABBERCB:

class CSampleGrabberCB : public ISampleGrabberCB
{
  //在后面提供的类中具体完成
}
CSampleGrabberCB mCB;

The second step, call Renderstream, in turn, still pin, Sample grabber and system default renderer filter are connected.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.