out of memory error when playing an array of videos sequentially
in
Core Library Questions
•
5 months ago
i have been working on a sketch which plays a quite large array (about 40) of short video clips - 30-90 seconds at 1280x720 resolution- activated by a sensor when someone is in the room
when the room is empty the sketch plays a short 3 sec video on a loop until someone comes into the space
and then the sequential array begins again
the sketch works for a bit, then bogs down losing sync and completely crashes
i am getting the following error message
JNA Callback org.gstreamer.elements.AppSink$33@2ffe7 threw the following exception:
java.lang.Out of MemoryError: Java heap space
i am a completely newbie to processing (or programming at all)
it seems to be a memory leak?
this is my code..does anyone have any suggestions for me?
with thanks
clem
import processing.video.*;
import processing.serial.*;
int maxmyMovies=31
; //total # movies
int myMoviesIndex=0; //initial movie to be displayed
int lastMovie = 0; // last movie that played before going back to the grid
int GRID = 0; // this is always the grid index
Movie[] myMovies = new Movie[maxmyMovies] ; //declare array of movies
Serial port;
int sensorValue;
int countdown = 0;
boolean sketchFullScreen(){
return true;
}
boolean someoneIsThere = false;
//////////////////////////////////////////////////////////////////////////////////////////
void setup( )
{
size(1280, 720);
port.bufferUntil('\n');
for (int i=0; i<myMovies.length; i++) {
myMovies[i] = new Movie(this, "trans"+nf(i, 2)+".mov"); //loading movies into the array
}
myMovies[myMoviesIndex].loop(); //play the first movie
}
//////////////////////////////////////////////////////////////////////////////////////////
void draw() {
image(myMovies[myMoviesIndex], 0, 0, 1280, 720); //display one movie
g.removeCache(myMovies[myMoviesIndex]); //empties cache so no OOM error
// the current movie is done
if (myMovies[myMoviesIndex].time() >= myMovies[myMoviesIndex].duration()) {
if (someoneIsThere) {
if (myMoviesIndex == GRID) { // we're on the grid clip
myMoviesIndex = lastMovie; // go back to where we were last time
}
nextMovie();
}
else {
myMovies[myMoviesIndex].stop(); // stop the current movie
if (myMoviesIndex != GRID) lastMovie = myMoviesIndex; // "save" it for later
myMoviesIndex = GRID; // grid
myMovies[myMoviesIndex].loop();
}
}
// DEBUG INFO
textSize(12);
fill(255);
text(myMovies[myMoviesIndex].time(), 30, 30);
text(myMovies[myMoviesIndex].duration(), 30, 60);
text(""+someoneIsThere, 30, 90);
textSize(48);
text(myMoviesIndex, 30, 500);
text("(" + lastMovie + ")", 30, 560);
}
//////////////////////////////////////////////////////////////////////////////////////////
void movieEvent(Movie myMovies) {
myMovies.read(); //read new frames from movie
}
//////////////////////////////////////////////////////////////////////////////////////////
void serialEvent( Serial s ) {
try {
String data = s.readString();
data = data.trim(); // gets rid \n and extra spaces if any
sensorValue = Integer.parseInt(data); // converts String --> number
if (sensorValue < 100) { // distance threshold
someoneIsThere = true;
countdown = 150; // time before we decide someone is gone
}
else {
if (countdown == 0) {
someoneIsThere = false;
}
}
// time running
if (countdown > 0) countdown--;
}
catch( Exception e ) {
println("whatever");
}
}
void nextMovie() {
myMovies[myMoviesIndex].stop(); // stop the current movie
myMoviesIndex=(myMoviesIndex+1) % myMovies.length; //increment movie by one and return to zero once size of array is reached
if (myMoviesIndex == GRID) myMoviesIndex = 1; // skip the grid when advancing to the next movie
myMovies[myMoviesIndex].play(); // play the next movie
}
when the room is empty the sketch plays a short 3 sec video on a loop until someone comes into the space
and then the sequential array begins again
the sketch works for a bit, then bogs down losing sync and completely crashes
i am getting the following error message
JNA Callback org.gstreamer.elements.AppSink$33@2ffe7 threw the following exception:
java.lang.Out of MemoryError: Java heap space
i am a completely newbie to processing (or programming at all)
it seems to be a memory leak?
this is my code..does anyone have any suggestions for me?
with thanks
clem
import processing.video.*;
import processing.serial.*;
int maxmyMovies=31
; //total # movies
int myMoviesIndex=0; //initial movie to be displayed
int lastMovie = 0; // last movie that played before going back to the grid
int GRID = 0; // this is always the grid index
Movie[] myMovies = new Movie[maxmyMovies] ; //declare array of movies
Serial port;
int sensorValue;
int countdown = 0;
boolean sketchFullScreen(){
return true;
}
boolean someoneIsThere = false;
//////////////////////////////////////////////////////////////////////////////////////////
void setup( )
{
size(1280, 720);
port.bufferUntil('\n');
for (int i=0; i<myMovies.length; i++) {
myMovies[i] = new Movie(this, "trans"+nf(i, 2)+".mov"); //loading movies into the array
}
myMovies[myMoviesIndex].loop(); //play the first movie
}
//////////////////////////////////////////////////////////////////////////////////////////
void draw() {
image(myMovies[myMoviesIndex], 0, 0, 1280, 720); //display one movie
g.removeCache(myMovies[myMoviesIndex]); //empties cache so no OOM error
// the current movie is done
if (myMovies[myMoviesIndex].time() >= myMovies[myMoviesIndex].duration()) {
if (someoneIsThere) {
if (myMoviesIndex == GRID) { // we're on the grid clip
myMoviesIndex = lastMovie; // go back to where we were last time
}
nextMovie();
}
else {
myMovies[myMoviesIndex].stop(); // stop the current movie
if (myMoviesIndex != GRID) lastMovie = myMoviesIndex; // "save" it for later
myMoviesIndex = GRID; // grid
myMovies[myMoviesIndex].loop();
}
}
// DEBUG INFO
textSize(12);
fill(255);
text(myMovies[myMoviesIndex].time(), 30, 30);
text(myMovies[myMoviesIndex].duration(), 30, 60);
text(""+someoneIsThere, 30, 90);
textSize(48);
text(myMoviesIndex, 30, 500);
text("(" + lastMovie + ")", 30, 560);
}
//////////////////////////////////////////////////////////////////////////////////////////
void movieEvent(Movie myMovies) {
myMovies.read(); //read new frames from movie
}
//////////////////////////////////////////////////////////////////////////////////////////
void serialEvent( Serial s ) {
try {
String data = s.readString();
data = data.trim(); // gets rid \n and extra spaces if any
sensorValue = Integer.parseInt(data); // converts String --> number
if (sensorValue < 100) { // distance threshold
someoneIsThere = true;
countdown = 150; // time before we decide someone is gone
}
else {
if (countdown == 0) {
someoneIsThere = false;
}
}
// time running
if (countdown > 0) countdown--;
}
catch( Exception e ) {
println("whatever");
}
}
void nextMovie() {
myMovies[myMoviesIndex].stop(); // stop the current movie
myMoviesIndex=(myMoviesIndex+1) % myMovies.length; //increment movie by one and return to zero once size of array is reached
if (myMoviesIndex == GRID) myMoviesIndex = 1; // skip the grid when advancing to the next movie
myMovies[myMoviesIndex].play(); // play the next movie
}
1