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 & HelpVideo Capture,  Movie Playback,  Vision Libraries › Movie - Memory being eaten up constantly
Page Index Toggle Pages: 1
Movie - Memory being eaten up constantly (Read 2243 times)
Movie - Memory being eaten up constantly
Sep 13th, 2008, 1:48am
 
when using the movie class in processing.video memory is being completely eaten up little by little. i'm running processing ver 135  here's some sample code:

Quote:




import processing.video.*;
Movie myMovie;

void setup() {
 size(200, 200);
 background(0);
 myMovie = new Movie(this, "drawing.mov");
 myMovie.loop();
}

void draw() {
 image(myMovie, 0, 0);
}

// Called every time a new frame is available to read
void movieEvent(Movie m) {
 m.read();  /////// this is what's eating up all the memory
}


Re: Movie - Memory being eaten up constantly
Reply #1 - Sep 24th, 2008, 12:05pm
 
I have the same problem with the same sort of simple code.
Whats the problem?
Re: Movie - Memory being eaten up constantly
Reply #2 - Sep 24th, 2008, 8:41pm
 
Well i took a look at the source code for the moviemaker class and under the read method there a line that reads:

Pict pict = movie.getPict(movie.getTime());

this is whats chewing up all the ram.  Apparently it reads whatever the current frame is in the movie and then saves it to a new pict image which is then converted to a pixmap, then a raw, and finally stored into a pixel array with the following lines of code:

PixMap pixmap = movieGraphics.getPixMap();
raw = pixmap.getPixelData();
raw.copyToArray(0, pixels, 0, width * height);

I looked up documentation on quicktime and pict images and couldn't find another way of saving individual frames.  But at least we know whats eating up all the ram now.  Maybe somebody else can figure out why

Pict pict = movie.getPict(movie.getTime());

keeps on using ram without releasing it.
Re: Movie - Memory being eaten up constantly
Reply #3 - Sep 25th, 2008, 2:45pm
 
Are you getting an OutOfMemoryError after it grows for a while? If not, you may be misunderstanding how Java handles RAM, where memory can be allocated for a while, even using up all available memory, and it won't bother running the garbage collector until it actually needs to (when memory caps out).
Re: Movie - Memory being eaten up constantly
Reply #4 - Sep 25th, 2008, 4:52pm
 
Hi, I have the same problem with different code.
It is a movieplayer that selects videos at random from a folder.

Any thoughts why it should gradually run out of memory?

import processing.video.*;
Movie myMovie;
float t;
float p;

void setup() {
 size(720, 576);
 myMovie = new Movie(this, "a2.mov");

}

void draw() {

 t = myMovie.duration();

 p = myMovie.time();

 myMovie.play();

 if (p == t)
 {
   int n = (int)random ( 1, 6);
   background(130);
   myMovie = null;
   myMovie = new Movie(this, "a" + n + ".mov");
 }
 else{

   image(myMovie, 0, 0);
 }

 tint (255, 50);

}

void movieEvent(Movie m) {
 m.read();
}

Thanks for your help

Dreadscribbles
Re: Movie - Memory being eaten up constantly
Reply #5 - Sep 26th, 2008, 3:44am
 
no it's definitely eating up ram.  If i play a high-res movie it only plays for a couple of seconds and then gives me an out of memory error.  I can even see the ram usage of the javaw.exe process in the task manager go steadily up until it reaches around 1.5gb in size and the gives me an out of memory error.
Re: Movie - Memory being eaten up constantly
Reply #6 - Sep 26th, 2008, 2:15pm
 
just noticed you're using 0135, have you tried it with 0148? i'm seeing the problem in 0135 but not in 0148.
Re: Movie - Memory being eaten up constantly
Reply #7 - Sep 26th, 2008, 6:08pm
 
Hello, I've tried the code I posted above in 0148 and it still runs out of memory. I am sure it is a simple thing but I can't see anything obvious.
I need the programme to run for a couple of hours without running out of memory.

Thanks  -  Dreadscribbles
Re: Movie - Memory being eaten up constantly
Reply #8 - Sep 26th, 2008, 6:41pm
 
