We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › capturing previous Movie frame into a PImage
Page Index Toggle Pages: 1
capturing previous Movie frame into a PImage (Read 1734 times)
capturing previous Movie frame into a PImage
Jun 14th, 2005, 8:29pm
 
I'm trying to capture the last read frame of a Movie object and store it in a PImage, so that I can compare differences as the movie plays.

My current approach doesn't seem to be working:

Code:

myMovie = new Movie(this, "doh.mov");
myMovie.loop();
myMovie.speed(.1);

void movieEvent(Movie m) {
// store previously read frame of movie
PImage oldfrm = new PImage(myMovie.pixels,myMovie.width,myMovie.height,RGB);

// update movie frame
myMovie.read();

// compare pixels
showColorDifferences(oldfrm,myMovie);
}


This gives me a valid image in 'oldfrm', but it appears to be the same as the current Movie frame.  That is, there are no color differences.

Any ideas?

Thanks,
jared
Re: capturing previous Movie frame into a PImage
Reply #1 - Jun 15th, 2005, 3:06pm
 
haven't tested it, but have you tried doing something like this?:

Code:

PImage oldfrm; // declare this outside and before your setup function


myMovie = new Movie(this, "doh.mov");
myMovie.loop();
myMovie.speed(.1);
oldfrm = new PImage(myMovie.pixels,myMovie.width,myMovie.height,RGB); // fill with initial value...

void movieEvent(Movie m) {
// update movie frame
myMovie.read();

// compare pixels
showColorDifferences(oldfrm,myMovie);

// store "new previously read" frame of movie after comparing...
oldfrm = new PImage(myMovie.pixels,myMovie.width,myMovie.height,RGB);
}
Re: capturing previous Movie frame into a PImage
Reply #2 - Jun 15th, 2005, 3:49pm
 
when creating a new PImage that way, it's just using the same pixels buffer as the original movie object, so it's gonna update whenever the movie updates.

the solution is actually simpler than what you had, all you need to do is copy the frame using get():

Code:
void movieEvent(Movie m) {  
// update movie frame
myMovie.read();

// compare pixels
showColorDifferences(oldfrm,myMovie);

// store "new previously read" frame of movie after comparing...
oldfrm = myMovie.get();
}
Re: capturing previous Movie frame into a PImage
Reply #3 - Jun 16th, 2005, 12:19am
 
come to think of it, that's gonna be really slow, because it's gonna re-create the pixel buffer on each step. this is more of what you want:

Code:
// create a duplicate image area for storage
// which will also set the initial value
oldfrm = myMovie.get();

void movieEvent(Movie m) {
// update movie frame
myMovie.read();

// compare pixels
showColorDifferences(oldfrm,myMovie);

// copy the pixel array to the old one
arraycopy(myMovie.pixels, oldfrm.pixels);
}
Re: capturing previous Movie frame into a PImage
Reply #4 - Jun 16th, 2005, 1:07am
 
I was looking around in the Movie documentation.  And I've seen in many examples the same thing I saw here:

Code:

void movieEvent(Movie m) {

myMovie.read();

// do whatever
}


why can't/shouldn't we do the following? note the difference at the first line:

Code:

void movieEvent(Movie myMovie) {

myMovie.read();

// do whatever
}


Or it doesn't matter if we only have one Movie class instantiated in the applet? whant if we have several?

another question is if Movie extends from PImage?

ricard
Re: capturing previous Movie frame into a PImage
Reply #5 - Jun 16th, 2005, 4:09pm
 
doesn't matter whether you use m or myMovie. casey uses the movie passed into the function in the reference because it's easier/probably more proper to learn it that way, especially when you want to move on to using multiple movies.

and yes, Movie does extend PImage (as does Capture, and PGraphics). so you can use it just like any other PImage.
Re: capturing previous Movie frame into a PImage
Reply #6 - Jun 20th, 2005, 5:27pm
 
I think that casey doesn't use the Movie object passed into the function (Movie m) he rather uses myMovie.

I agree with you that using the movie passed into the function would make it easier to learn and to handle multiple movies.  So I think the reference should be changed, I will post this in the Website and Refernces bugs section.
Page Index Toggle Pages: 1