本文整理汇总了C++中IGraphBuilder::AddSourceFilter方法的典型用法代码示例。如果您正苦于以下问题:C++ IGraphBuilder::AddSourceFilter方法的具体用法?C++ IGraphBuilder::AddSourceFilter怎么用?C++ IGraphBuilder::AddSourceFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraphBuilder
的用法示例。
在下文中一共展示了IGraphBuilder::AddSourceFilter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CoCreateInstance
/******************************Public*Routine******************************\
* BuildAndRender
*
* 视频文件源
\**************************************************************************/
HRESULT CVMR9Subgraph::BuildAndRender( LPCWSTR lpPath , IMultiVMR9Wizard* pWizard ,SourceConnectProc ConnectProc)
{
HRESULT hr = S_OK;
if(!pWizard)return E_FAIL;
if(m_pGraph) return E_FAIL;
m_ConnectProc = ConnectProc;
if( !lpPath )
{
return E_POINTER;
}
IBaseFilter * pVMR9 = 0;
IBaseFilter * pFileScr = 0;
IVMRFilterConfig9 * pConfig = 0;
IGraphBuilder * pGb = 0;
ICaptureGraphBuilder2 * pBuild = NULL;
IBaseFilter *pAviSplit = NULL;
IPin*pPin = 0;
USES_CONVERSION;
m_GraphType = Media_File;
try
{
// first, check that file exists
if( INVALID_FILE_ATTRIBUTES == GetFileAttributes( lpPath))throw VFW_E_NOT_FOUND;
// create graph
hr = CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IFilterGraph, (void**)&(m_pGraph) );
if( FAILED(hr))throw hr;
// create and add VMR9
hr = CoCreateInstance( CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER,
IID_IBaseFilter, (void**)&(pVMR9) );
if( FAILED(hr))throw hr;
hr = m_pGraph->AddFilter( pVMR9, L"VMR9");
if( FAILED(hr))throw hr;
// configure VMR9
hr = pVMR9->QueryInterface( IID_IVMRFilterConfig9, (void**)&(pConfig) );
if( FAILED(hr))throw hr;
// if wizard is provided, set VMR to the renderless code and attach to the wizard
if( pWizard )
{
// set VMR to the renderless mode
hr = pConfig->SetRenderingMode( VMR9Mode_Renderless );
if( FAILED(hr))throw hr;
hr = pWizard->Attach( pVMR9, D3DFMT_UNKNOWN,&m_dwID );
if( FAILED(hr))throw hr;
}
// try to render media source
hr = m_pGraph->QueryInterface( IID_IGraphBuilder, (void**)&(pGb) );
if( FAILED(hr))throw hr;
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2, (void **)&pBuild);
if( FAILED(hr))throw hr;if(!pBuild)throw E_OUTOFMEMORY;
//--
hr = pBuild->SetFiltergraph(pGb);
if( FAILED(hr))throw hr;
hr = pGb->AddSourceFilter( lpPath, L"Source", &pFileScr);
if( FAILED(hr))throw hr;
if(m_ConnectProc) {
hr = m_ConnectProc(m_dwID,m_pGraph,pFileScr,pVMR9);
if( FAILED(hr))throw hr;
}else
{
hr = CoCreateInstance(CLSID_AviSplitter, 0, CLSCTX_INPROC_SERVER,IID_IBaseFilter, reinterpret_cast<void**>(&pAviSplit));
if( FAILED(hr))throw hr;
hr = m_pGraph->AddFilter(pAviSplit, L"AVI Splitter");
if( FAILED(hr))throw hr;
hr = pBuild->RenderStream(0, 0,pFileScr,pAviSplit,pVMR9);
if( FAILED(hr))throw hr;
}
// ok, all is rendered, now get MediaControl, MediaSeeking and continue
hr = m_pGraph->QueryInterface( IID_IMediaControl, (void**)&(m_pMc) );
if( FAILED(hr))throw hr;
hr = m_pGraph->QueryInterface( IID_IMediaSeeking, (void**)&(m_pMs) );
//.........这里部分代码省略.........
示例2: main
int main(int argc, char* argv[])
{
ICaptureGraphBuilder2 *pCaptureGraphBuilder = NULL;
IGraphBuilder *pGraphBuilder = NULL;
IBaseFilter *pSource = NULL;
IBaseFilter *pMux = NULL;
IBaseFilter *pVideoCompressor = NULL;
IBaseFilter *pAudioCompressor = NULL;
IAMStreamConfig *pAMStreamConfig = NULL;
IAMVideoCompression *pAMVideoCompression = NULL;
IMediaControl *pControl = NULL;
IMediaSeeking *pSeek = NULL;
IMediaEvent *pEvent = NULL;
HRESULT hr;
DWORD pdwRegister=0;
CoInitialize(NULL);
// Create the capture graph builder.
CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, (void **)&pCaptureGraphBuilder);
// Make the rendering section of the graph.
pCaptureGraphBuilder->SetOutputFileName(
&MEDIASUBTYPE_Avi, // File type.
L"C:\\STDIUE1.avi", // File name.
&pMux, // pointer to the multiplexer.
NULL); // pointer to the file writer.
// Load the source file.
pCaptureGraphBuilder->GetFiltergraph(&pGraphBuilder);
pGraphBuilder->AddSourceFilter(L"C:\\Program Files\\Microsoft Money\\Media\\STDIUE1.avi", L"Source Filter", &pSource);
// Add the compressor filter.
CoCreateInstance(CLSID_AVICo, NULL, CLSCTX_INPROC,
IID_IBaseFilter, (void **)&pVideoCompressor);
pGraphBuilder->AddFilter(pVideoCompressor, L"Video Compressor");
// Render the video stream, through the compressor.
pCaptureGraphBuilder->RenderStream(
NULL, // Output pin category
NULL, // Media type
pSource, // Source filter
pVideoCompressor, // Compressor filter
pMux); // Sink filter (the AVI Mux)
/* CoCreateInstance(CLSID_GSM, NULL, CLSCTX_INPROC,
IID_IBaseFilter, (void **)&pAudioCompressor);
pGraphBuilder->AddFilter(pAudioCompressor, L"Audio Compressor");*/
// Render the audio stream.
pCaptureGraphBuilder->RenderStream(
NULL,
NULL,
pSource,
pAudioCompressor,
pMux);
// Compress at 100k/second data rate.
AM_MEDIA_TYPE *pmt;
pCaptureGraphBuilder->FindInterface(NULL, NULL, pVideoCompressor, IID_IAMStreamConfig, (void **)&pAMStreamConfig);
pAMStreamConfig->GetFormat(&pmt);
if (pmt->formattype == FORMAT_VideoInfo)
{
((VIDEOINFOHEADER *)(pmt->pbFormat))->dwBitRate = 100000;
pAMStreamConfig->SetFormat(pmt);
}
// Request key frames every four frames.
pAMStreamConfig->QueryInterface(IID_IAMVideoCompression, (void **)&pAMVideoCompression);
pAMVideoCompression->put_KeyFrameRate(4);
pAMVideoCompression->Release();
pAMStreamConfig->Release();
// Run the graph.
pGraphBuilder->QueryInterface(IID_IMediaControl, (void **)&pControl);
pGraphBuilder->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
hr = pMux->QueryInterface(IID_IMediaSeeking, (void**)&pSeek);
pControl->Run();
printf("Recompressing... \n");
long evCode;
if (SUCCEEDED(hr))
{
REFERENCE_TIME rtTotal, rtNow = 0;
pSeek->GetDuration(&rtTotal);
while ((pEvent->WaitForCompletion(1000, &evCode)) == E_ABORT)
{
//.........这里部分代码省略.........