简体   繁体   English

如何从具有H264硬件编码器的网络摄像头访问H264流?

[英]How to access the H264 stream from webcams that feature H264 hardware encoders?

I'm developing a video capture application using DirectShow and I'd like to take advantage of the H264 hardware encoders present on some web-cams. 我正在使用DirectShow开发视频捕获应用程序,我想利用某些网络摄像头上的H264硬件编码器。

In particular I'm looking at two cameras: the Creative Connect HD VF0750 and the Logitech C920 which both claim to feature H264 hardware encoders. 特别是我正在研究两款相机:Creative Connect HD VF0750和Logitech C920,它们都声称具有H264硬件编码器。

Using GraphEdit, so far I've had mixed results. 使用GraphEdit,到目前为止我的结果好坏参半。 The Logitech C920 camera exposes an H264 stream as a Pin on the DirectShow WDM Capture filter but only on Windows 7. Trying the same on Windows 8 only shows output Pins for MJPEG and uncompressed YUV streams. Logitech C920相机在DirectShow WDM Capture过滤器上将H264流作为Pin进行曝光,但仅在Windows 7上进行。在Windows 8上尝试相同,仅显示MJPEG和未压缩YUV流的输出引脚。

On the other hand, the Creative Connect HD VF0750 camera does not appear to expose an H264 Pin at all - even in Windows 7. 另一方面,即使在Windows 7中,Creative Connect HD VF0750相机也似乎没有露出H264引脚。

Yet, they both claim H264 encoders, and they claim that Skype can take advantage of the hardware encoders. 然而,他们都声称H264编码器,他们声称Skype可以利用硬件编码器。

So the question is - what interface or API does Skype use to obtain the hardware encoded H264 stream from these cameras? 所以问题是 - 用什么接口或API来从这些摄像头获取硬件编码的H264流? Since they're offered by different manufacturers it stands to reason that they use some common API and not just some obscure made-for-Skype custom interface. 由于它们是由不同的制造商提供的,因此它们使用一些通用API而不仅仅是一些模糊的Skype定制界面。

I've used code like this to enumerate all pins and media types/sub types for each: 我使用这样的代码来枚举每个的所有引脚和媒体类型/子类型:

IBaseFilterPtr f = getBaseFilterFromEnum();    // code omitted for brevity

IEnumPinsPtr pEnum;
f->EnumPins(&pEnum);
IPinPtr pin;
while (pEnum->Next(1, &pin, NULL) == S_OK)
{
    PIN_INFO PinInformation;
    pin->QueryPinInfo(&PinInformation);                 

    IKsPropertySetPtr pKsPropertySet = pin;
    if(pKsPropertySet)
    {
        GUID Category;
        DWORD nCategorySize;                

        if(SUCCEEDED(pKsPropertySet->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0, &Category, sizeof Category, &nCategorySize)))
        {
            // checks category type here

            IAMStreamConfigPtr pAmStreamConfig = pin;
            if(pAmStreamConfig)
            {
                int fmts, sccsz;
                pAmStreamConfig->GetNumberOfCapabilities(&fmts, &sccsz);
                BYTE* scc = new BYTE[sccsz];            

                for (int i = 0; i < fmts; i++)
                {
                    AM_MEDIA_TYPE* mt;
                    pAmStreamConfig->GetStreamCaps(i, &mt, scc);
                    if (mt)
                    {
                        if (mt->pbFormat)
                        {
                            // query here based on mt->formattype

                            //  and based on mt->subtype
                            if(mt->subtype == MEDIASUBTYPE_H264)
                            {
                                // has H264
                            }else if(mt->subtype == MEDIASUBTYPE_RGB24)
                            {
                                // has RGB
                            }else if(mt->subtype == MEDIASUBTYPE_YUY2)
                            {
                                // has YUY2
                            }else if(mt->subtype == MEDIASUBTYPE_MJPG)
                            {
                                // has MJPEG
                            }else
                            {
                                // has some other sub-type
                                //   not getting this on either of my cams
                            }
                            // free mem here
                        }
                        // more free mem here
                    }
                }
                delete[] scc;
            }else{                  
                // Error Getting Formats - this happens for the Video Terminal Pins
            }
        }           
    }
}

This is output I'm getting for the two cameras on Windows 7: 这是我在Windows 7上为两台摄像机获得的输出:

Live! Cam Connect HD VF0750
   Capture (CAPTURE):  
       18 Formats: RGB; YUY2; MJPEG; (VIDEO_INFO; )
   Video Camera Terminal (UNKNOWN):  
       Error Getting Formats
   Still (STILL):  
       3 Formats: RGB; (VIDEO_INFO; )
HD Pro Webcam C920
   Capture (CAPTURE):  
       106 Formats: H264; YUY2; MJPEG; (VIDEO_INFO; VIDEO_INFO2; )
   Video Camera Terminal (UNKNOWN):
       Error Getting Formats

On Windows 8, the output is different. 在Windows 8上,输出不同。 Neither of them come up with H264 sub-types (despite both claiming to support H264 hardware-encoded stream). 他们都没有提出H264子类型(尽管两者都声称支持H264硬件编码流)。

At least in Win7 the Logitech camera provides the H264 pin as expected. 至少在Win7中,罗技相机提供了预期的H264引脚。

Over time I received a few submissions from users for video capture capabilities of Logitech HD Pro Webcam C920 camera in different systems. 随着时间的推移,我收到了一些用户提交的有关Logitech HD Pro Webcam C920相机在不同系统中的视频捕获功能的提交。 The data is here . 数据在这里 Availability of hardware H.264 video requires specific (most recent?) version of driver, and behavior is different across operating system versions. 硬件H.264视频的可用性需要特定的(最近的?)版本的驱动程序,并且操作系统版本的行为是不同的。 While in Windows 7 H264 media type is available on the capture pin the usual way, in newer OSes there is a separate additional Capture pin with H264 media types. 虽然在Windows 7中,H264介质类型通常采用捕获引脚,但在较新的操作系统中,还有一个单独的附加Capture引脚,具有H264介质类型。 Apparently, applications capturing H.264 are assumed to be aware of this new layout and connect pins/capture appropriately. 显然,假设捕获H.264的应用程序知道这种新布局并适当地连接引脚/捕获。

The same applies to Logitech Webcam C930e camera (Windows 7 - no H.264 at all , Windows 8.1 - H.264 on second capture pin ). 这同样适用于罗技Webcam C930e相机(Windows 7 - 完全没有H.264 ,Windows 8.1 - 第二个捕获引脚上的H.264 )。

The data on the secondary capture pin has standard MEDIASUBTYPE_H264 formatting: 辅助捕获引脚上的数据具有标准MEDIASUBTYPE_H264格式:

在此输入图像描述

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

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