Unalbe to add "FFDshow Video Decoder" filter to graph


  • I can add "FFDshow Video Decoder" filter to graph in graphedit: I can select it from directshow filter list and insert it, or I can directly render a MPEG-2 video file and it will be automatically added.
    Both methods will add "FFDshow Video Decoder" filter to graph.

    But I can not do that by code.
    I have tried the following two methods, but neither of them works.
    Someone says it is because of the interface IBaseFilter, but I don't really understand what it means.

    ==Method 1: ==
    Code Snippet

    EXTERN_C const GUID DECLSPEC_SELECTANY CLSID_FFDshowDecoder = { 0x04FE9017, 0xF873, 0x410E, { 0x87, 0x1E, 0xAB, 0x91, 0x66, 0x1A, 0x4E, 0xF7 } };

    IBaseFilter * pFFDshowDecoder = NULL;
    hr = CoCreateInstance(CLSID_FFDshowDecoder, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void **)&pFFDshowDecoder);
    hr = mGraph->AddFilter(pFFDshowDecoder, L"FFDshow Video Decoder");

    ==Method 2: ==
    Code Snippet

    //Create an enumerator
    ICreateDevEnum *pCreateDevEnum;
    hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **)&pCreateDevEnum);

    IEnumMoniker *pEnumCat;
    hr = pCreateDevEnum->CreteClassEnumerator(CLSID_LegacyAmFilterCategory, &pEnumCat, 0);
    IMoniker *pMoniker;
    IBaseFilter *pFFDshowDecoderFilter;
    ULONG cFetched;
    while(hr = pEnumCat->Next(1, &pMoniker, &cFetched), hr == S_OK){
        IPropertyBag *pPropBag;
        hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void**)&pPropBag);
            VARIANT var;
            var.vt = VT_BSTR;
            hr = pPropBag->Read(L"FriendlyName", &var, 0);
            if (lstrcmpiW(var.bstrVal, L"ffdshow Video Decoder") == 0){
                // This is the right filter.
                pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pFFDshowDecoderFilter);
                hr = mGraph->AddFilter(pFFDshowDecoderFilter, L"ffdshow Video Decoder - m2v");

            //make sure you release everything

    Any help appreciated. Thanks in advance!

    Tuesday, September 25, 2007 6:22 AM


All replies