Extract data collected in DirectShow.

xiaoxiao2021-03-05  26

Data flow (Data Flow) flows throughout the filter. It has its own method for the management of the data, and does not provide a unified interface for the user to operate the data stream. Here to extract video capture Each frame is bitmap data as an example to talk about how data is extracted in DirectShow.

Here we use DirectShow to provide us interface isamplegrabber, and define a CSAMpleGRabbercb object for it to call back (inherited the IsampleGRabbercb interface).

We know that data storage in DirectShow is done by SAMPLE, so extracting data also needs to pass by Samplegrabber.

Proceed as follows:

1. Establish a CSAMPLEGRABBERCB object.

Class Csamplegrabbercb: public isamplegrabbercb {

STDMETHODIMP BUFFERCB (Double Dblsampletime, Byte * PBuffer, long lbuffersize)

{

// Callback Method That Receives A Pointer to The Sample Buffer.

}

STDMETHODIMP SAMPLECB (Double Sampletime, IMEDIASAMPLE * PSAMPLE) {// Callback Method That Receives A Pointer To The Media Sample.}

}

2. Define the ISAMPLEGRABBER interface and initialize

CCIMPTR m_pgrabber;

HRESULT HR;

HR = m_pgrabber.coCreateInstance (CLSID_SAMPLEGRABBER);

IF (Failed (HR))

// error Action;

3. Define the grabber filter, set its media type, and add it to Graph

CCOMQIPTR PGRABBASE (M_PGRABBER);

CMEDiatype.Settype; VIDETYPE.SETTYPE (& MediaType_Video); VideoType.setSubtype (& MediaSubType_RGB24); hr = m_pgrabber-> setMediaType (& video);

HR = pgraph-> addfilter (pgrabbase, l "grabber);

4. Set the callback to enable the Grabber to automatically complete the acquisition data through BufferCB.

// don't buffer the samples as the pass through // hr = m_pgrabber-> setBuffersamples (false);

// ONLY GRAB One At A Time, Stop StreamAfter // Grabbing One Sample // HR = M_PGRABBER-> SetOnShot (false);

// set the callback, so we can grab the one sample // hr = m_pgrabber-> setCallback (& ​​MCB, 1); // MCB is CSAMPLEGRABBER object

Thus, during the DirectShow data flow, MCB. ButffB will automatically execute and extract data in Graph.

转载请注明原文地址:https://www.9cbs.com/read-34871.html

New Post(0)