Regarding the scope of Sample Grabber in DirectSho

2019-02-21 03:49发布

问题:

I have 2 related questions for my web cam live capture application.

  1. The webcams capture data in varying formats such as YUY2, RGB24, I420, MJPG etc. I need to convert the captured data to I420 irrespective of the input format. Hence I need to know the current scope/capability of the Direct Show inbuilt Transform filter such as Sample Grabber. Will the Sample Grabber support at least these many transformations? Or will I have to write my own custom filters?

  2. Many of the webcams seem to have multiple format output. When I connect Sample Grabber whose media type is Set to I420, will the Sample Grabber filter talk to the Web camera driver to make sure that the data output from Webcam will be I420 ( if the Web cam has support).

I had already posted questions related to the above, but couldn't get them fully answered. Please help.

回答1:

Sample Grabber does not change media type of the data, but if you set a preferred media type before connecting then it will require the input stream to be of that mediatype. Just use RenderStream (intelligent connect, not direct one) and DirectShow will insert required decoders or transformers, if they are present.



回答2:

Take a look at the RGBFilters example in the directx sdk. For example one of the filters included is TransNull24. That filter will pass all samples unmodified, but is only able to connect when the input is MEDIASUBTYPE_RGB24. What you do is connect the webcam filter to the TransNull24, and the TransNull24 with the samplegrabber. If the webcam is able to output RGB24, that will be used. Otherwise a transform filter will be automatically added between the webcam and the TransNull24. Now you will only receive RGB24 in your samplegrabber, even if the webcam does not support that directly.

Of course you don't need RGB24, but you can simply modify the example filter and create your own TransNullI420 filter. I am not sure the standard color space conversion filter can output I420, so you might need to install ffdshow, en configure it to convert uncompressed video.