directX显示采集源(摄像头)filter

简介: <br><br>IGraphBuilder * g_pGraphBuilder = NULL;<br>IBaseFilter *Pbf=0;<br>IVideoWindow  * g_pVWindow = NULL;<br>IMediaControl * g_pMControl = NULL;<br>IMediaEventEx * g_pMEvent = NULL;<br>ICaptureGr


IGraphBuilder * g_pGraphBuilder = NULL;
IBaseFilter *Pbf=0;
IVideoWindow  * g_pVWindow = NULL;
IMediaControl * g_pMControl = NULL;
IMediaEventEx * g_pMEvent = NULL;
ICaptureGraphBuilder2 * g_pCaptureBuilder = NULL;
IVideoWindow  *g_pivw  = NULL;


void CTestDlg::OnButton5() 
{
// TODO: Add your control notification handler code here
HRESULT hr;
IBaseFilter *pSrcFilter=NULL;
     CoInitialize(NULL);
    // Create the filter graph
    hr = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
                           IID_IGraphBuilder, (void **) &g_pGraphBuilder);
    // Create the capture graph builder
    hr = CoCreateInstance (CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
                           IID_ICaptureGraphBuilder2, (void **) &g_pCaptureBuilder);
    // Obtain interfaces for media control and Video Window
    hr = g_pGraphBuilder->QueryInterface(IID_IMediaControl,(LPVOID *) &g_pMControl);
    hr = g_pGraphBuilder->QueryInterface(IID_IVideoWindow, (LPVOID *) &g_pVWindow);
    hr = g_pGraphBuilder->QueryInterface(IID_IMediaEvent, (LPVOID *) &g_pMEvent);
         g_pGraphBuilder->QueryInterface(IID_IVideoWindow, (void **)&g_pivw);
    // Set the window handle used to process graph events
    hr = g_pMEvent->SetNotifyWindow((OAHWND)ghApp, WM_GRAPHNOTIFY, 0);
//
hr = g_pCaptureBuilder->SetFiltergraph(g_pGraphBuilder);
hr = FindCaptureDevice(&pSrcFilter);
    if (FAILED(hr))
    {
        // Don't display a message because FindCaptureDevice will handle it
        exit(1);
    }
    Pbf = pSrcFilter;
    // Add Capture filter to our graph.
    hr = g_pGraphBuilder->AddFilter(pSrcFilter, L"Video Capture");
hr = g_pCaptureBuilder->RenderStream (&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,
                                   pSrcFilter, NULL, NULL);
pSrcFilter->Release();


// hr = SetupVideoWindow(0);
///* //////////////////////////////////////////////////
    HWND m_hwnd = m_Screen2.GetSafeHwnd();
    m_Screen2.ModifyStyle(0, WS_CLIPCHILDREN);
    RECT rc;
m_Screen2.GetClientRect(&rc);

hr = g_pVWindow->put_Owner((OAHWND)m_hwnd);
hr = g_pVWindow->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);

hr = g_pVWindow->SetWindowPosition(0, 0, (rc.right), (rc.bottom));
hr = g_pVWindow->put_Visible(OATRUE);//*/
//////////////////////////////////////////////////
DWORD g_dwGraphRegister=0;
hr = g_pMControl->Run();
//


}
int rate=1;
void CTestDlg::OnButton2() 
{   
if (pims)
{    
rate++;
if(rate==4)
{
rate=1;

}
pims->SetRate(rate);
CString str;
str.Format("快进>> X %d",rate);
(GetDlgItem(IDC_BUTTON2))->SetWindowText(str);
}


// pivw->GetCurrentImage(&lpCurrImage) ;

}



HRESULT FindCaptureDevice(IBaseFilter ** ppSrcFilter)
{
    HRESULT hr;
    IBaseFilter * pSrc = NULL;
    IMoniker *pMoniker;
    ULONG cFetched;


    if (!ppSrcFilter)
        return E_POINTER;
   
    // Create the system device enumerator
    CComPtr <ICreateDevEnum> pDevEnum =NULL;


    hr = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
                           IID_ICreateDevEnum, (void **) &pDevEnum);
    if (FAILED(hr))
    {
    //    Msg(TEXT("Couldn't create system enumerator!  hr=0x%x"), hr);
        return hr;
    }


    // Create an enumerator for the video capture devices
   // CComPtr <IEnumMoniker> pClassEnum = NULL;
