• 大小: 14.22MB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2023-07-31
  • 语言: C/C++
  • 标签: directshow  视频播放  

资源简介

MFC+DirectShow实现视频播放器,同事还可以摄像头采集视频,并播放出来

资源截图

代码片段和文件信息

#include “StdAfx.h“
#include “MyCapPin.h“


CMyCapPin::CMyCapPin(void)
{
CoInitialize(NULL);
m_CapGraph=NULL;
m_pGraph=NULL;
m_pSysDevEnum=NULL;
m_pMoniker=NULL;
m_pEnumCat=NULL;
m_pWindow=NULL;
m_pControl=NULL;
m_pbaseFilter=NULL;
m_hWnd=(HWND)INVALID_HANDLE_VALUE;
}


CMyCapPin::~CMyCapPin(void)
{
CoUninitialize();
}

BOOL CMyCapPin::AddFilter()
{
HRESULT hr = CoCreateInstance(CLSID_CaptureGraphBuilder2 NULL CLSCTX_INPROC_SERVER
IID_ICaptureGraphBuilder2 (void **)&m_CapGraph);
if(SUCCEEDED(hr))
{
hr=CoCreateInstance(CLSID_FilterGraphNULLCLSCTX_INPROC_SERVERIID_IGraphBuilder(void**)&m_pGraph);
if (SUCCEEDED(hr))
{
m_CapGraph->SetFiltergraph(m_pGraph);
}
else
{
m_CapGraph->Release();
return FALSE;
}

return TRUE;
}
else
return FALSE;
}
BOOL CMyCapPin::CreateDev()
{
HRESULT hr=CoCreateInstance(CLSID_SystemDeviceEnumNULLCLSCTX_INPROC_SERVERIID_ICreateDevEnum(void**)&m_pSysDevEnum);
hr=m_pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory&m_pEnumCat0);
return SUCCEEDED(hr);
return FALSE;
}
void CMyCapPin::SetHwnd(HWND hWnd)
{
m_hWnd=hWnd;
}
BOOL CMyCapPin::Create(void)
{
HRESULT hr;
if (!AddFilter()||!CreateDev())
{

return FALSE;
}
ULONG cFetched;
while(m_pEnumCat->Next(1 &m_pMoniker &cFetched) == S_OK)
{
hr=m_pMoniker->BindToobject(00IID_IbaseFilter(void**)&m_pbaseFilter);
hr=m_pGraph->AddFilter(m_pbaseFilterL“Capture Filter“);
hr=m_CapGraph->RenderStream(&PIN_CATEGORY_PREVIEW&MEDIATYPE_Videom_pbaseFilterNULLNULL);
hr=m_pGraph->QueryInterface(IID_IVideoWindow(void**)&m_pWindow);
hr=m_pGraph->QueryInterface(IID_IMediaControl(void**)&m_pControl);
m_pControl->Run();
m_pWindow->put_Owner((OAHWND)m_hWnd);
m_pWindow->put_Windowstyle(WS_CHILD);
m_pWindow->get_Width(&pWidth);
m_pWindow->get_Height(&pHeight);
m_pWindow->SetWindowPosition(00pWidthpHeight);
m_pMoniker->Release();
}
/* m_pSysDevEnum->CreateClassEnumerator(CLSID_VideoCompressorCategory&m_pEnumCat0);
IPropertyBag* pProp= NULL;
while (m_pEnumCat->Next(0&m_pMoniker&cFetched)==S_OK)
{
m_pMoniker->BindToStorage(00IID_IPropertyBag(VOID**)&pProp); 
VARIANT varName;
varName.vt = VT_BSTR;
pProp->Read(L“FriendlyName“ &varName0);
CString str=(char*)varName.bstrVal;
if (str.Find(“Microsoft Video 1“0)!= -1)
{
m_pMoniker->BindToobject(0 0 IID_IbaseFilter (void**)&m_pCompress);
m_pMoniker->Release(); 
break;
}
VariantClear(&varName);
}
m_pEnumCat->Release();
if (m_pCompress==NULL)
{
AfxMessageBox(IDOK);
return;

m_pGraph->AddFilter(m_pCompressL“com“);
CoCreateInstance(CLSID_AviDestNULL CLSCTX_ALL 
IID_IbaseFilter(void**)&pMux);
pGraph->AddFilter(pMuxL“Mux“);
CoCreateInstance(CLSID_FileWriter NULL CLSCTX_ALL 
IID_IbaseFilter (void **)&pWriter);
pGraph->AddFilter(pWriterL“Writer“);
p

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-11-07 21:17  Player\
     目录           0  2013-11-03 09:49  Player\Debug\
     文件      240128  2013-11-05 21:27  Player\Debug\Player.exe
     文件     1717160  2013-11-05 21:27  Player\Debug\Player.ilk
     文件     6532096  2013-11-05 21:27  Player\Debug\Player.pdb
     目录           0  2013-11-07 21:16  Player\ipch\
     目录           0  2013-11-07 21:16  Player\ipch\player-bf5bfe53\
     目录           0  2013-11-05 21:26  Player\Player\
     文件         885  2013-10-18 19:25  Player\Player.sln
     文件       30208  2013-11-07 21:17  Player\Player.suo
     文件         636  2013-10-19 14:32  Player\Player\ClassDiagram1.cd
     目录           0  2013-11-05 21:27  Player\Player\Debug\
     文件        4470  2013-11-05 21:27  Player\Player\Debug\cl.command.1.tlog
     文件       77628  2013-11-05 21:27  Player\Player\Debug\CL.read.1.tlog
     文件        6408  2013-11-05 21:27  Player\Player\Debug\CL.write.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link-cvtres.read.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link-cvtres.write.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.6896-cvtres.read.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.6896-cvtres.write.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.6896.read.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.6896.write.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.6948-cvtres.read.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.6948-cvtres.write.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.6948.read.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.6948.write.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.8664-cvtres.read.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.8664-cvtres.write.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.8664.read.1.tlog
     文件           2  2013-11-05 21:27  Player\Player\Debug\link.8664.write.1.tlog
     文件        2308  2013-11-05 21:27  Player\Player\Debug\link.command.1.tlog
     文件        5746  2013-11-05 21:27  Player\Player\Debug\link.read.1.tlog
............此处省略49个文件信息

评论

共有 条评论