Video data collection can be divided into four steps:
1. Create a capture graph builder and a filter graph manager to associate the two.
2. Create a filter and add it to graph.
3. Connect Filter Based on media type and other information.
4. Run graph.
Ccomptr <icapturegraphbuilder2> pcapture; <br/> ccomptr <igraphbuilder> pgb; <br/> ccomptr <imediacontrol> PMC; <br/> ccomptr <imediaevent> PME; </P> <p> ccomptr <ibasefilter> psource; <br/> ccomptr <ibasefilter> Prender; <br/> ccomptr <ibasefilter> pdecompressor; </P> <p> // 1. Create the capture graph builder and filter graph manager, and associate the two. // <br/> cocreateinstance (<br/> clsid_capturegraphbuilder2, null, <br/> clsctx_inproc_server, iid_icapturegraphbuilder2, <br/> (void **) & pcapture. p); </P> <p> cocreateinstance (clsid_filtergraph, 0, clsctx_inproc_server, <br/> iid_igraphbuilder, (void **) & pgb. p); </P> <p> pcapture-> setfiltergraph (pgb); </P> <p> // 2. Create a filter, and add it to graph /////////////////////////////////// /</P> <p> // step 1, find the collection device, create a source filter <br/> // implement it in the findcapture function <br/> // you can find it by using the system enumerator enumeration, filter Mapper, CLSID, and other methods <br/> findcapture (psource ); </P> <p> // step 2, create a render filter <br/> // class cmyrender to implement the render filter <br/> // This class can be used to write Video data to the process shared space for other processes <br/> // You can also write Video data to a file, and so on <br/> cmyrender * pmyrender = new cmyrender (); <br/> Prender = pmyrender; </P> <p> // step 3, create a translate filter <br/> // This is an interface provided by DirectShow <br/> // if the video data is in YUV format, you need to use this class <br/> cocreateinstance (<br/> clsid_avidec, null, clsctx_inproc, <br/> iid_ibasefilter, (void **) & (pdecompressor. p); </P> <p> // Step 4: add the three filters to the graph. <br/> pgb-> addfilter (psource, L "video capture"); <br/> pgb-> addfilter (pdecompressor, l "color format convert"); <br/> pgb-> addfilter (Prender, L "video receive "); </P> <p> // 3. Connect to the filter based on the media type and other information ///////////////////// ///////////// <br/> // The connectfilter function is used to connect two filters in graphbuild, this function needs to be implemented <br/> // videotype is the data type, obtained through other methods <br/> If (videotype = vf_rgb24) <br/>{< br/> connectfilter (pcapture, psource, Prender); <br/>}< br/> else if (videotype = vf_yuv2) <br/>{< br/> connectfilter (pcapture, psource, pdecompressor); <br/> connectfilter (pcapture, pdecompressor, Prender ); <br/>}</P> <p> // 4. Run graph ///////////////////// /// // <br/> pgb. queryInterface (& PMC); <br/> pgb. queryInterface (& PME); <br/> PMC-> Run ();