DirectShow basic programming to collect video data

Source: Internet
Author: User

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 ();

 

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.