IGraphBuilder *pigb = NULL;
IMediaControl *pimc = NULL;
IMediaEventEx *pimex = NULL;
IVideoWindow *pivw = NULL;
IMediaSeeking *pims = NULL;
ICaptureGraphBuilder2 * g_pCaptureBuilder = NULL;
IBaseFilter *pF = 0;
void CTestFilterDlg::OnButton4()
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_FilterGraph,
NULL,
CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,
(void **)&pigb);
hr = CoCreateInstance (CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, (void **) &g_pCaptureBuilder);
pigb->QueryInterface(IID_IMediaControl, (void **)&pimc);
pigb->QueryInterface(IID_IMediaEventEx, (void **)&pimex);
pigb->QueryInterface(IID_IMediaSeeking, (void **)&pims);
pigb->QueryInterface(IID_IVideoWindow, (void **)&pivw);
hr = g_pCaptureBuilder->SetFiltergraph(pigb);
// avi-source ////////////////////////////////////////////////////////////
const GUID CLSID_AviSource={0xCEA8DEFF,0x0AF7,0x4DB9,{0x9A,0x38,0xFB,0x3C,0x3A,0xEF,0xC0,0xDE}};
hr = CoCreateInstance(CLSID_AviSource, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast<void**>(&pF));
hr = pigb->AddFilter(pF,L"SOURCE FILTER");
IFileSourceFilter *pSF = NULL;
hr = pF->QueryInterface(IID_IFileSourceFilter, (void**)&pSF);
if (SUCCEEDED(hr))
{
pSF->Load(L"F:\\FFOutput\\ff640480.avi", NULL);
pSF->Release();
}
IPin *pOut_Source = 0;
IPin *pPin;
if(SUCCEEDED(hr))
{
IEnumPins *pEnum;
// IPin *pPin;
hr = pF->EnumPins(&pEnum);
if (SUCCEEDED(hr))
{
/*
while(pEnum->Next(1, &pPin, 0) == S_OK)
{
PIN_DIRECTION pinDirThis;
pPin->QueryDirection(&pinDirThis);
if (PINDIR_OUTPUT == pinDirThis)
{
break;
}
}*/
hr = g_pCaptureBuilder->FindPin(pF,PINDIR_OUTPUT,NULL,NULL,FALSE,0,&pPin);
pEnum->Release();
}
}
pOut_Source= pPin;
if (hr)
{
MessageBox("ERR RENDERAVI!");
}
// ffshow-decoder /////////////////////////////////////////////////
IBaseFilter *paviDecoder;//---871E-AB91661A4EF7
const GUID CLSID_Decoder={0x04FE9017,0xF873,0x410E,{0x87,0x1e,0xaB,0x91,0x66,0x1a,0x4e,0xf7}};
hr = CoCreateInstance(CLSID_Decoder,NULL,CLSCTX_ALL,IID_IBaseFilter,(void **)&paviDecoder);
hr = pigb->AddFilter(paviDecoder,L"ffdshow Video Decoder ");
IPin *pIn_aviDecoder = 0;
IPin *pOut_aviDecoder = 0;
hr = g_pCaptureBuilder->FindPin(paviDecoder,PINDIR_INPUT,NULL,NULL,FALSE,0,&pIn_aviDecoder);
hr = g_pCaptureBuilder->FindPin(paviDecoder,PINDIR_OUTPUT,NULL,NULL,FALSE,0,&pOut_aviDecoder);
// Render filter ////////////////////////////////////////
IBaseFilter *pRenderFilter;
hr = CoCreateInstance(CLSID_VideoRenderer,NULL,CLSCTX_ALL,IID_IBaseFilter,(void **)&pRenderFilter);
hr = pigb->AddFilter(pRenderFilter,L"ffdshow Video Render ");
IPin *pIn_Render = 0;
hr = g_pCaptureBuilder->FindPin(pRenderFilter,PINDIR_INPUT,NULL,NULL,FALSE,0,&pIn_Render);
///// 特效filter ///////////////////////////////////////////////
IBaseFilter *peffect;//---871E-AB91661A4EF7
const GUID CLSID_EFFECT={0x8b498501, 0x1218, 0x11cf,{ 0xad, 0xc4, 0x0, 0xa0, 0xd1, 0x0, 0x4, 0x1b}};
hr = CoCreateInstance(CLSID_EFFECT,NULL,CLSCTX_ALL,IID_IBaseFilter,(void **)&peffect);
hr = pigb->AddFilter(peffect,L"Image effect ");
IPin *pIn_peffect = 0;
IPin *pOut_peffect = 0;
hr = g_pCaptureBuilder->FindPin(peffect,PINDIR_INPUT,NULL,NULL,FALSE,0,&pIn_peffect);
hr = g_pCaptureBuilder->FindPin(peffect,PINDIR_OUTPUT,NULL,NULL,FALSE,0,&pOut_peffect);
peffect->Release();
/// Connect 连接 pin/////////////////////////
hr = pigb->Connect(pOut_Source, pIn_aviDecoder);
if(FAILED(hr))
{
MessageBox("err17");
}
hr = pigb->Connect(pOut_aviDecoder, pIn_peffect);
if(FAILED(hr))
{
MessageBox("err18");
}
hr = pigb->Connect(pOut_peffect, pIn_Render);
if(FAILED(hr))
{
MessageBox("err19");
}
///////显示//////////////////////
HWND m_hwndScreen = m_Screen2.GetSafeHwnd();
RECT rc;
hr = pivw->put_Owner((OAHWND)m_hwndScreen);
hr = pivw->put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN);
m_Screen2.GetClientRect(&rc);
hr = pivw->SetWindowPosition(0, 0, (rc.right), (rc.bottom));
hr = pivw->put_Visible(OATRUE);//*/
hr = pimc->Run();
}