Menu Close

Working with DirectShow

1. Building DirectShow Application

Header file:    dshow.h

Library files:   strmiids.lib, quartz.lib

2. Calling the CoInitialize function, which initializes the COM library.

IGraphBuilder *pGraph;                 //filter graph manager interface. used to construct the filter graph

CoInitialize(NULL);

3. Then call the CoCreateInstance function to create the filter graph manager:

// create the filter graph – the object that contains all the filters ad interconnection info

HRESULT hr  = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);

4. Create a tool to assist in the creation and connection of capture filters

ICaptureGraphBuilder2* pBuild = 0;

hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,

(void **)&pBuild);

5. Connect the graph structure to the builder tool

hr = pBuild->SetFiltergraph(pGraph);

6. Find capture device and add it to filter graph

  • Create the System Device Enumerator

CComPtr<ICreateDevEnum> pSysDevEnum;

CComPtr<IEnumMoniker> pEnumCat = NULL;

hr = pSysDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum);

  • Obtain a class enumerator for the video input device category

hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);

  • Enumerate the monikers

CComPtr<IMoniker> pMoniker;

ULONG cFetched;

while(pEnumcat->Next(1, &pMoniker, &cFetched) == S_OK)

{

CComPtr<IPropertyBag> pProp;

pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **) &pProp);

VARIANT varName;

VariantInit(&varName);

           // get the friendly name.

hr = pProp->Read(L”FriendlyName”, &varName, 0);

if (SUCCEEDED(hr) && (wcscmp(CapName, varName.bstrVal) == 0))

{

  • If the friendly name matched, make a capture filter from the device

hr = pMoniker->BindToObject(0,0,IID_IBaseFilter,(void **)&pCapture);

  • add the vide device to graph

           pGraph->AddFilter(pCapture,varName.bstrVal);

VariantClear(&varName);

break;

}

VariantClear(&varName);

pMoniker = NULL; // Release for the next loop.

}

7. Set video sub type

hr = SetUncompressedRGBVideoSubType(MEDIASUBTYPE_RGB24);

8. Create a sample grabber if need to capture the frame from the video

9. Set video decoder

10. Set resolution

11. if not render, add a NULL filter

12. Render stream

hr = pBuild->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pCapture, pF, NULL);

13. Use the filter graph manager interface pointer pGraph to query for other two interfaces that are needed

IMediaControl* pControl;   //use to handle media straming in the filter graph

pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);

IMediaEvent* pEvent;   // use to handle filter graph events

pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

14. Control the media streaming in the filter graph

pControl->Run();

15. Handle filter graph events

pEvent->WaitForCompletion(INFINITE, &evCode);

In real application, you should avoid setting the wait interval to INFINIT, as this can block indefinitely. Also, you might want to respond to other filter graph events.

18. Clean up by release all the interface pointers nd the COM libray.

 

 

 

 

