下面这个函数可以将Filter Gfraph保存到(*.grf)中,非常方便作程序调试:
用法示例:HRESULT CVMR_Capture::SaveGraphFile(IGraphBuilder *pGraph, WCHAR *wszPath) { const WCHAR wszStreamName[] = L"ActiveMovieGraph"; HRESULT hr; IStorage *pStorage = NULL; hr = StgCreateDocfile( wszPath, STGM_CREATE | STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pStorage); if(FAILED(hr)) { return hr; } IStream *pStream; hr = pStorage->CreateStream( wszStreamName, STGM_WRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream); if (FAILED(hr)) { pStorage->Release(); return hr; } IPersistStream *pPersist = NULL; pGraph->QueryInterface(IID_IPersistStream, (void**)&pPersist); hr = pPersist->Save(pStream, TRUE); pStream->Release(); pPersist->Release(); if (SUCCEEDED(hr)) { hr = pStorage->Commit(STGC_DEFAULT); } pStorage->Release(); return hr; }
原文地址:http://msdn.microsoft.com/en-us/library/dd377551%28VS.85%29.aspxvoid __cdecl main(void) { HRESULT hr; IGraphBuilder *pGraph; CoInitialize(NULL); // Create the Filter Graph Manager and render a file. CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, reinterpret_cast<void**>(&pGraph)); hr = pGraph->RenderFile(L"C://Video.avi", NULL); if (SUCCEEDED(hr)) { hr = SaveGraphFile(pGraph, L"C://MyGraph.grf"); } pGraph->Release(); CoUninitialize(); }