视频采集---MPEG4压缩实现

1 先分析 AvCap的例子

   (1)构建压缩filter

       代码如下:

IBaseFilter* pFlt = UDsUtils::CreateCompressor(TRUE, "DivX 5.0.2 Codec"); if (pFlt) { mVideoEncoder = new CDXFilter(mGraph->GetGraph()); mVideoEncoder->Attach(pFlt, "DivX Encoder"); pFlt->Release(); pass = TRUE; } else { pass = FALSE; AfxMessageBox("DivX Encoder failed to create!"); } BOOL CDXFilter::Attach(IBaseFilter * inFilter, const char * inName) { ReleaseFilter(); if (inName) { MultiByteToWideChar(CP_ACP, 0, inName, -1, mName, 256); } if (mGraph && inFilter) { if (SUCCEEDED(mGraph->AddFilter(inFilter, mName))) { mFilter = inFilter; mFilter->AddRef(); // Add extra refercence count return TRUE; } } return FALSE; }

特别值得注意的是

IBaseFilter* pFlt = UDsUtils::CreateCompressor(TRUE,  "DivX 5.0.2 Codec");  DivX 5.0.2 Codec很重要因为

代码会遍历系统中所有的视频压缩filter 找到后匹配 friendlyname    在这里 就是 DivX 5.0.2 Codec 

如下:

WideCharToMultiByte(CP_ACP, 0, name.bstrVal, -1, friendlyName, 256, NULL, NULL); if (strcmp(friendlyName, inFriendlyName) == 0) { moniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&hardwareFilter); }

你可能感兴趣的:(filter,null,Codec)