directshow render 示例代码

#include <dshow.h>

 

void main(void)

{

    IGraphBuilder *pGraph = NULL;

    IMediaControl *pControl = NULL;

    IMediaEvent   *pEvent = NULL;

 

    // Initialize the COM library.

    HRESULT hr = CoInitialize(NULL);

    if (FAILED(hr))

    {

        printf("ERROR - Could not initialize COM library");

        return;

    }

 

    // Create the filter graph manager and query for interfaces.

    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 

                        IID_IGraphBuilder, (void **)&pGraph);

    if (FAILED(hr))

    {

        printf("ERROR - Could not create the Filter Graph Manager.");

        return;

    }

 

    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);

    hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

 

       IBaseFilter* pFilter;

       pGraph->AddSourceFilter(L"C://1.avi",L"test",&pFilter);

 

       IPin * pPin;

       IEnumPins *pEnum = NULL;

       pFilter->EnumPins(&pEnum);

       while(pEnum->Next(1,&pPin,NULL)==S_OK)

       {

              PIN_DIRECTION PinDir;

              pPin->QueryDirection(&PinDir);

 

              if(PinDir == PINDIR_OUTPUT)

              {

                     IPin *pTemp;

                     if(SUCCEEDED(pPin->ConnectedTo(&pTemp)))

                     {

                            pTemp->Release();

                     }

                     else

                     {

                            pGraph->Render(pPin);  

                     }

              }

       }

    if (SUCCEEDED(hr))

    {

        // Run the graph.

        hr = pControl->Run();

        if (SUCCEEDED(hr))

        {

            // Wait for completion.

            long evCode;

            pEvent->WaitForCompletion(INFINITE, &evCode);

        }

    }

    pControl->Release();

    pEvent->Release();

    pGraph->Release();

    CoUninitialize();

}


经测试,代码可以顺利编译并播放指定的avi文件

你可能感兴趣的:(render,avi,directshow)