I decided to use a PGraphics
object as a buffer to draw the mask and then your video in. There, I make it fully black transparent using blendMode(REPLACE)
and background(0,0);
. After that, I draw a mask(i.e. the needed shape) with 2 circles and a colored rectangle as an example. After that, I use blendMode(MULTIPLY)
and draw the video ontop.
Then I pass the buffer on the screen with needed coordinates.
import processing.video.*;
int videoScale = 8;
int cols, rows;
Movie movie;
//PImage movie;
PGraphics movieBuffer;
int posX, posY; //Example position of the buffer.
void setup(){
size(640, 480);
cols = width/videoScale;
rows = height/videoScale;
movie = new Movie(this, "lava bubbles volcano.mp4");
//movie = loadImage(sketchPath("img.png"));
movieBuffer = createGraphics(640,480);
movie.loop();
}
void movieEvent(Movie movie){
movie.read();
}
void draw(){
movieBuffer.beginDraw();
movieBuffer.blendMode(REPLACE);
movieBuffer.background(0,0);
movieBuffer.blendMode(BLEND);
//Define your mask here. Here's an example with shapes and colors:
movieBuffer.noStroke();
movieBuffer.fill(255);
movieBuffer.ellipse(100,100,100,100);
movieBuffer.ellipse(125+sin(millis()/500.0)*50,130,100,100); //A shape that constantly changes for fun
movieBuffer.fill(255,127,0);
movieBuffer.rect(125,130,150,20);
//End of mask.
movieBuffer.blendMode(MULTIPLY);
movieBuffer.image(movie,0,0);
movieBuffer.endDraw();
if(mousePressed){ //Allows for dragging and dropping
posX+=mouseX-pmouseX;
posY+=mouseY-pmouseY;
}
background(0,127,255);
image(movieBuffer, posX, posY);
}
It’s not the best, as blendMode(MULTIPLY);
seems to be broken and ignores alpha channel of the mask, filling everything else with black. However, you can replace background(0,127,255);
with background(0);
to have the background behind the buffer also being black, keeping it all consistent.
EDIT: The issue above is fixable by converting the sketch to P2D and using a scary alien function as seen in reply #9 below.
Ignore the commented lines - I used them to test with an image because I don’t happen to have a video laying around to test it with. But it should work the same as it did for me.
Hopefully this bunch of information isn’t too hard to chew through!