ah, i see something that might be a problem. try calling stop() before setting the movie to null, and see if that helps.

if not, i've made a change for 0149 that might fix the problem.
Re: Movie - Memory being eaten up constantly
Reply #9 - Sep 26th, 2008, 10:08pm
 
Thanks for the reply. But unfortunately the memory continues to get eaten up.
A shall continue to fiddle with it.

Dreadscribbles
Re: Movie - Memory being eaten up constantly
Reply #10 - Sep 26th, 2008, 11:29pm
 
in your particular code, the problem is that you're creating a new movie object on each randomize.. you should instead load your six movies into an array, and switch between them as necessary. otherwise you're just accumulating running movies that are never freed from memory.

also, be sure to use 0148, because 0135 leaks memory in the video examples.
Re: Movie - Memory being eaten up constantly
Reply #11 - Sep 27th, 2008, 12:03am
 
Thanks. I'll give it a go.
DS
Re: Movie - Memory being eaten up constantly
Reply #12 - Oct 11th, 2008, 1:23pm
 
Hi again, I have rewritten the code so that the movies are loaded into an array first, but I still get the same problem. An out of memory error, eventually.

Here is the code.

import processing.video.*;

import java.util.*;

float t, d ;

int n;

Movie clip;

boolean s = false;

ArrayList clips = new ArrayList();



//float d;//duration of clip
//float t;// time on clip

void setup(){
 
 size(720, 576);
 
 
 for(int i=1; i<7; i++)
 {
   Movie clip = new Movie(this,"a" + i +".mov");
   clips.add(clip);
 }
 tint (255, 60);
 
 clip = (Movie)clips.get(0);
 
 clip.play();
}

void draw()
{
 
 if(hasClipEnded()) {
   println("end clip");
  startNextClip();
 }
 image(clip, 0, 0);
 
}

boolean hasClipEnded() {
 
 if( clip.time() == clip.duration()){
 
   return true;
 } else{
   return false;
 }
 
 
}


void startNextClip(){
     
     clip.stop();
     
     clip = null;
     
     int n = (int)random (0, 5);
   
     clip = (Movie)clips.get(n);
     
     clip.play();
     
   }
   
   void movieEvent(Movie m) {
 m.read();
}

Re: Movie - Memory being eaten up constantly
Reply #13 - Oct 11th, 2008, 1:28pm
 
Sorry but i didn't put this on the end of my last post.
Could I ask for your help in sorting this application out so that it does not run out of memory.
Thanks

Dreadscribbles
Re: Movie - Memory being eaten up constantly
Reply #14 - Nov 20th, 2008, 3:54pm
 
Hey,

I think I'm experiencing the same problem in my program.

In order to make sure Movie playback causes the problem, I started modifying "Loop" bundled example:  

I just changed the way playback loops, by using play() instead of loop(), and by checking for the end of the movie, then I stop(), re-create and play() again.

The result seems exactly the same as the original example, except it uses more and more memory, and never releases it. The result is an "out of memory error" after quitting.

Here's my -hacked- Loop example:

/**
* Loop.  
*  
* Move the cursor across the screen to draw.  
* Shows how to load and play a QuickTime movie file.  
*/

import processing.video.*;

Movie myMovie;


void setup() {
 size(640, 480, P3D);
 background(0);
 // Load and play the video in a loop
 initMovie();
}

void initMovie ()
{
 myMovie = new Movie(this, "station.mov");
 myMovie.play();    
}

void movieEvent(Movie myMovie) {
 if (myMovie.duration() != myMovie.time())
 {
   myMovie.read();
 }
 else
 {
   myMovie.stop();
   myMovie = null; // useful?
   initMovie();
 }
}

void draw() {
 tint(255, 20);
 image(myMovie, mouseX-myMovie.width/2, mouseY-myMovie.height/2);
}


remarks:
# I'm using Processing 0157, on Windows XP SP3 and MacOS 10.5.5
# about myMovie = null; I'm a C++ programmer, so I don't know much about "memory management" in Processing/Java; because it's a garbage-collected langage, I suppose it's useless, but not critical.

Page Index Toggle Pages: 1