동영상을 저장할 때
//////////////////////////////////////////////////////////////////
HRESULT hr = S_OK;
hr = pRenderEngine.CoCreateInstance(CLSID_RenderEngine);
IGraphBuilder *pGraph = NULL;
ICaptureGraphBuilder2 *pBuilder = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;
// Build the graph.
hr = pRenderEngine->SetTimelineObject(pMainTL);
hr = pRenderEngine->ConnectFrontEnd( );
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, (void **)&pBuilder);
// Get a pointer to the graph front end.
hr = pRenderEngine->GetFilterGraph(&pGraph);
hr = pBuilder->SetFiltergraph(pGraph);
// Create the file-writing section.
WCHAR wstring[1024];
ZeroMemory(wstring, sizeof(wstring));
mbstowcs(wstring, (LPCTSTR)createFileName, createFileName.GetLength());
IBaseFilter *pMux;
hr = pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, wstring, &pMux, NULL);
long NumGroups;
hr = pMainTL->GetGroupCount(&NumGroups);
// Loop through the groups and get the output pins.
for (int i = 0; i < NumGroups; i++)
{
IPin *pPin;
if (pRenderEngine->GetGroupOutputPin(i, &pPin) == S_OK)
{
hr = pBuilder->RenderStream(NULL, NULL, pPin, NULL, pMux);
pPin->Release();
}
}
// Run the graph.
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
hr = pControl->Run();
long evCode;
hr = pEvent->WaitForCompletion(INFINITE, &evCode);
hr = pControl->Stop();
// Clean up.
if (pMux)
{
pMux->Release();
}
pEvent->Release();
pControl->Release();
pGraph->Release();
pBuilder->Release();
//////////////////////////////////////////////////////////////////
HRESULT hr = S_OK;
hr = pRenderEngine.CoCreateInstance(CLSID_RenderEngine);
IGraphBuilder *pGraph = NULL;
ICaptureGraphBuilder2 *pBuilder = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;
// Build the graph.
hr = pRenderEngine->SetTimelineObject(pMainTL);
hr = pRenderEngine->ConnectFrontEnd( );
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, (void **)&pBuilder);
// Get a pointer to the graph front end.
hr = pRenderEngine->GetFilterGraph(&pGraph);
hr = pBuilder->SetFiltergraph(pGraph);
// Create the file-writing section.
WCHAR wstring[1024];
ZeroMemory(wstring, sizeof(wstring));
mbstowcs(wstring, (LPCTSTR)createFileName, createFileName.GetLength());
IBaseFilter *pMux;
hr = pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, wstring, &pMux, NULL);
long NumGroups;
hr = pMainTL->GetGroupCount(&NumGroups);
// Loop through the groups and get the output pins.
for (int i = 0; i < NumGroups; i++)
{
IPin *pPin;
if (pRenderEngine->GetGroupOutputPin(i, &pPin) == S_OK)
{
hr = pBuilder->RenderStream(NULL, NULL, pPin, NULL, pMux);
pPin->Release();
}
}
// Run the graph.
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
hr = pControl->Run();
long evCode;
hr = pEvent->WaitForCompletion(INFINITE, &evCode);
hr = pControl->Stop();
// Clean up.
if (pMux)
{
pMux->Release();
}
pEvent->Release();
pControl->Release();
pGraph->Release();
pBuilder->Release();