Archived

This topic is now archived and is closed to further replies.

computer_guy

playing AVI's in a game

Recommended Posts

How would I go about playing AVIs in my 2d game. It is written in C++ and uses directX 8.1 and DirectDraw7 for the graphics. Could someone show me where I could find a tutorial or some code or something? Thanks in advance.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use DirectShow to play avi file on directdraw7 surface, render avi to offscreen surface then blt it to backbuffer, then flip screen/ bacbbuffor, exaples are in msdn, i don''t have my source code right now in work sorry

Share this post


Link to post
Share on other sites
Would any one happen to know If there is like a DirectShow engine that will do all the hard coding for me. I know It probably sounds like I''m really lazzy but I really need to play an AVI in my game i''m currently writting. And I''m pretty new to programming graphics.

Thankyou for your time.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The direct draw example using direct show is pretty simple to use, everything is all wrapped up for you. It would take a matter of a half hour at most to comment out the text drawing, and overlay functionality and then copy & paste into your game. Not that difficult at all.

If you want something even simpler look at the direct show "cut scene" sample.

Share this post


Link to post
Share on other sites
There''s some tutorial on gamedev.net about playing AVIs in DirectDraw or something similar. It''s a simple AVI loader that keeps copying frames from the avi to the backbuffer/whatever_you_use.

Maybe you can use that?

Share this post


Link to post
Share on other sites
Well in case you want a fast solution, in which you don''t want to programm much and its just an intro avi. You could just use MCI which will only take you about 4-10 lines of code.
Offcourse its not the best solution just wanted to mention it.

-CProgrammer

Share this post


Link to post
Share on other sites
MCI = MediaControlInterface.
Well i dont remember exactly and i dont have access to my older projects at the moment but heres what i remember.

Change the resolution with directx.
Use MCIWndCreate to load the avi and create the MCI wnd(avi must be size of screen res.)
Use MCIWndPlay to play back

Check your MSDN for them.

Use the following in the win32 message handler to check whether the avi is done.

case MCIWNDM_NOTIFYMODE:
if((int)lParam == MCI_MODE_STOP)
{
VideoStop();
}
break;

I think you must play right after the resolution change and then after closing MCI continue with the directx stuff.

-CProgrammer

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you can play avis using directshow so easily
i made a class to play cutscenes before i cant find it
ill be making it again soon
its really easy to use directshow

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
im unsuccessful in locating it
i thought i burned it to a disc but i cant find it

I have 5 more disc too look at

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I found it

just gotta get it together here and Ill post it

Share this post


Link to post
Share on other sites
Is there an "easy" way to play AVI files without resorting to DX7 DirectDraw? I''m using DX9. I know I could use the new VMR9 to render onto a texture, but not only is that complex to setup, texture size is way too limiting. Any other ideas?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ok i got it working correctly now

two files ill post in a moment

testing

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
it appears to work ok now
having some trouble intercepting the messages
it should start up a video play fullscreen and then close out

here is how to use it

CVideo IntroVid;
IntroVid.Play(L"file.avi";


class CVideo
{

protected:

WNDCLASSEX m_wcEx;
HWND m_hWnd;

IGraphBuilder* m_pGraphBuilder;
IMediaControl* m_pMediaControl;
IVideoWindow* m_pVideoWindow;
IMediaEvent* m_pMediaEvent;

protected:

static LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

BOOL InitWindow();
VOID CleanupWindow();

HRESULT GetInterfaces();
HRESULT CleanupInterfaces();

HRESULT PlayMedia(const unsigned short* FileName);

public:

CVideo();
~CVideo();

HRESULT Play(const unsigned short* FileName);

};



#include <dshow.h>
#include "video.h"

HRESULT CVideo::Play(const unsigned short* FileName)
{

HRESULT hr = S_OK;

// Hide the mouse cursor.

ShowCursor(FALSE);

// Create the hidden window to field keyboard input.

if( !InitWindow() )
return E_FAIL;

// Get DirectShow interfaces.

hr = GetInterfaces();
if( FAILED(hr) )
{
CleanupWindow();
return hr;
}

// Play the Movie.

hr = PlayMedia(FileName);

// Cleanup.

CleanupInterfaces();
CleanupWindow();

// Show the mouse cursor.

ShowCursor(TRUE);

return hr;
}

HRESULT CVideo::PlayMedia(const unsigned short* FileName)
{

HRESULT hr = S_OK;

// Allow DirectShow to create the FilterGraph for this media file.

hr = m_pGraphBuilder->RenderFile( FileName, NULL );
if( FAILED(hr) )
{
return hr;
}

// Set the message drain of the video window to point to our hidden window.

hr = m_pVideoWindow->put_MessageDrain( (OAHWND)m_hWnd );
if( FAILED(hr) )
{
return hr;
}

// Set fullscreen.

hr = m_pVideoWindow->put_FullScreenMode(OATRUE);
if( FAILED(hr) )
{
return hr;
}

// Display first frame of the movie.

hr = m_pMediaControl->Pause();
if( FAILED(hr) )
{
return hr;
}

// Start playback.

hr = m_pMediaControl->Run();
if( FAILED(hr) )
{
return hr;
}

// Enter a loop of checking for events and sampling keyboard input.

while( 1 )
{
MSG Msg;
long lEventCode, lParam1, lParam2;

// Has there been a media event?

hr = m_pMediaEvent->GetEvent(&lEventCode, &lParam1, &lParam2, 0);
if( hr != E_ABORT )
{
// Is this the end of the movie?

if( lEventCode == EC_COMPLETE )
{
return S_OK;
}

// Free the media event resources.

m_pMediaEvent->FreeEventParams(lEventCode, lParam1, lParam2);
}

// Give system threads time to run.

Sleep(100);

// Check and process window messages.

if( PeekMessage(&Msg, m_hWnd, 0, 0, PM_REMOVE) )
{
if( Msg.message == WM_QUIT )
{
m_pMediaControl->Stop();
return S_OK;
}
else
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
}

return S_OK;
}

HRESULT CVideo::GetInterfaces()
{

HRESULT hr = S_OK;

// Instantiate filter graph interface.

hr = CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **)&m_pGraphBuilder );
if( FAILED(hr) )
{
CleanupInterfaces();
return hr;
}

// Get interfaces to control playback & screensize.

hr = m_pGraphBuilder->QueryInterface( IID_IMediaControl, (void **)&m_pMediaControl );
if( FAILED(hr) )
{
CleanupInterfaces();
return hr;
}
hr = m_pGraphBuilder->QueryInterface( IID_IVideoWindow, (void **)&m_pVideoWindow );
if( FAILED(hr) )
{
CleanupInterfaces();
return hr;
}

// Get interface to allow the app to wait for completion of playback.

hr = m_pGraphBuilder->QueryInterface( IID_IMediaEventEx, (void **)&m_pMediaEvent );
if( FAILED(hr) )
{
CleanupInterfaces();
return hr;
}

return S_OK;
}

