directshow获取 颜色空间 分辨率



void GetColorSpaceResolution()
{
    HRESULT hr;
    AM_MEDIA_TYPE *pmt = NULL;
    VIDEOINFOHEADER *pvi = NULL;
    VIDEO_STREAM_CONFIG_CAPS scc;
    IAMStreamConfig* pConfig = 0;


    hr = pBuild->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,pCap,
                               IID_IAMStreamConfig, (void**)&pConfig);
    if (FAILED(hr)) {
        qWarning()<<"failed to get config on capture device";
        return;
    }


    int iCount;
    int iSize;
    hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);
    if (FAILED(hr)) {
        qWarning()<<"failed to get capabilities";
        return;
    }


    QList<QSize> sizes;
    QVideoFrame::PixelFormat f = QVideoFrame::Format_Invalid;


    types.clear();
    resolutions.clear();


    for (int iIndex = 0; iIndex < iCount; iIndex++) {
        hr = pConfig->GetStreamCaps(iIndex, &pmt, reinterpret_cast<BYTE*>(&scc));
        if (hr == S_OK) {
            pvi = (VIDEOINFOHEADER*)pmt->pbFormat;
            if ((pmt->majortype == MEDIATYPE_Video) &&
                    (pmt->formattype == FORMAT_VideoInfo)) {
                // Add types
                if (pmt->subtype == MEDIASUBTYPE_RGB24) {
                    if (!types.contains(QVideoFrame::Format_RGB24)) {
                        types.append(QVideoFrame::Format_RGB24);
                        f = QVideoFrame::Format_RGB24;
                    }
                } else if (pmt->subtype == MEDIASUBTYPE_RGB32) {
                    if (!types.contains(QVideoFrame::Format_RGB32)) {
                        types.append(QVideoFrame::Format_RGB32);
                        f = QVideoFrame::Format_RGB32;
                    }
                } else if (pmt->subtype == MEDIASUBTYPE_YUY2) {
                    if (!types.contains(QVideoFrame::Format_YUYV)) {
                        types.append(QVideoFrame::Format_YUYV);
                        f = QVideoFrame::Format_YUYV;
                    }
                } else if (pmt->subtype == MEDIASUBTYPE_MJPG) {
                } else if (pmt->subtype == MEDIASUBTYPE_I420) {
                    if (!types.contains(QVideoFrame::Format_YUV420P)) {
                        types.append(QVideoFrame::Format_YUV420P);
                        f = QVideoFrame::Format_YUV420P;
                    }
                } else if (pmt->subtype == MEDIASUBTYPE_RGB555) {
                    if (!types.contains(QVideoFrame::Format_RGB555)) {
                        types.append(QVideoFrame::Format_RGB555);
                        f = QVideoFrame::Format_RGB555;
                    }
                } else if (pmt->subtype == MEDIASUBTYPE_YVU9) {
                } else if (pmt->subtype == MEDIASUBTYPE_UYVY) {
                    if (!types.contains(QVideoFrame::Format_UYVY)) {
                        types.append(QVideoFrame::Format_UYVY);
                        f = QVideoFrame::Format_UYVY;
                    }
                } else {
                    qWarning() << "UNKNOWN FORMAT: " << pmt->subtype.Data1;
                }
                // Add resolutions
                QSize res(pvi->bmiHeader.biWidth, pvi->bmiHeader.biHeight);
                if (!resolutions.contains(f)) {
                    sizes.clear();
                    resolutions.insert(f,sizes);
                }
                resolutions[f].append(res);
            }
        }
    }
    pConfig->Release();


    if (!types.isEmpty()) {
        // Add RGB formats and let directshow do color space conversion if required.
        if (!types.contains(QVideoFrame::Format_RGB24)) {
            types.append(QVideoFrame::Format_RGB24);
            resolutions.insert(QVideoFrame::Format_RGB24, resolutions[types.first()]);
        }
        if (!types.contains(QVideoFrame::Format_RGB32)) {
            types.append(QVideoFrame::Format_RGB32);
            resolutions.insert(QVideoFrame::Format_RGB32, resolutions[types.first()]);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DirectShow是一种用于视频和音频捕捉和处理的Microsoft Windows多媒体框架。通过DirectShow,我们可以获取麦克风是否有输入。 要获取麦克风是否有输入,我们可以使用DirectShow提供的基本功能和接口。以下是一个简单的步骤: 1. 首先,我们需要创建一个DirectShow的Graph对象,用于构建一个捕捉图形流水线。我们可以使用CoCreateInstance函数来创建该对象。 2. 接下来,我们需要创建一个捕捉源,用于实时捕捉麦克风的音频。我们可以使用CoCreateInstance函数创建一个音频捕捉过滤器。 3. 然后,我们将捕捉源添加到Graph中。我们可以调用IGraphBuilder接口的AddFilter方法来添加捕捉源。 4. 接下来,我们需要连接捕捉源和一个音频渲染器,以便我们能够通过扬声器听到捕捉到的音频。我们可以使用IBaseFilter接口的EnumPins方法枚举捕捉源的输出引脚,并使用IPin接口的Connect方法将其连接到音频渲染器的输入引脚。 5. 最后,我们可以通过检查捕捉源是否成功连接到音频渲染器来判断麦克风是否有输入。我们可以调用IGraphBuilder接口的Render方法将图形渲染到渲染设备上,并检查是否出现连接错误。 通过上述步骤,我们可以使用DirectShow获取麦克风是否有输入。如果连接成功,即表示麦克风有输入;否则,表示没有输入或连接失败。这样我们就可以进行后续的音频捕捉和处理操作,实现更多有关麦克风的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值