Playing AVI file in irrlicht - IMPOSSIBLE!

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
fleven_2001
Posts: 6
Joined: Mon Apr 16, 2007 9:51 am
Location: Perth - Australia
Contact:

Playing AVI file in irrlicht - IMPOSSIBLE!

Post by fleven_2001 »

Using code taken from a previous post, i have constructed a small app that will attempt to play an avi... unfortunately it just doesn't display anything, and so far all code i have tried has failed...

i have also tried irrExtensions.. but i do not use dev, nor do i want to have to recompile irrlicht.dll, so if anyone has been able to find, or construct a separate avi player using irrlicht (preferably using the texturing method, allowing me to apply it to a mesh) i would greatly appreciate it. so far my code looks like so:

Code: Select all


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

// Irrlicht Namespaces

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif



using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


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


static GUID MY_CLSID_AMMultiMediaStream={0x49C47CE5,0x9BA4,0x11D0,0x82,0x12,0x00,0xC0,0x4F,0xC3,0x2C,0x45};
static GUID MY_IID_IAMMultiMediaStream={0xBEBE595C,0x9A6F,0x11D0,0x8F,0xDE,0x00,0xC0,0x4F,0xD9,0x18,0x9D};
static GUID MY_MSPID_PrimaryVideo={0xA35FF56A,0x9FDA,0x11D0,0x8F,0xDF,0x00,0xC0,0x4F,0xD9,0x18,0x9D};
static GUID MY_IID_IDirectDrawMediaStream={0xF4104FCE,0x9A70,0x11D0,0x8F,0xDE,0x00,0xC0,0x4F,0xD9,0x18,0x9D}; 
static GUID MY_MSPID_PrimaryAudio={0xA35FF56B,0x9FDA,0x11D0,0x8F,0xDF,0x00,0xC0,0x4F,0xD9,0x18,0x9D};

class TMovie
 {
         IAMMultiMediaStream*     pAMStream;
         IMediaStream*            pPrimaryVidStream;
         IDirectDrawMediaStream*  pDDStream;
         IDirectDrawStreamSample* pSample;
         IDirectDrawSurface*      pSurface;
         RECT                     Movie_rect;
         LONG                     MoviePitch;
         void*                    MovieBuffer;
         DWORD                    time;
         DWORD                    oldtick;
     
     public:   
           TMovie()
            {
               CoInitialize(0);
               pAMStream         = 0;
               pPrimaryVidStream = 0; 
               pDDStream         = 0;   
               pSample           = 0;
               pSurface          = 0;
               time              = 0;
            }
               
           ~TMovie()
            {
                pPrimaryVidStream->Release();
                pDDStream->Release();
                pSample->Release();
                pSurface->Release();
                pAMStream->Release();
                CoUninitialize();
            }
           
           void LoadMovie(char* filename)
            {
                WCHAR buf[512];
                MultiByteToWideChar(CP_ACP,0,filename,-1,buf,512);
                CoCreateInstance(MY_CLSID_AMMultiMediaStream,0,1,MY_IID_IAMMultiMediaStream,(void**)&pAMStream);
                pAMStream->Initialize((STREAM_TYPE) 0, 0, NULL);
                pAMStream->AddMediaStream( 0, &MY_MSPID_PrimaryVideo, 0, NULL);
                pAMStream->OpenFile(buf,4);
                pAMStream->GetMediaStream( MY_MSPID_PrimaryVideo, &pPrimaryVidStream);
                pPrimaryVidStream->QueryInterface(MY_IID_IDirectDrawMediaStream,(void**)&pDDStream);
                pDDStream->CreateSample(0,0,0,&pSample);
                pSample->GetSurface(&pSurface,&Movie_rect);
                pAMStream->SetState((STREAM_STATE)1);
            }
           
           void NextMovieFrame()
            {
               if(GetTickCount()-oldtick < time)return ;
               oldtick = GetTickCount(); 
               pSample->Update( 0, NULL, NULL, 0);
            }
           
           int MovieWidth() { return (Movie_rect.right - Movie_rect.left);}
           
           int MovieHeight() { return (Movie_rect.bottom - Movie_rect.top);} 
           
           void DrawMovie(int x,int y,ITexture* Buf)
            {   
                void* pBits = Buf->lock();
                LONG  Pitch = Buf->getPitch(); 
                DDSURFACEDESC  ddsd;
                ddsd.dwSize=sizeof(DDSURFACEDESC);
                pSurface->Lock( NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT , NULL);
                int wmin=(Pitch<ddsd.lPitch)?Pitch:ddsd.lPitch;
                for(int h=0; h<ddsd.dwHeight; h++)
                     memcpy((BYTE*)pBits+((y+h)*Pitch)+x*4,(BYTE*)ddsd.lpSurface+h*ddsd.lPitch,wmin);
                pSurface->Unlock(NULL);
                Buf->unlock();
            } 
           
          void SetMovieFPS(int fps)
            {
                time = fps;
            }           
           
 } ;   

 int main()
 {

    IrrlichtDevice* irrDevice   = createDevice(EDT_OPENGL, dimension2d<s32>(640, 
				480), 32, false, false, false, 0);
    IVideoDriver*   irrVideo    = irrDevice->getVideoDriver();
    ISceneManager*  irrSceneMgr = irrDevice->getSceneManager();
	IGUIEnvironment* m_guienv = irrDevice->getGUIEnvironment();

    TMovie* movie = new TMovie;
movie->LoadMovie("Internetisforporn.avi");
movie->SetMovieFPS(25);

ITexture* movTxtr;
irrVideo->setTextureCreationFlag(ETCF_ALWAYS_32_BIT , TRUE);
irrVideo->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, FALSE);
movTxtr = irrVideo->addTexture(dimension2d<s32>(512,256),"imovie");

 while(irrDevice->run())
  {
     irrVideo->beginScene(true, true, SColor(0,200,200,200));
                  movie->NextMovieFrame();
                  movie->DrawMovie(0,0,movTxtr);
                  irrSceneMgr->drawAll();
      irrVideo->endScene();
  } 
 

    irrDevice->drop();

    return 0;
}    
and i cant for the life of me figure out what i am doing wrong...

