How to play movie into Irrlicht window from file.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

How to play movie into Irrlicht window from file.

Post by xterminhate »

First of all, Magic2d Library (thank Emil Halim) provides a way to render to texture a movie (video only).

In my project (see french H.E.L.P.), I need to display a trailer at the begining of the game (with video and pefectly synchronised sound) into the irrlicht render window. I give you my way. Hope that may help Irrlicht users.

In fact, it is based on DirectShow sample code from MSDN (I don't even understand how it works in detail). Skilled DirectShow developers will probably extend the few possibilities, I suggested here after.

Important : You must create an irrlicht device. Movie is just displayed over the irrlicht viewport without transparency. And you can adjust the size and the position of the "movie render window".


INITIALISATION :

Code: Select all

// find "irrlicht render window" handler
irr::video::SExposedVideoData exposedData = driver->getExposedVideoData();
HWND hWnd = reinterpret_cast<HWND>(exposedData.D3D9.HWnd);

// init DirectShow pointers
IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent   *pEvent = NULL;
IMediaSeeking  * pSeek = NULL;
IVideoWindow  *pVW ;

// init COM client/server
CoInitialize(NULL);
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);

// get DirectShow interfaces
pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
pGraph->QueryInterface(IID_IMediaSeeking, (void **)&pSeek);
pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVW);

// init render (passing movie file)
pGraph->RenderFile(L"trailer.avi", NULL);

// make parent
pVW->put_Owner((OAHWND)hWnd);

// Adjust "movie render window" to "irrlicht render window" dimensions
RECT grc;
GetClientRect(hWnd, &grc);
pVW->SetWindowPosition(0,0, grc.right, grc.bottom);
pVW->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);

// keep focus "irrlicht render window"
SetFocus(hWnd);
SetForegroundWindow(hWnd);
MAKE VISIBLE:

Code: Select all

// display "movie render window"
pVW->put_Visible(OATRUE);
//pVW->put_Owner((OAHWND)hWnd);
MAKE INVISIBLE:

Code: Select all

// hiding "movie render window"
pVW->put_Visible(OAFALSE);
//pVW->put_Owner(NULL);
PLAY/RESUME PLAYBACK:

Code: Select all

// (re)start movie
pControl->Run();
STOP PLAYBACK:

Code: Select all

// stop movie
pControl->Stop();
REWIND PLAYBACK:

Code: Select all

// (re)start movie
REFERENCE_TIME rtNow = 0;
pSeek->SetPositions( &rtNow, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning );
DESTRUCTION

Code: Select all

// release
pVW->put_Owner(NULL);
pVW->Release();
pSeek->Release();
pControl->Release();
pEvent->Release();
pGraph->Release();
CoUninitialize();
To compile and build, you need : Direct X SDK and Windows Platform SDK.

Include headers : dshow.h, mmstream.h, amstream.h, ddstream.h.

Link with libs : uuid, ole32, user32, strmiids, and .... have a guess : irrlicht ! :D

I update this post when I have found enough time to build an easy to use c++ class for irrlicht.....But I have a "smooth first and third person" camera scene node to update and post here, before ! 8)

Xterm-in'Hate
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
Guest

Post by Guest »

i tried ur code but got linking errors

Code ::

Code: Select all

#include <irrlicht.h>
#include <dshow.h> 
#include <mmstream.h> 
#include <amstream.h> 
#include <ddstream.h> 


#pragma comment (lib , "irrlicht.lib")
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


int main()
{
// global declration of Irrlicht interfaces
IrrlichtDevice* device;
IVideoDriver*   driver;
device = createDevice(EDT_OPENGL, dimension2d<s32>(640, 480), 32);
driver = device->getVideoDriver();
irr::video::SExposedVideoData exposedData = driver->getExposedVideoData(); 
HWND hWnd = reinterpret_cast<HWND>(exposedData.D3D9.HWnd); 
// init DirectShow pointers 
IGraphBuilder *pGraph = NULL; 
IMediaControl *pControl = NULL; 
IMediaEvent   *pEvent = NULL; 
IMediaSeeking  * pSeek = NULL; 
IVideoWindow  *pVW ; 
// init COM client/server 
CoInitialize(NULL); 
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); 
// get DirectShow interfaces 
pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); 
pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); 
pGraph->QueryInterface(IID_IMediaSeeking, (void **)&pSeek); 
pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVW); 

// init render (passing movie file) 
pGraph->RenderFile(L"trailer.avi", NULL); 

// make parent 
pVW->put_Owner((OAHWND)hWnd); 

// Adjust "movie render window" to "irrlicht render window" dimensions 
RECT grc; 
GetClientRect(hWnd, &grc); 
pVW->SetWindowPosition(0,0, grc.right, grc.bottom); 
pVW->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS); 

// keep focus "irrlicht render window" 
SetFocus(hWnd); 
SetForegroundWindow(hWnd); 
return false;
}

Errors ::
Linking...
main.obj : error LNK2019: unresolved external symbol __imp__SetForegroundWindow@4 referenced in function _main
main.obj : error LNK2019: unresolved external symbol __imp__SetFocus@4 referenced in function _main
main.obj : error LNK2019: unresolved external symbol __imp__GetClientRect@8 referenced in function _main
main.obj : error LNK2019: unresolved external symbol _IID_IVideoWindow referenced in function _main
main.obj : error LNK2019: unresolved external symbol _IID_IMediaSeeking referenced in function _main
main.obj : error LNK2019: unresolved external symbol _IID_IMediaEvent referenced in function _main
main.obj : error LNK2019: unresolved external symbol _IID_IMediaControl referenced in function _main
main.obj : error LNK2019: unresolved external symbol __imp__CoCreateInstance@20 referenced in function _main
main.obj : error LNK2019: unresolved external symbol _CLSID_FilterGraph referenced in function _main
main.obj : error LNK2019: unresolved external symbol _IID_IGraphBuilder referenced in function _main
main.obj : error LNK2019: unresolved external symbol __imp__CoInitialize@4 referenced in function _main
They r the linking errors , how to deal with them
utimagus
Posts: 17
Joined: Fri May 26, 2006 2:55 pm

Post by utimagus »

looks like you are not linking against the directx libraries...
Post Reply