multiple instance of video player/grabber

Normally you would do this:

// in declaration  
ofVideoGrabber vidGrabber;  
// in setup  

If creating an array of grayImages for example, I would…

// declaration  
ofCvGrayscaleImage * myImage;   
// setup  
myImage = new ofCvGrayscaleImage[2];  
for(int i =0; i <2; i++){  

But if you do the same with video players, you get this error :
error C2679: binary ‘=’ : no operator found which takes a right-hand operand of type 'ofVideoPlayer *'

However, if I do this…

// in .h  
ofVideoPlayer ** videoFile;  
// in .cpp setup  
videoFile = new ofVideoPlayer[2];  
for(int i =0; i < 2; i++){  
 videoFile[i] = new ofVideoPlayer();  

This works fine. Could you perhaps explain why?

However, when I try this with the video grabber, it builds but the error output is:
choosing 15663656
error locating a video device
please check your software with amcap or other software

Now I only have one device, but in theory this should work, as here is my code

// .h  
ofVideoGrabber ** vidGrabber;  
// .cpp  
vidGrabber  = new ofVideoGrabber*[2];  
for(int i =0; i < 1; i++){  

Any ideas? Thanks.

If I’m not mistaken in your myImage, the declaration should be

ofCvGrayscaleImage * myImage;  

which declares a pointer to ofCvGrayscaleImage instances and then you can access them with the array syntax.

try to do the same with your videoGrabber

ofVideoGrabber * vidGrabbers;  
// and then  
for(int i =0; i <2; i++){  

someone with more experience with c++ can explain this far better than me, but I think that should work

Sorry I forgot to include the image declare in my post, but it is in my code
ofCvGrayscaleImage * myImage;

Using * doesn’t seem to work with video player or video grabber, but ** works with video player, as explained above. I had already done what you are suggesting :slight_smile:

someone with more experience with c++ can explain this far better than me, but I think that should work

Yep, thats why I posted it in the advance section.

oops, sorry I came from bloglines and didn’t see the section.

this works for me (just tested)

// in .h  
ofVideoPlayer 		* fallout;  
// in setup   
fallout = new ofVideoPlayer[3];  
char movie[100];  
for (int i=0; i < 3; i++) {	  
     sprintf( movie, "movies/", i+1 );	  

edit: reading it again I don’t really know if I’ve misunderstood your question. ignore and excuse me if that’s the case :slight_smile:

Hi Chris,

If I get this right you have no problem compiling your code but you do get a runtime error. According to the error it seams like you have some trouble locating your input device/devices. If you only have one input device try

videoFile = new ofVideoPlayer[1];  

and see if that works. I’m guessing you’re trying to locate a device that doesn’t exists.

Thanks Henrik, this problem is now fixed. As you say, if you create a videoGrabber instance, that uses up the device, so if you start another it will say device not available. Sorted.