我正在寻找一种在Windows XP/Vista机器上枚举所有视频编解码器的好方法.
我需要向用户呈现一组视频编解码器,包括压缩器和解压缩器.输出看起来像
Available Decoders DiVX Version 6.0 XVID Motion JPEG CompanyX's MPEG-2 Decoder Windows Media Video **Available Encoders** DiVX Version 6.0 Windows Media Video
我遇到的问题是没有可靠的方法来捕获系统可用的所有解码器.例如:
您可以使用DirectShow枚举所有解压缩程序,但这不会告诉您有关压缩程序(编码器)的任何信息.
您可以枚举所有Video For Windows组件,但是没有迹象表明这些是编码器还是解码器.
DirectShow过滤器可以很好地完成这项工作(例如Motion JPEG过滤器),但没有迹象表明特定的DirectShow过滤器是"视频解码器".
有没有人使用任何Windows API找到解决此问题的通用解决方案?Windows Vista Media Foundation API是否解决了这些问题?
这最好由DirectShow处理.
DirectShow目前是平台SDK的一部分.
HRESULT extractFriendlyName( IMoniker* pMk, std::wstring& str ) { assert( pMk != 0 ); IPropertyBag* pBag = 0; HRESULT hr = pMk->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag ); if( FAILED( hr ) || pBag == 0 ) { return hr; } VARIANT var; var.vt = VT_BSTR; hr = pBag->Read(L"FriendlyName", &var, NULL); if( SUCCEEDED( hr ) && var.bstrVal != 0 ) { str = reinterpret_cast( var.bstrVal ); SysFreeString(var.bstrVal); } pBag->Release(); return hr; } HRESULT enumerateDShowFilterList( const CLSID& category ) { HRESULT rval = S_OK; HRESULT hr; ICreateDevEnum* pCreateDevEnum = 0; // volatile, will be destroyed at the end hr = ::CoCreateInstance( CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, reinterpret_cast ( &pCreateDevEnum ) ); assert( SUCCEEDED( hr ) && pCreateDevEnum != 0 ); if( FAILED( hr ) || pCreateDevEnum == 0 ) { return hr; } IEnumMoniker* pEm = 0; hr = pCreateDevEnum->CreateClassEnumerator( category, &pEm, 0 ); // If hr == S_FALSE, no error is occured. In this case pEm is NULL, because // a filter does not exist e.g no video capture devives are connected to // the computer or no codecs are installed. assert( SUCCEEDED( hr ) && ((hr == S_OK && pEm != 0 ) || hr == S_FALSE) ); if( FAILED( hr ) ) { pCreateDevEnum->Release(); return hr; } if( hr == S_OK && pEm != 0 ) // In this case pEm is != NULL { pEm->Reset(); ULONG cFetched; IMoniker* pM = 0; while( pEm->Next(1, &pM, &cFetched) == S_OK && pM != 0 ) { std::wstring str; if( SUCCEEDED( extractFriendlyName( pM, str ) ) { // str contains the friendly name of the filter // pM->BindToObject creates the filter std::wcout << str << std::endl; } pM->Release(); } pEm->Release(); } pCreateDevEnum->Release(); return rval; }
以下调用枚举控制台的所有视频压缩器:
enumerateDShowFilterList( CLSID_VideoCompressorCategory );
MSDN页面过滤器类别列出了所有其他"官方"类别.
我希望这对你来说是一个很好的起点.