HRESULT CVideo::CleanupInterfaces()
{

if( m_pGraphBuilder )
{
if( m_pVideoWindow )
m_pVideoWindow->Release();

if( m_pMediaEvent )
m_pMediaEvent->Release();

if( m_pMediaControl )
m_pMediaControl->Release();

m_pGraphBuilder->Release();
}

return S_OK;
}

LRESULT CVideo::WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hWnd, Msg, wParam, lParam);
}

BOOL CVideo::InitWindow()
{

m_wcEx.cbSize = sizeof(WNDCLASSEX);
m_wcEx.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
m_wcEx.lpfnWndProc = this->WindowProc;
m_wcEx.cbClsExtra = 0;
m_wcEx.cbWndExtra = 0;
m_wcEx.hInstance = GetModuleHandle(NULL);
m_wcEx.hIcon = 0;
m_wcEx.hCursor = 0;
m_wcEx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
m_wcEx.lpszMenuName = NULL;
m_wcEx.lpszClassName = "DirectShow Video Window";
m_wcEx.hIconSm = NULL;

if( !RegisterClassEx(&m_wcEx) )
return FALSE;

m_hWnd = CreateWindowEx( 0, m_wcEx.lpszClassName, "DirectShow",
0, 0, 0, 0, 0, NULL, NULL, m_wcEx.hInstance, NULL );
if( !m_hWnd )
{
UnregisterClass(m_wcEx.lpszClassName, m_wcEx.hInstance);
return FALSE;
}

return TRUE;
}

VOID CVideo::CleanupWindow()
{
DestroyWindow(m_hWnd);
UnregisterClass(m_wcEx.lpszClassName, m_wcEx.hInstance);
}

CVideo::CVideo()
{
ZeroMemory(&m_wcEx, sizeof(WNDCLASSEX));
m_hWnd = NULL;

m_pGraphBuilder = NULL;
m_pMediaControl = NULL;
m_pVideoWindow = NULL;
m_pMediaEvent = NULL;
}

CVideo::~CVideo()
{
ZeroMemory(&m_wcEx, sizeof(WNDCLASSEX));
m_hWnd = NULL;

m_pGraphBuilder = NULL;
m_pMediaControl = NULL;
m_pVideoWindow = NULL;
m_pMediaEvent = NULL;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
oh ya make sure you have initialised COM

CoInitialize(NULL);

Share this post


Link to post
Share on other sites
I re-pasted the code in and got rid of a lot of errors. I put the class at the top this time. But I get two linker errors now.

The errors are as follows;

error LNK2001: unresolved external symbol _IID_IGraphBuilder
Debug/Bar_Bandit2.exe : fatal error LNK1120: 1 unresolved externals

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
put the first box in a file called video.h
put the second box in a file called video.cpp

link with strmiids.lib

Share this post


Link to post
Share on other sites
it comes up with 15 linker errors stating that there are multiple defined symbols found. I can''t seem to find where they are defined in your code. Sorry for all the trouble I have made for you.


error LNK2005: _IID_IKsPropertySet already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IReferenceClock already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDrawColorControl already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDrawClipper already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDrawPalette already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDrawSurface7 already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDrawSurface4 already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDrawSurface3 already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDrawSurface2 already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDrawSurface already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDraw2 already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _IID_IDirectDraw already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _CLSID_DirectDrawClipper already defined in bandit2.obj
strmiids.lib(strmiids.obj) : error LNK2005: _CLSID_DirectDraw already defined in bandit2.obj
Debug/Bar_Bandit2.exe : fatal error LNK1169: one or more multiply defined symbols found

Share this post


Link to post
Share on other sites