33 comments on “Working with DirectShow

  1. Shandi on said:

    I definitely wanted to write a brief remark to appreciate you for some of the remarkable recommendations you are posting at this site. My particularly long internet search has finally been recognized with good points to go over with my partners. I would believe that many of us visitors actually are unquestionably fortunate to live in a decent network with very many marvellous individuals with useful points. I feel very privileged to have come across your entire weblog and look forward to plenty of more enjoyable times reading here. Thanks once more for a lot of things.

  2. Karrie Hird on said:

    You made some clear points there. I did a search on the subject and found most persons will agree with your site.

  3. Rayford Weeler on said:

    It’s perfect time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I wish to suggest you few interesting things or suggestions. Perhaps you could write next articles referring to this article. I desire to read more things about it!

  4. source on said:

    A interesting blog post there mate ! Thank you for that !

  5. I like the helpful info you provide in your articles. I’ll bookmark your blog and check again here regularly. I’m quite sure I will learn lots of new stuff right here! Best of luck for the next!

  6. Amal Kines on said:

    I wanted to send you this bit of word just to say thanks a lot the moment again for those exceptional concepts you have provided in this case. This has been quite incredibly generous of you to convey openly precisely what some people could have marketed for an e book to generate some profit for themselves, chiefly considering the fact that you might well have tried it if you wanted. Those guidelines in addition acted as the easy way to understand that someone else have a similar dreams like mine to understand a little more with regards to this problem. Certainly there are several more enjoyable situations in the future for folks who look over your blog.

  7. Stevie Persinger on said:

    Well I definitely enjoyed studying it. This article procured by you is very useful for correct planning.

  8. Emilia Kidwell on said:

    I don’t even know how I ended up here, but I thought this post was good. I don’t know who you are but definitely you’re going to a famous blogger if you are not already 😉 Cheers!

  9. Wilma Flato on said:

    Simply desire to say your article is as surprising. The clarity in your post is simply excellent and i can assume you’re an expert on this subject. Fine with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please carry on the gratifying work.

  10. Just want to say your article is as astonishing. The clearness in your post is just excellent and i could assume you are an expert on this subject. Well with your permission allow me to grab your feed to keep up to date with forthcoming post. Thanks a million and please carry on the gratifying work.

  11. Jim Caldwell on said:

    I’ve recently started a site, the information you offer on this website has helped me tremendously. Thank you for all of your time & work.

  12. Sook Touch on said:

    I believe this site contains some very good info for everyone :D. “Calamity is the test of integrity.” by Samuel Richardson.

  13. Tyree Starner on said:

    I do trust all of the ideas you have introduced to your post. They’re very convincing and can certainly work. Still, the posts are very quick for newbies. May you please prolong them a little from next time? Thanks for the post.

  14. I love reading through and I think this website got some genuinely utilitarian stuff on it!

  15. Lanie Haman on said:

    Of course, what a splendid site and educative posts, I surely will bookmark your site.Best Regards!

  16. Elene Newingham on said:

    I really appreciate this post. I’ve been looking everywhere for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again!

  17. kacamata original on said:

    Very wonderful info can be found on blog.

  18. I in addition to my guys were reviewing the nice guidelines located on your site and so immediately got a terrible suspicion I never expressed respect to the blog owner for those strategies. The people were definitely absolutely happy to study them and now have absolutely been taking pleasure in them. I appreciate you for being really kind as well as for using such helpful themes most people are really eager to learn about. My very own sincere regret for not expressing appreciation to you sooner.

  19. Thank you, I have just been looking for info about this topic for a while and yours is the greatest I have came upon so far. But, what concerning the conclusion? Are you positive about the supply?

  20. arrone on said:

    hi I considered you may condone my guide

  21. Paz Casana on said:

    Very good info can be found on weblog . “Wealth may be an ancient thing, for it means power, it means leisure, it means liberty.” by James Russell Lowell.

  22. Leah Messer on said:

    I’ll immediately seize your rss feed as I can not to find your email subscription hyperlink or e-newsletter service. Do you’ve any? Kindly let me realize so that I could subscribe. Thanks.

  23. rozwod warszawa on said:

    Some genuinely interesting details you have written.Helped me a lot, just what I was searching for :D.

  24. Nickolas Dombrosky on said:

    You have brought up a very wonderful points , thankyou for the post.

  25. Erminia Tilson on said:

    Only a smiling visitor here to share the love (:, btw great design .

  26. Kris Cipolla on said:

    I’ve learn several just right stuff here. Definitely price bookmarking for revisiting. I surprise how a lot attempt you put to make this sort of excellent informative web site.

  27. Dorene Hohenberger on said:

    Great write-up, I’m normal visitor of one’s blog, maintain up the nice operate, and It is going to be a regular visitor for a long time.

  28. Harold Raminez on said:

    I have been browsing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the net will be a lot more useful than ever before.

  29. Naruto Manga on said:

    Thankyou for this rattling post, I am glad I observed this web site on yahoo.

  30. Josef Orland on said:

    Spot on with this write-up, I absolutely believe that this website needs far more attention. Iíll probably be returning to read through more, thanks for the information!

  31. Macrobid and Breatfeeding on said:

    This site definitely has all of the information and facts I wanted concerning this subject and didn’t know who to ask.

  32. Viper T56 on said:

    Awesome! Its genuinely awesome paragraph, I have got much clear idea concerning from this
    piece of writing.

  33. Pingback: Google

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy This Password *

* Type Or Paste Password Here *

18,519 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>