Please help... Thankyou in advance.
Steve.


EDIT::

i have also tried attaching the texture to a IGUIImage Element, and also using the draw2d method, all to no avail...!!!
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

I don't see the bug in this one currently, but there are some other movie playing code snipplets in this forum, maybe you can try one of those.

I wrote once some movie play myself for irrlicht, maybe I can publish this in the near future and maintain it. It would also have sound playback, because it works together with irrKlang. :)
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I had absolutely no problem using "evo"'s AVI player from the "play movie in texture" thread. Look for his last release in the zip file that includes sound. Since then I have added fast forward, slow forward, fast reverse, slow reverse etc that change the pitch of the sound to match the movie. Its pretty cool and I didnt think it will be possible with irrlicht, but I managed after some hard thinking.

Anyway, you haven'nt really told us the problem, if you have an error than maybe we can help you.

A few possible solutions:

Draw movie after the scenemanager.

Use a different movie.

Look in the thread i mentioned and use "evo"'s avi player which uses vfw32.lib. (Video For Windows). OR if you are in linux maybe the linux one will work but I have not tried it so dont complain if it doesnt :P

Cheers
fleven_2001
Posts: 6
Joined: Mon Apr 16, 2007 9:51 am
Location: Perth - Australia
Contact:

Post by fleven_2001 »

G-day all... i have been using evo's player, but even after adding all of the dependencies, it will crash when trying to play...

if anyone knows of a FULL WORKING AVI PLAYER on the forums, i would greatly appreciate it...

also Thankyou all for your quick replies!
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

It will crash if the AVI resolution is too big, or the codec is incompatible. I have tested the example movie that comes with IrrExtensions and that one works fine. A good program for editing other movies to work with it is VirtualDub. Make them CinePak Codec and try to keep the height resolution below 400. The resolution of the example movie I mentioned is a good example.
evo
Posts: 96
Joined: Mon Jun 27, 2005 6:46 pm
Location: The Netherlands

Post by evo »

Hi fleven_2001,

I tried running your code sample. Under ms visual studio it runs without problems. Under devc it crashes for me also. Strangely enough when you remove the 2 setTextureCreationFlag lines it runs fine.

However, as you indicated, you do need an output for your texture. Like a textured object. Also I found that you need to load at least 2 objects for the movie class to operate properly. See this post: http://irrlicht.sourceforge.net/phpBB2/ ... c&start=31
This thread is getting a lot of hits. Maybe it's time to move it to faq-forum.

Anyway it is nice to see that my avi code is being used.
@blindside: any chance that you are going to post your modifications ? Or maybe you already have.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Yes I also had to remove the texture creation flags also to get it working. The problem was that the mipmapping makes it look screwy from a far distance, I have no found a solution for this yet.
Kalda
Posts: 47
Joined: Wed Aug 23, 2006 1:38 pm
Location: Prostejov, Czech Republic
Contact:

Post by Kalda »

Hi. I've created DLL which can play AVI with Direct3D9 Driver.
Look at http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=21274.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

So this plays an AVI movie in a texture. So that could be used to have like a TV in a game running while the player moves around?
TheQuestion = 2B || !2B
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

This plays movies in Irrlicht:

http://www.freewebs.com/bcxgl/index.htm
-------------------------------------
IrrLua - a Lua binding for Irrlicht
http://irrlua.sourceforge.net/
arnir
Competition winner
Posts: 154
Joined: Sat Jan 20, 2007 4:36 pm
Location: Czech Republic

Post by arnir »

BlindSide wrote:I had absolutely no problem using "evo"'s AVI player from the "play movie in texture" thread. Look for his last release in the zip file that includes sound. Since then I have added fast forward, slow forward, fast reverse, slow reverse etc that change the pitch of the sound to match the movie. Its pretty cool and I didnt think it will be possible with irrlicht, but I managed after some hard thinking.

Anyway, you haven'nt really told us the problem, if you have an error than maybe we can help you.

A few possible solutions:

Draw movie after the scenemanager.

Use a different movie.

Look in the thread i mentioned and use "evo"'s avi player which uses vfw32.lib. (Video For Windows). OR if you are in linux maybe the linux one will work but I have not tried it so dont complain if it doesnt :P

Cheers
which libraries are you using? I am trying to compile it (dev c++) but i still have some linker errors:

Code: Select all

  [Linker error] undefined reference to `AVIFileInit@0' 
  [Linker error] undefined reference to `AVIFileOpenA@16' 
etc

thx

I try every source code in this forum but any work. i want only play some movie huaaaa :evil:
programmer is bad designer
designer is bad programmer
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

note the date of the posts there, thats a long time.
Post Reply