1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| #include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
CComPtr<ICaptureGraphBuilder2> pCaptureGraphBuilder;//m_pCaptureGraphBuilder
CComPtr<IGraphBuilder> pGraphBuilder;//pFilterGraph
CComPtr<IImageSinkFilter> m_pImageSinkFilter;
CComPtr<IAMStreamConfig> pConfig;
CComPtr<IBaseFilter> pVideoCapture;//m_pVideoCaptureFilter
CComPtr<IPersistPropertyBag> pPropertyBag;
CPropertyBag PropBag;
CComPtr<IBaseFilter> pImageSinkFilter;
CComPtr<IMediaControl> pMediaControl;
CComPtr<IMediaEvent> pMediaEvent;
CComPtr<IUnknown> pUnkCaptureFilter;
CComPtr<IPin> pStillPin;//cap
CComPtr<IAMVideoControl> pVideoControl;
int _tmain(int argc, _TCHAR* argv[])
{
CComVariant varCamName;
HRESULT hr = S_OK;
HANDLE handle = NULL;
DEVMGR_DEVICE_INFORMATION di;
GUID guidCamera = { 0xCB998A05, 0x122C, 0x4166, 0x84, 0x6A, 0x93, 0x3E, 0x4D, 0x7E, 0x3C, 0x86 };
WCHAR wzDeviceName[ MAX_PATH + 1 ];
CoInitialize( NULL );
CComPtr<IFileSinkFilter> pFileSinkT;
// Create the capture grahp builder and register the filtergraph manager.
hr = pCaptureGraphBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder);
hr = pGraphBuilder.CoCreateInstance(CLSID_FilterGraph);
hr = pCaptureGraphBuilder->SetFiltergraph(pGraphBuilder);
// Create and initialize the video capture filter.
pVideoCapture.CoCreateInstance(CLSID_VideoCapture);
pVideoCapture.QueryInterface(&pPropertyBag);
// ////////////////////////////////////////kamera /////////////////
di.dwSize = sizeof(di);
handle = FindFirstDevice( DeviceSearchByGuid, &guidCamera, &di );
if(( handle == NULL ) || ( di.hDevice == NULL ))
{
MessageBox(NULL,L"camera not found ",L"not found",MB_OK);
}
StringCchCopy( wzDeviceName, MAX_PATH, di.szLegacyName );
FindClose( handle );
varCamName = wzDeviceName;
PropBag.Write( L"VCapName", &varCamName );
pPropertyBag->Load( &PropBag, NULL );
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
pGraphBuilder->AddFilter(pVideoCapture, L"Video capture source");
//
//////////////////////////////////////////////////////////imgsinkfilter///////////////////////////////////////////////////////////////////////////
pImageSinkFilter.CoCreateInstance(CLSID_IMGSinkFilter);
pGraphBuilder->AddFilter(pImageSinkFilter, L"Stil image filter");
//////////////////////////////////////////capturer le flux///////////////////////////////////////////////////////////////////////////////
pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_STILL, &MEDIATYPE_Video,pVideoCapture, NULL, pImageSinkFilter);
pCaptureGraphBuilder->ControlStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pVideoCapture, 0, 0, 0, 0);
hr = pVideoCapture.QueryInterface( &pUnkCaptureFilter);
hr = pCaptureGraphBuilder->FindPin( pUnkCaptureFilter, PINDIR_OUTPUT, &PIN_CATEGORY_STILL, &MEDIATYPE_Video, FALSE, 0, &pStillPin);
////////////////////
hr = pStillPin.QueryInterface(&pConfig);
//////////////////////////
pImageSinkFilter.QueryInterface( &m_pImageSinkFilter );
//ready to capture data
hr = m_pImageSinkFilter.QueryInterface( &pFileSinkT );
hr = pFileSinkT->SetFileName(L"\\test.bmp", NULL);
hr = pVideoCapture.QueryInterface( &pVideoControl );
hr = pGraphBuilder.QueryInterface(&pMediaControl);
hr = pMediaControl->Run();
//MessageBox(NULL,L"no",L"no",MB_OK);
hr = pMediaControl->Stop();
hr = pVideoControl->SetMode( pStillPin, VideoControlFlag_Trigger);
MessageBox(NULL,L"The file has been captured\r\n",L"The file has been captured\r\n",MB_OK);
CoUninitialize();
return 0;
} |
Partager