Hi!
I was wondering if someone may be able to help me with a project I'm working on. I'll give a brief outline. I've written 2 programs, the first of which continually captures and saves movies using the input from a MBP webcam. The second program searches within the movie folder and selects at random a movie to play, then when it's finished playing, plays another in the same fashion. Eventually, this will form a live video installation. The first program runs without any detectable problems, however the second doesn't work well at all.
I'm currently experiencing 2 problems with the second program, the first of which is that after playing about 5-7 videos, playback drastically slows down until it gives me the error:
An OutOfMemoryError means that your code is either using up too much memory
because of a bug (e.g. creating an array that's too large, or unintentionally
loading thousands of images), or that your sketch may need more memory to run.
If your sketch uses a lot of memory (for instance if it loads a lot of data files)
you can increase the memory available to your sketch using the Preferences window.
Exception in thread "Thread-11" java.lang.OutOfMemoryError: Java heap space
at processing.core.PImage.init(PImage.java:194)
at processing.video.Movie.read(Movie.java:448)
at processing.video.Movie.run(Movie.java:679)
at java.lang.Thread.run(Thread.java:680)
The other error is that sporadically the program crashes, highlighting the following line of code:
image(randomVideo, 0, 0, width, height);
With this error:
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1681
at processing.core.PPolygon.scanline(PPolygon.java:445)
at processing.core.PPolygon.render(PPolygon.java:335)
at processing.core.PGraphics2D.endShape(PGraphics2D.java:401)
at processing.core.PGraphics.endShape(PGraphics.java:1242)
at processing.core.PGraphics.imageImpl(PGraphics.java:2925)
at processing.core.PGraphics2D.imageImpl(PGraphics2D.java:1410)
at processing.core.PGraphics.image(PGraphics.java:2853)
at processing.core.PGraphics.image(PGraphics.java:2829)
at processing.core.PApplet.image(PApplet.java:8690)
at CCTVPlayer.draw(CCTVPlayer.java:69)
at processing.core.PApplet.handleDraw(PApplet.java:1631)
at processing.core.PApplet.run(PApplet.java:1530)
at java.lang.Thread.run(Thread.java:680)
I believe the first may be a memory leak, so I think I need a line like "
randomVideo.delete();" or something to clear the cache after each video plays, however I can't seem to find any reference to this existing.
I'd be very grateful for any help or advice on either of the problems. Apologies for the rather long post and thank youvery much in advance. Please let me know if I can provide any extra information. Here is the sketch:
I'd be very grateful for any help or advice on either of the problems. Apologies for the rather long post and thank youvery much in advance. Please let me know if I can provide any extra information. Here is the sketch:
import processing.video.*;
Movie randomVideo;
boolean playing = false;
boolean videoInFolder = false;
void setup() {
size(screen.width/2, screen.height/2, P2D);
}
void draw() {
if (!videoInFolder) {
int t = 0;
while (t < 1) {
String path = sketchPath + "/videos/";
File dataFolder = new File(path);
String[] fileList = dataFolder.list();
t = fileList.length;
}
videoInFolder = true;
}
if (!playing) {
String path = sketchPath + "/videos/";
File dataFolder = new File(path);
String[] fileList = dataFolder.list();
int i;
i = int(random(fileList.length));
println(fileList[i]);
randomVideo = new Movie(this, path + fileList[i]);
randomVideo.play();
image(randomVideo, 0, 0, width, height);
playing = true;
}
else {
image(randomVideo, 0, 0, width, height);
float rvPlayhead = randomVideo.time();
float rvDuration = randomVideo.duration();
if (rvPlayhead == rvDuration) {
playing = false;
}
}
}
void keyPressed() {
if (key == ' ') {
exit();
}
}
1