2014年1月24日 星期五

DirectShow coding 環境

(a)  使用visual studio c++ 2012

(b)  download  SDK ,
         http://www.microsoft.com/en-us/download/confirmation.aspx?id=3138
        (windows 7)

(c)
    in project must include Dshow.h file

(d) include library

    Strmiids.lib & Quartz.lib

    project --> 屬性
 
    set library path
   
 


Set library file 


    




DirectShow play avi example

// ConsoleApplication3.cpp : 定義主控台應用程式的進入點。
//

#include "stdafx.h"
#include "Dshow.h"



int _tmain(int argc, _TCHAR* argv[])
{
    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 0;
    }

    // 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 0;
    }

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

    // Build the graph. IMPORTANT: Change this string to a file on your system.
    hr = pGraph->RenderFile(L"C:\\Example.avi", NULL);
    if (SUCCEEDED(hr))
    {
        // Run the graph.
        hr = pControl->Run();
        if (SUCCEEDED(hr))
        {
            // Wait for completion.
            long evCode;
            pEvent->WaitForCompletion(INFINITE, &evCode);

            // Note: Do not use INFINITE in a real application, because it
            // can block indefinitely.
        }
    }
    pControl->Release();
    pEvent->Release();
    pGraph->Release();
    CoUninitialize();

    return 0;
}

沒有留言:

張貼留言