简体   繁体   English

ISampleGrabber可以将视频帧转换为特定的mediaType吗?

[英]can ISampleGrabber convert the video frames to a specific mediaType?

I found this nice example on the internet explaining how directshow works. 我在互联网上找到了一个很好的例子,解释了DirectShow的工作原理。

http://alax.info/trac/public/browser/trunk/Utilities/SetLifeCamStudioResolutionSample/SetLifeCamStudioResolutionSample.cpp http://alax.info/trac/public/browser/trunk/Utilities/SetLifeCamStudioResolutionSample/SetLifeCamStudioResolutionSample.cpp

In that example there is two samplegrabbers. 在该示例中,有两个样本收集器。 One called NON-RGB grabber, and one called RGB-grabber. 一种称为NON-RGB采集卡,另一种称为RGB采集卡。

The first one: (NON-RGB) 第一个:(非RGB)

#pragma region Non-RGB Sample Grabber
        {
            CComPtr<IBaseFilter> pBaseFilter;
            ATLENSURE_SUCCEEDED(pBaseFilter.CoCreateInstance(__uuidof(SampleGrabber)));
            ATLENSURE_SUCCEEDED(pFilterGraph->AddFilter(pBaseFilter, L"Non-RGB Sample Grabber")); // This will connect in MJPG format
            const CComQIPtr<ISampleGrabber> pSampleGrabber = pBaseFilter;
            ATLASSERT(pSampleGrabber);
#if TRUE
            // NOTE: IFilterGraph::Connect would do just fine, but with a real capture device, if we prefer having Smart Tee added, we need to use 
            //       Capture Graph Builder (only here)
            CComPtr<ICaptureGraphBuilder2> pCaptureGraphBuilder;
            ATLENSURE_SUCCEEDED(pCaptureGraphBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2));
            ATLENSURE_SUCCEEDED(pCaptureGraphBuilder->SetFiltergraph(pFilterGraph));
            ATLENSURE_SUCCEEDED(pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, NULL, pCurrentOutputPin, NULL, pBaseFilter));
#else
            ATLENSURE_SUCCEEDED(pFilterGraph->Connect(pCurrentOutputPin, GetPin(pBaseFilter, 0)));
#endif
            MessageBox(GetActiveWindow(), _T("After Non-RGB Sample Grabber Connected"), _T("Debug"), MB_OK);
            pCurrentOutputPin = GetPin(pBaseFilter, 1);
        }
        #pragma endregion 

the second: (RGB) 第二个:(RGB)

#pragma region RGB Sample Grabber
        {
            CComPtr<IBaseFilter> pBaseFilter;
            ATLENSURE_SUCCEEDED(pBaseFilter.CoCreateInstance(__uuidof(SampleGrabber)));
            ATLENSURE_SUCCEEDED(pFilterGraph->AddFilter(pBaseFilter, L"RGB Sample Grabber"));
            const CComQIPtr<ISampleGrabber> pSampleGrabber = pBaseFilter;
            ATLASSERT(pSampleGrabber);
            AM_MEDIA_TYPE MediaType;
            ZeroMemory(&MediaType, sizeof MediaType);
            MediaType.majortype = MEDIATYPE_Video;
            MediaType.subtype = MEDIASUBTYPE_RGB24;
            ATLENSURE_SUCCEEDED(pSampleGrabber->SetMediaType(&MediaType));
            ATLENSURE_SUCCEEDED(pFilterGraph->Connect(pCurrentOutputPin, GetPin(pBaseFilter, 0)));
            MessageBox(GetActiveWindow(), _T("After RGB Sample Grabber Connected"), _T("Debug"), MB_OK);
            pCurrentOutputPin = GetPin(pBaseFilter, 1);
        }
        #pragma endregion 

The method "setmediatype()" is used only in the "RGB" version. 方法“ setmediatype()”仅在“ RGB”版本中使用。 But i wonder. 但是我不知道。 On MSDN page is says that setmediatype() says what type of data that is avaiable to in input pin of the sample grabber filter. 在MSDN页面上,说setmediatype()表示样本采集器过滤器的输入引脚中可用的数据类型。 And if it possible to use the sample grabber without seting the media type, why should I set it to anything? 如果可以在不设置媒体类型的情况下使用样品采集器,为什么还要将其设置为任何值?

Questions: 问题:

Do sample grabber do any type of media converting? 样品采集卡是否可以进行任何类型的媒体转换?

Why should I set the media type of the sample grabber? 为什么要设置样品采集器的介质类型?

If the mediatype form the cam is set to MJPG, and I set the media type to RGB24 in the samplegrabber, what happens? 如果cam的媒体类型设置为MJPG,而我在samplegrabber中将媒体类型设置为RGB24,会发生什么情况?

Could there be any performance difference of using one over another? 相互使用会不会有性能差异? To increase the performance (fps) of the software, should I remove one of the sample grabbers? 为了提高软件的性能(fps),我是否应该卸下其中一个样品采集器?

Thanks! 谢谢!

Sample Grabber Filter does not do any conversion. Sample Grabber Filter不执行任何转换。 This is why it is flexible to accept variety of formats, video and audio included, without being aware of individual format specific. 这就是为什么可以灵活地接受各种格式(包括视频和音频)而无需知道特定于特定格式的原因。

When you set media type on Sample Grabber, you force it to use this type only. 在Sample Grabber上设置媒体类型时,您强制其仅使用此类型。 To only accept this type and reject other. 只接受这种类型而拒绝其他类型。 Together with Intelligent Connect , this works in a way that DirectShow might provide additional filters to convert to requested format, if possible. Intelligent Connect一起使用时,DirectShow可能会提供其他过滤器,以尽可能转换为请求的格式。 It is typically possible with 24-bit RGB because it is a sort of "universal uncompressed video format". 24位RGB通常是可能的,因为它是一种“通用未压缩视频格式”。 This is why is is safe to set media type to 24-bit RGB and in the same time it is going to fail with almost any compressed video format (unless source already can supply exactly a match). 这就是为什么将媒体类型设置为24位RGB是安全的,同时几乎所有压缩视频格式都将失败(除非源已经可以提供完全匹配的内容)。

Note that if Intelligent Connect supplies additional conversion filters, they are attached upstream to Sample Grabber, not inside it. 请注意,如果Intelligent Connect提供了附加的转换过滤器,它们将连接到Sample Grabber的上游,而不是内部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM