Problem creating video mask

Hi everyone,

I'm playing with video on processing and I'm trying to draw a mask and put a video on it. The thing is I keep getting a "mask() can only be used with an image that's the same size" error. The video I'm using is 640x360px. The weird part is that sometimes (about 1 in 10) the sketch runs and works ok!!

If anyone could give me hand here would be great.

Here's the code:

import processing.video.*;

Movie movie;
PImage mask01;

void setup() {
  size(640,360);
  movie = new Movie(this, "experiment_1.mp4");
  movie.loop();
  mask01 = createImage(width, height, ALPHA);
}

void draw() {
  //draw the mask - 1/4 window width
  mask01.loadPixels();
  for (int x=0; x < width; x++) {
    for (int y=0; y < height; y++) {
      int loc = x + y * width;
      if (x < width/4) {
        mask01.pixels[loc] = color(255);
      } else {
        mask01.pixels[loc] = color(0);
      }
    }
  }
  mask01.updatePixels();
  movie.mask(mask01);
  image(movie,0,0);  
}

void movieEvent(Movie movie) {
  movie.read();
}
Tagged:

Answers

  • You have to apply the mask on a PImage, not on a PGraphics. Here is a simple example:

    http://bazaar.launchpad.net/~philho/+junk/Processing/view/head:/_QuickExperiments/MaskImage/MaskImage.pde

  • I'm testing this with PGraphics but I'm getting the same mask() size error on the line movie.mask(mask01Shape);

    Am I doing something wrong? :) Thanks.

    import processing.video.*;
    
    int windowW = 640;
    int windowH = 360;
    Movie movie;
    PGraphics mask01Shape;
    
    void setup() {
      size(windowW,windowH);
      movie = new Movie(this, "experiment_1.mp4");
      movie.loop();
      mask01Shape = createGraphics(windowW, windowH, JAVA2D);
    }
    
    void draw() {
      //draw the mask - 1/4 window width
      mask01Shape.beginDraw();
      mask01Shape.background(0);
      mask01Shape.fill(255);
      mask01Shape.noStroke();
      mask01Shape.rect(0, 0, windowW/4, windowH);
      mask01Shape.endDraw();
      //assign the created mask to the movie
      movie.mask(mask01Shape);
      image(movie, 0, 0);
    }
    
    void movieEvent(Movie movie) {
      movie.read();
    }
    
  • If you reject an answer, you should indicate why. Have you tried? Have you a problem with the suggestion? Which one?

  • Sorry PhiLho. It doesn't work. It works when masking an image not a video (even though I believe it should). The way I got it to work was to code the masks and then actually save a .tga file and load it. That worked. Copying a PGraphic to a PImage didn't. Anyway, Processing seems to be very slow running several videos simultaneously.

    Thanks for your time.

Sign In or Register to comment.