1. Download and install Visual Studio 2010 express (free) on your PC.


2. Download and install Microsoft DirectX 9.0 SDK Update (Summer 2004)

    which contains DirectShow

    P.S. After DirectX 9.0b, DirectShow has been moved to Windows Platform SDK.

    P.S. Other DirectX versions which include DirectShow are also suitable.

    P.S. In this article, DirectX was installed in C:\Program Files\DirectX


3.To get strmbasd.lib (in DEBUG & RELEASE modes),

   build baseclasses.sln in ./Samples/C++/DirectShow/BaseClasses 

   You may encounter many errors during this step:


   3.1 ctlutil.h:

      "operator=(LONG);" to "COARefTime& operator=(LONG);"

   3.2 wxdebug.cpp:

      "static g_dwLastRefresh = 0;" to "static int g_dwLastRefresh = 0;"

   3.3 winutil.cpp:

      "for (Count = PalLoCount;INT(Count) < min(PalHiStart,iColours);Count++) {"

        to "for (int Count = PalLoCount;INT(Count) < min(PalHiStart,iColours);Count++) {"

   3.4 outputq.cpp

       Add the line long iDone = 0; just before the 

       "for (iDone = 0;iDone < nSamples || (m_nBatched != 0 && m_bSendAnyway);"

   3.5 Errors at 

       "typedef void *PVOID;  typedef void *POINTER_64 PVOID64;"

       Add "#define POINTER_64 __ptr64" before them

   3.6 Others:

      Google them or Refer to 

      http://blog.csdn.net/yuanbingster/article/details/5573141

      http://blog.csdn.net/Amy_1007/article/details/5574607

      http://blog.xuite.net/miinyuan/blog/23556251


4. New a Project for DirectShow

   

   4.1 Set Project->Properties->Configuration Properties->VC++ Directories->Include Directories

      C:/Program Files/DirectX/Samples/C++/DirectShow/BaseClasses

      C:/Program Files/DirectX/Include

   4.2 Set Project->Properties->Configuration Properties->VC++ Directories->Library Directories

      C:/Program Files/DirectX/Samples/C++/DirectShow/BaseClasses/Debug

      C:/Program Files/DirectX/Samples/C++/DirectShow/BaseClasses/Release

      C:/Program Files/DirectX/Lib

   4.3 Include header files

      #include <dshow.h> // for all DirectShow applications

      #include <streams.h> // for DirectShow Base Class

   4.4 Import library

      (a) Add #pragma comment(lib,"strmbasd.lib") in header file

      (b) Set Project->Properties->Configuration Properties->Linker->Command Line

            ->Additional Options: strmbasd.lib

   4.5 Notes

      (a) error in wxdebug.h: Add #include <tchar.h> and #define PTCHAR (TCHAR *) 

      (b) Error C1189: #error : Include <strsafe.h> after <tchar.h>,

           add #include <tchar.h> ahead of other header files

      (C) Failed to save the updated manifest to the file: Delete the Debug folder

           Ex: If you change (install, modify, unistall) the codec intsalled on the computer,

                 you may face this problem.


5. Sample Code for Playing a Video 

#include <dshow.h>
#include <streams.h>
#include <stdio.h>

#pragma comment(lib,"strmbasd.lib") // see 4.4 Import library

#define FILENAME L"D:\\TEST.avi"

void main()
{
      IGraphBuilder *pGraphBuilder = NULL;
      IMediaControl *pMediaControl = NULL;
      IMediaEvent *pMediaEvent = 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,
          IID_IGraphBuilder, (LPVOID *)&pGraphBuilder);

     if (FAILED(hr)){
          printf("ERROR - Could not create the Filter Graph Manager.");
          return;
     }

     hr = pGraphBuilder->QueryInterface(IID_IMediaControl, (LPVOID *)&pMediaControl);
     hr = pGraphBuilder->QueryInterface(IID_IMediaEvent, (void **)&pMediaEvent);

     // Build the graph.
     hr = pMediaControl->RenderFile(FILENAME);
     if (SUCCEEDED(hr))
     {
          // Run the graph.
          hr = pMediaControl->Run();
          if (SUCCEEDED(hr))
          {
               // Wait for completion.
               long evCode;
               pMediaEvent->WaitForCompletion(INFINITE, &evCode);

 

              // Note: Do not use INFINITE in a real application, because it
              // can block indefinitely.
          }
     }

     pMediaControl->Release();
     pMediaEvent->Release();
     pGraphBuilder->Release();
     CoUninitialize();
}


6. DirectShow Programming: 

    http://www.geekpage.jp/en/programming/directshow/

arrow
arrow
    文章標籤
    DirectShow Visual C++ 2010 Express
    全站熱搜
    創作者介紹
    創作者 trick 的頭像
    trick

    trick的部落格

    trick 發表在 痞客邦 留言(0) 人氣()