IEnumMoniker *pClassEnum=0;
    hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
    if (FAILED(hr))
    {
      //  Msg(TEXT("Couldn't create class enumerator!  hr=0x%x"), hr);
        return hr;
    }


    // If there are no enumerators for the requested type, then 
    // CreateClassEnumerator will succeed, but pClassEnum will be NULL.
    if (pClassEnum == NULL)
    {
        MessageBox(ghApp,TEXT("No video capture device was detected.\r\n\r\n")
                   TEXT("This sample requires a video capture device, such as a USB WebCam,\r\n")
                   TEXT("to be installed and working properly.  The sample will now close."),
                   TEXT("No Video Capture Hardware"), MB_OK | MB_ICONINFORMATION);
        return E_FAIL;
    }


    // Use the first video capture device on the device list.
    // Note that if the Next() call succeeds but there are no monikers,
    // it will return S_FALSE (which is not a failure).  Therefore, we
    // check that the return code is S_OK instead of using SUCCEEDED() macro.
    /*if (S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
    {
        // Bind Moniker to a filter object
        hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pSrc);
        if (FAILED(hr))
        {
          //  Msg(TEXT("Couldn't bind moniker to filter object!  hr=0x%x"), hr);
            return hr;
        }
    }
    else
    {
       // Msg(TEXT("Unable to access video capture device!"));   
        return E_FAIL;
    }*/


while(S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
    {
IPropertyBag *pProp= 0;
pMoniker->BindToStorage(0,0,IID_IPropertyBag,(void**)&pProp);
VARIANT varName;
varName.vt = VT_BSTR;
hr=pProp->Read(L"FriendlyName",&varName,0);
if(hr == NOERROR)
        {
CString str(varName.bstrVal);


if (str.Find("Virtual Camera",0)!=-1)
{
hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pSrc);
if (FAILED(hr))
{
//  Msg(TEXT("Couldn't bind moniker to filter object!  hr=0x%x"), hr);
break;
}
break;
}

}
pMoniker->Release();
    }
    // Copy the found filter pointer to the output parameter.
    // Do NOT Release() the reference, since it will still be used
    // by the calling function.
    *ppSrcFilter = pSrc;


    return hr;
}

相关文章
音视频开发: ffmpeg采集桌面屏幕、摄像头保存为视频
音视频开发: ffmpeg采集桌面屏幕、摄像头保存为视频
1023 0
音视频开发: ffmpeg采集桌面屏幕、摄像头保存为视频
|
3月前
|
编解码 网络协议 前端开发
如何实现Android平台GB28181设备接入模块按需打开摄像头并回传数据
后台采集摄像头,如果想再进一步扩展,可以把android平台gb28181的camera2 demo,都移植过来,实现功能更强大的国标设备侧,这里主要是展示,收到国标平台侧的回传请求后,才打开摄像头,才开始编码打包,最大限度的减少资源的占用
|
5月前
|
编解码 Linux 计算机视觉
python 调用ffmpeg使用usb摄像头录制视频,输出h264格式,自动获取摄像头的最佳帧率和最大画面尺寸
使用 Python 调用 FFmpeg 进行 USB 摄像头视频录制,需先确保安装 FFmpeg 和 Python 的 `subprocess` 模块。代码示例展示了如何自动获取摄像头的最佳帧率和最大分辨率,然后录制视频。首先通过 FFmpeg 列出摄像头格式获取信息,解析出帧率和分辨率,选择最优值。之后调用 FFmpeg 命令录制视频,设置帧率、分辨率等参数。注意 `/dev/video0` 是 Linux 的摄像头设备路径,Windows 系统需相应调整。代码中未直接实现自动获取最佳参数,通常需要借助其他库如 OpenCV。
|
11月前
|
Python
树莓派的摄像头信息实时发送到PC端显示
树莓派的摄像头信息实时发送到PC端显示
275 1
|
数据采集 Android开发 开发者
Android平台GB28181设备接入模块摄像头采集方向不对怎么办?
我们在做Android平台GB28181设备接入模块的时候,有开发者提到这样的诉求:他们的智能头盔、执法记录仪等设备,采集到的图像,是旋转了90、180甚至270°的,设备本身无法针对图像做翻转或者旋转操作,问我们这种情况下需要如何处理?
【C#】【FFmpeg】获取电脑可用音视频设备并输出到下拉列表框
【C#】【FFmpeg】获取电脑可用音视频设备并输出到下拉列表框
296 0
【C#】【FFmpeg】获取电脑可用音视频设备并输出到下拉列表框
|
Ubuntu Linux
FFMPEG音频开发: Linux下采集摄像头(使用V4L2框架)数据录制成MP4视频保存到本地
FFMPEG音频开发: Linux下采集摄像头(使用V4L2框架)数据录制成MP4视频保存到本地
1421 0
FFMPEG音频开发: Linux下采集摄像头(使用V4L2框架)数据录制成MP4视频保存到本地
|
Linux
linux下使用QT调用FFMPEG读取摄像头一帧数据显示到标签控件上
linux下使用QT调用FFMPEG读取摄像头一帧数据显示到标签控件上
647 0
linux下使用QT调用FFMPEG读取摄像头一帧数据显示到标签控件上
解决OBS录屏软件窗口采集不全的问题
解决OBS录屏软件窗口采集不全的问题
1412 0
解决OBS录屏软件窗口采集不全的问题
打印手机摄像头的支持参数+将预览帧转换为位图+获取最佳预览
打印手机摄像头的支持参数+将预览帧转换为位图
164 0