該是自己動手來寫的時候了,最簡單的代碼能突出重點。
自己建個win32項目,選擇空項目。
CMovie類來自于
Microsoft Platform SDK for Windows Server 2003 R2\Samples\Multimedia\DirectShow\VMR9\VMRPlayer\
中的vcdplyer.h,做了一點修改。
程序主體代碼用了
Direct3D Tutorial 3: Using Matrices的部分代碼。
截圖: 播放

不播放
項目配置:
#include <streams.h>
位于Microsoft Platform SDK for Windows Server 2003 R2\Samples\Multimedia\DirectShow\BaseClasses
鏈接:只有這三個d3d9.lib Strmiids.lib Quartz.lib
使用 Unicode 字符集
多線程調試 DLL (/MDd)核心代碼:
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
// Register the window class
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
L"D3D Tutorial", NULL };
RegisterClassEx( &wc );
// Create the application's window
g_hwnd = CreateWindow( L"D3D Tutorial", L"DShow CMovie Test",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
NULL, NULL, wc.hInstance, NULL );
g_pMovie = new CMovie(g_hwnd);
g_pMovie->OpenMovie(L"C:\\Program Files\\Microsoft Platform SDK for Windows Server 2003 R2\\Samples\\Multimedia\\DirectShow\\Media\\Video\\ruby.avi");
g_pMovie->PlayMovie();
// Initialize Direct3D
if( SUCCEEDED( InitD3D( g_hwnd ) ) )
{
// Show the window
ShowWindow( g_hwnd, SW_SHOWDEFAULT );
UpdateWindow( g_hwnd );
// Enter the message loop
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while(msg.message != WM_QUIT)
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
Render();
}
}
}
UnregisterClass( L"D3D Tutorial", wc.hInstance );
return 0;
}
視頻播放時d3d不渲染,不播放的時候才渲染
VOID Render()
{
if(g_pMovie->IsPlaying())
{
RECT rc;
::GetClientRect(g_hwnd, &rc);
g_pMovie->PutMoviePosition(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
g_pMovie->RepaintVideo(g_hwnd, ::GetDC(g_hwnd));
}
else
{
if( NULL == g_pd3dDevice )
return;
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// Rendering of scene objects can happen here
// End the scene
g_pd3dDevice->EndScene();
}
// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
}
代碼下載:
dshow.cmovie.rar
Reference:
DirectShow播放視頻
posted on 2008-12-24 00:25
七星重劍 閱讀(1382)
評論(0) 編輯 收藏 引用 所屬分類:
Game Graphics 、
IDE -- visual c++