none
[Solved] How to Check if DirectShow Codec is installed for a given media file

    Question

  • Hello

    I use DirectShow to display some video file in a C++ (MFC) application and it works fine.


    I would like to check if the codecs required to render a video file are installed on the PC .
     

     Thanks for any clue to solve this issue

    TGMDev

    Solution:

    IGraphBuilder* pGraphBuilder;

    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_ALL, IID_IGraphBuilder, (void**)&pGraphBuilder);

    hr = pGraphBuilder->RenderFile(wszMediaFilePath, 0); 

    hr = pGraphBuilder->EnumFilters(&pEnum);

    Thanks to Roman and Michel 

    TGMDev

    www.tgmdev.be
    Friday, January 27, 2017 10:04 PM

Answers

  • You need to attempt a real rendering of the file. So after AddSourceFilter, you can get a ICaptureGraphBuilder2 interface (pBuilder),

    ICaptureGraphBuilder2 *pBuilder = NULL; hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&pBuilder); if (SUCCEEDED(hr)) { pBuilder->SetFiltergraph(pGraph);

    }

        hr =  pBuilder->RenderStream (NULL, NULL, pSource, NULL,NULL);


    then if it succeds, you can do as above and enumerate the filters.


    Michel Roujansky, http://www.roujansky.com

    Saturday, January 28, 2017 3:41 PM
    Moderator

All replies

  • Use the code from Using the System Device Enumerator with CLSID_LegacyAmFilterCategory for DirectShow Filters


    Friday, January 27, 2017 11:12 PM
  • If you look for specific filter, you can try to instantiate it using its CLSID (or using enumerator in certain cases, esp. with compressors).

    If you want to ensure that pipeline can be built using Intelligent connect with undefined installed filters, you can only build a test pipeline and make sure it builds with no failures.


    http://alax.info/blog/tag/directshow

    Saturday, January 28, 2017 8:05 AM
  • Thanks for your ansewer. I knew the code..

    It gives something like this: 

    MPEG Audio Decoder
    DV Splitter
    Video Mixing Renderer 9
    Haali Media Splitter (AR)
    Microsoft MPEG-2 Encoder
    ACM Wrapper
    Video Renderer
    MPEG-2 Video Stream Analyzer
    Line 21 Decoder
    Video Port Manager
    Video Renderer
    Haali Video Renderer
    VPS Decoder
    WM ASF Writer

    What I need to know is which one(s) is (are) required to render a given media file .  Or, say in an other way, what are the file extension handled by those different codecs ..

    TGMDev

    Saturday, January 28, 2017 12:51 PM
  • Hello

    Thanks for your answer ... 

    I tried this (error handling removed and code simplified) with wsrpath being the path to the video file to check...
     
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&pGraph);
     
    hr = pGraph->AddSourceFilter(wstrPath, NULL, &pSource);
     
    hr = pGraph->QueryInterface(IID_IFilterGraph2, (void**)&pGraph2);
     
    hr = pGraph2->EnumFilters(&pEnum);
     
    while (pEnum->Next(1, &pFilter, &cFetched) == S_OK)
        hr = pFilter->QueryFilterInfo(&FilterInfo);
     
    Here is the output. All is S_OK !!! But no filters are found. Output is empty . 
    EnumFilters  Wide Char File: c:\transit\corons.wmv
    EnumFilters  CoCreateInstance HResult: hr = 0x0 Descr: The operation completed successfully.
    EnumFiltersh   AddSourceFilter HResult: hr = 0x0 Descr: The operation completed successfully.
    EnumFiltersh   QueryInterface IID_IFilterGraph2 HResult: hr = 0x0 Descr: The operation completed successfully.
    EnumFiltersh   EnumFilters: hr = 0x0 Descr: The operation completed successfully.
    EnumFiltersh   QueryFilterInfo: hr = 0x0 Descr: The operation completed successfully. 

    TGMDev


    Saturday, January 28, 2017 12:58 PM
  • The fact that QueryFilterInfo succeeded means you do have a filter there.

    What I however originally suggested was to build a playback pipeline as close as possible to what you use for real playback (that is, you only use AddSourceFilter in the probing graph if you use it in the real one).


    http://alax.info/blog/tag/directshow

    Saturday, January 28, 2017 3:18 PM
  • You need to attempt a real rendering of the file. So after AddSourceFilter, you can get a ICaptureGraphBuilder2 interface (pBuilder),

    ICaptureGraphBuilder2 *pBuilder = NULL; hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&pBuilder); if (SUCCEEDED(hr)) { pBuilder->SetFiltergraph(pGraph);

    }

        hr =  pBuilder->RenderStream (NULL, NULL, pSource, NULL,NULL);


    then if it succeds, you can do as above and enumerate the filters.


    Michel Roujansky, http://www.roujansky.com

    Saturday, January 28, 2017 3:41 PM
    Moderator
  • Hello Roman

    Ok .. I finally found the right way...

    IGraphBuilder* pGraphBuilder;

    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_ALL, IID_IGraphBuilder, (void**)&pGraphBuilder);

    hr = pGraphBuilder->RenderFile(wszMediaFilePath, 0); 

    hr = pGraphBuilder->EnumFilters(&pEnum);

    Thanks for your help

    Thierry

    Saturday, January 28, 2017 3:51 PM
  • Hello Michel

    Following Roman's answer, I came to a similar solution:

    IGraphBuilder* pGraphBuilder;

    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_ALL, IID_IGraphBuilder, (void**)&pGraphBuilder);

    hr = pGraphBuilder->RenderFile(wszMediaFilePath, 0); 

    hr = pGraphBuilder->EnumFilters(&pEnum);

    Thanks for your interest and help

    Thierry

    Saturday, January 28, 2017 3:52 PM