Processing sketch: merge alpha channel video with another movie

53 Views Asked by At

I have a Processing sketch. I need to overlay a .mov video with alpha channel transparency with another video. The rest of the code works but i got error when the overlay should be started. I'm afraid the error is in the PImage, or in the all code structure what am I doing wrong? Please help me :)

import TUIO.*;
import processing.video.*;

TuioProcessing tuioClient;
TuioObject tobj;

boolean showOverlay  = false;
boolean flipVideo = false;

Movie video;
Movie overlayVideo;
void setup() {
size(600, 352);
 
frameRate(30);

 randomSeed(System.nanoTime());
 video = new Movie(this, "movie.mov");
overlayVideo  = new Movie(this, "overlay.mov");
  
 tuioClient = new TuioProcessing(this);
overlayVideo.loop();
 video.loop();
}

void draw() {
 background(0);

  if (showOverlay) {
   overlayVideo.loadPixels();
   PImage overlayVideo = video.get(0, 0 ,width, height);
    overlayVideo.mask(video);
    video.play();
     image(overlayVideo, 0, 0, width, height);  // Draw the overlay
   
    video.updatePixels();
    overlayVideo.updatePixels();  
  }

  if (flipVideo) {
    video.pixels = flipPixels(video.pixels);
  }
  
  image(video, 0, 0);
  video.updatePixels();
 
}

int[] flipPixels(int[] pixels) {
  int[] flippedPixels = new int[pixels.length];
  int width = video.width;

  for (int y = 0; y < video.height; y++) {
    for (int x = 0; x < video.width; x++) {
      flippedPixels[y * width + x] = pixels[y * width + (width - x - 1)];
    }
  }

  return flippedPixels;
}

void movieEvent(Movie m) {
  m.read();
}
void addTuioObject(TuioObject tobj) {
...
}
void removeTuioObject(TuioObject tobj) {
...
}
void stop() {
...
}

i need a video overlay with transparency, in processing

0

There are 0 best solutions below