Playing a Video

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
NotAnotherNun
Posts: 8
Joined: Fri Nov 21, 2008 1:10 am

Playing a Video

Post by NotAnotherNun »

Hello again all, I have been playing around with irrlicht and trying to implement the Playing a Video as Texture and have imported all the code, but I keep getting the error:

Unhandled exception at 0x00402d6a in VidTest.exe: 0xC0000005: Access violation writing location 0x04cf1000.

I have tried this on two different systems, but it doesn't work. Can anyone help?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

This looks like a job for Green Lantern, She-Ra, or possibly Ghost Rider.

How about you help us to help you? Post or upload your source somewhere, or at least provide us with a link to whereever you're getting it from. You're basically asking us to debug your source for you. Well, where is it?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
FreakNigh
Posts: 122
Joined: Thu Oct 19, 2006 7:31 am
Location: Orlando FL, USA
Contact:

Post by FreakNigh »

http://www.youtube.com/watch?v=5vvp-08y ... re=channel

It's not perfect but the CvIrrAviTexture does render an avi to a texture which is apart of the CvIrrCamController lib.

Example useing it..

Code: Select all

#include <irrlicht/irrlicht.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>

#include "CvIrrAviTexture.h"

using namespace irr;

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

IrrlichtDevice *device;
IVideoDriver* driver;
ISceneManager* smgr;

int main()
{
	device = createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16, false, false, false, 0);
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
   
	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
   
	//something for 3d reference
	IAnimatedMesh* mesh = smgr->getMesh("media/sydney.md2");
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation ( scene::EMAT_STAND );
		node->setMaterialTexture( 0, driver->getTexture("media/sydney.bmp") );
		node->setPosition(vector3df(10,10,-10));
	}
	
	//and some more
	device->getFileSystem()->addZipFileArchive("media/map-20kdm2.pk3");
	IAnimatedMesh* mesh2 = smgr->getMesh("20kdm2.bsp");
	ISceneNode* node2 = 0;
	if (mesh2)
		node2 = smgr->addOctTreeSceneNode(mesh2->getMesh(0), 0, -1, 128);
	if (node2)
		node2->setPosition(vector3df(-1300,-144,-1249));
	
	//our billboard
	IBillboardSceneNode* our_bill_node = smgr->addBillboardSceneNode(NULL, dimension2d<f32>(25.0f, 25.0f), vector3df(0,0,0));
	our_bill_node->setMaterialFlag(video::EMF_LIGHTING, false);
	
	//camera stuff
	ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
	camera->setPosition(vector3df(60,10,0));
	camera->setTarget(vector3df(0,0,0));
	
	//start the vid
	CvIrrAviTexture* cv_text_mgr = new CvIrrAviTexture(driver,"video.avi");
	//set the texture
	our_bill_node->setMaterialTexture( 0, cv_text_mgr->getTexture() );

	while(device->run())
	{
		//update webcam texture
		cv_text_mgr->UpdateTexture();
		
		driver->beginScene(true, true, SColor(255,100,101,140));

		smgr->drawAll();

		driver->endScene();
	}
   
	device->drop();

	return 0;
}
Image

CvIrrCamController - 3D head tracking lib to create window effect with webcam
IrrAR - Attach Irrlicht nodes to real life markers
http://www.nighsoft.com/
NotAnotherNun
Posts: 8
Joined: Fri Nov 21, 2008 1:10 am

Post by NotAnotherNun »

rogerborg wrote:This looks like a job for Green Lantern, She-Ra, or possibly Ghost Rider.

How about you help us to help you? Post or upload your source somewhere, or at least provide us with a link to whereever you're getting it from. You're basically asking us to debug your source for you. Well, where is it?
Fair enough, here is my code, its code that has been here for a while, but doesnt like me, anyway:

This is a file called video.h

Code: Select all

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

#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; 

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; 
            }            
 } ; 
and this is the runner (main.cpp):

Code: Select all

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

#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; 

int main() 
{ 
	IrrlichtDevice* irrDevice   = createDevice(video::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("intro.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,0,0,0)); 
		movie->NextMovieFrame(); 
        movie->DrawMovie(0,0,movTxtr);
        irrSceneMgr->drawAll(); 
        irrVideo->endScene(); 
	}

    irrDevice->drop(); 

    return 0; 
}
Murcho
Posts: 26
Joined: Mon Nov 10, 2008 8:45 am
Location: Australia

Post by Murcho »

I'd be checking your pointers after assigning them values. eg.

Code: Select all

TMovie* movie = new TMovie(); 
if (movie != NULL)
{
      movie->LoadMovie("intro.avi"); 
      movie->SetMovieFPS(25); 
}
else
      return 1;

If you do this and put break points in you will be able to see if all you objects are loading correctly.
NotAnotherNun
Posts: 8
Joined: Fri Nov 21, 2008 1:10 am

Post by NotAnotherNun »

Murcho wrote:I'd be checking your pointers after assigning them values. eg.

Code: Select all

TMovie* movie = new TMovie(); 
if (movie != NULL)
{
      movie->LoadMovie("intro.avi"); 
      movie->SetMovieFPS(25); 
}
else
      return 1;

If you do this and put break points in you will be able to see if all you objects are loading correctly.
I know the file location is correct, because when it isnt, the program does nothing. Through trial and error, i have found that the line:

movie->DrawMovie(0,0,movTxtr);

is what causes the error:

Unhandled exception at 0x00402d6a in vidtest.exe: 0xC0000005: Access violation writing location 0x04ce1000.

but anyway, after inserting that code, it still operates in exactly the same way
Murcho
Posts: 26
Joined: Mon Nov 10, 2008 8:45 am
Location: Australia

Post by Murcho »

Well check the pointer movTxtr too, if thats not loading properly it will cause a problem.
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

[offtopic]any plan to add video rendering to irrlicht core?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yeah, code which is cross-platform and offers a nice API might become part of the irrExt library. FreakNigh's code might be a candidate, earlier proposals usually failed at one or the other requirement.
NotAnotherNun, your code reminds me of the MagicLibrary, the problem with this code was the complete lack of format checks of any kind. So in case you get a different color depth, or some different alignment of either the texture or your screen the code will fail. It's just a quick hack for a minimal capability test, for any serious usage that code needs an intensive overhaul.
NotAnotherNun
Posts: 8
Joined: Fri Nov 21, 2008 1:10 am

Post by NotAnotherNun »

damn, are there any other peices of code that can play videos that work?
vynguyen
Posts: 1
Joined: Thu Dec 11, 2008 5:03 am

Too slow !

Post by vynguyen »

I add some code

Code: Select all

//  --- > driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
				core::stringw tmp(L"ARToolkit  Irrlicht  OpenCV [");
				tmp += driver->getName();
				tmp += L"] fps: ";
				tmp += fps;

				device->setWindowCaption(tmp.c_str());
				lastFPS = fps;
		}
I see that Frame per second about 6-10 . It is too slow.
And i realize that function: UpdateTexture() is the reason.
Please help me!
Thanks.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You should ask this in the original thread for CvIrrAviTexture, because it's a problem with that code.
Post Reply