1

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

George Profenza
  • 50,687
  • 19
  • 144
  • 218
mrblade
  • 11
  • 2
  • Can you please clarify what the error is ? (Is it a runtime error, what's the message/stack trace ?) The logic in the `if(showOverlay)` block looks a bit strange. Are you trying to simply render overlay.mov on top of movie.mov (assuming overlay.mov has an alpha channel ? (Currently your code reads like you're masking the overlay video and rendering it, then rendering the original video on top (which if they're the same size would hide the masked overlay). – George Profenza Aug 31 '23 at 14:32
  • i have this error: illegalargumentexception: mask() can only be used with an image that's the same size. both videos are the same size (600 x 352) yes, i'm trying to render overlay.mov on top of movie.mov i set if (showOverlay) because i use tuio library. when a markers is removed the showOverlay start (the idea is this). the code that works is: void removeTuioObject(TuioObject tobj) { if (tobj.getSymbolID() == 0) { showOverlay = true; } else if (tobj.getSymbolID() == 1) { flipVideo = true; } } Thanks so much – mrblade Aug 31 '23 at 15:15
  • The original videos might be the same resolution, however you're getting a "screenshot" of video that is the same dimensions as the sketch (no longer 600 x 532): `PImage overlayVideo = video.get(0, 0 ,width, height);`. It's unclear why. Also it's unclear why you need to use `mask()`. If the overlay video has transparency hopefully you just need `if (showOverlay) image(overlayVideo, 0,0);` after `image(video, 0, 0);`, right ? (assuming the Processing video library handles video with alpha channel correctly) (without `mask()` or `blend()`) – George Profenza Aug 31 '23 at 15:21
  • a short sample of the two mov files would be hand to share for debugging. – George Profenza Aug 31 '23 at 15:37

0 Answers0