Sound Cuts Out on Video in Processing 2: Advice

edited July 2016 in Library Questions

Hello Processing Forum,

I am working on a 2010 Mac with Processing 2. I am running a simple program with 3 ellipse masks over a video. Whenever I run the video the sound goes silent at about 20-30 seconds. I have tried a variety of codecs including mpeg and H264 and even other videos. All seem to out to silence pretty quickly. I am dying here trying to get it up for a video installation. I really want the sound to play. I would even be up for loading the sound as separate from the video in Processing 2 if that made it work. I would be thrilled with any advice on this-- this is the code I am using:

import java.util.*; import processing.video.*;

//creating Movie object Movie vid; //creating mask image PImage img; // movement speed of ellipses in pixels int moveSpd = 5;

// class representing ellipse class ellipseMask { // x,y position of center float x; float y; // x and y radius float xr; float yr;

//constructor ellipseMask(float x,float y,float xr,float yr) { this.x = x; this.y = y; this.xr = xr; this.yr = yr; }

}

// initializing ellipse mask objects - CHANGE HEIGHT & WIDTH SCALE HERE ellipseMask e1 = new ellipseMask(156,280,68,87); ellipseMask e2 = new ellipseMask(512,280,68,87); ellipseMask e3 = new ellipseMask(868,280,68,84);

// initialize transparent and black colors color trans = color(255,255,255,0); color black = color(0,0,0,255);

void setup() { size(1024,768); // loading video vid = new Movie(this,"test2-QuickTimeH.264.mov"); //making video run in loop vid.loop();

// create blank image of screen size img = createImage(width,height,ARGB); }

void draw() { background(255);

// displaying current video frame image(vid,0,0,width,height);

// loading pixel array, so we can set it img.loadPixels();

// iterating over all pixels indices in mask image for(int i=0;i<widthheight;i++) { // computing x,y coordinates of index float y = (float)( i/(int)width ); float x = (float)(i - ywidth);

// checking if points are inside ellipses using formula (x-h)^2/rx^2 + (y-k)^2/ry^2 <= 1 for disk/point intersection
if(  ((x-e1.x)*(x-e1.x))/(e1.xr*e1.xr) +  ((y-e1.y)*(y-e1.y))/(e1.yr*e1.yr) <= 1 || ((x-e2.x)*(x-e2.x))/(e2.xr*e2.xr) +  ((y-e2.y)*(y-e2.y))/(e2.yr*e2.yr) <= 1 ||  ((x-e3.x)*(x-e3.x))/(e3.xr*e3.xr) +  ((y-e3.y)*(y-e3.y))/(e3.yr*e3.yr) <= 1  )
{ 
// changing pixel array value of mask image to transparent if its inside ellipse 
img.pixels[i] = trans; 
}
else
{
// changing pixel array value of mask image to black if its outside ellipse   
img.pixels[i] = black;
}

}

// update mask image using the pixel array img.updatePixels();

// displaying mask image image(img,0,0,width,height);

}

// video event void movieEvent(Movie m) { m.read(); }

// called upon key press TO CHANGE POSITION OF ELLIPSES void keyPressed() { // moving ellipse 1 if(keyCode==UP){e1.y -= moveSpd;} else if(keyCode==DOWN){e1.y += moveSpd;} else if(keyCode==LEFT){e1.x -= moveSpd;} else if(keyCode==RIGHT){e1.x += moveSpd;}

// moving ellipse 2 if(key=='w'){e2.y -= moveSpd;} else if(key=='s'){e2.y += moveSpd;} else if(key=='a'){e2.x -= moveSpd;} else if(key=='d'){e2.x += moveSpd;}

// moving ellipse 3 if(key=='i'){e3.y -= moveSpd;} else if(key=='k'){e3.y += moveSpd;} else if(key=='j'){e3.x -= moveSpd;} else if(key=='l'){e3.x += moveSpd;}

}

Tagged:
Sign In or Register to comment.