We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there,
I am trying to use different moving 2D primitives to mask out a video and play it on top of another video.
Here is how far I have gotten until now:
import processing.video.*;
Movie myMovie;
float a;
float b;
float c;
float d;
float theta = 0.0;
int threshold = 240;
void setup() {
size(640, 360);
myMovie = new Movie(this, "station.MOV");
myMovie.loop();
myMovie.volume(0);
a = height/2;
}
void draw() {
background(55);
image(myMovie, 0, 0, width, height);
Mask();
}
void Mask() {
float x = (sin(theta) + 1) * width/8;
theta += 0.005;
//horizontal lines
stroke(255);
strokeWeight(1);
line(0, a, width, a);
a = a - 0.2;
if (a < 0) {
a = height;
}
strokeWeight(5);
line(0, b, width, b);
b = b + 0.1;
if (b > height) {
b = 0;
}
//Vertical lines
noStroke();
fill(155);
rect(c, 0, 50+x, height);
c = c -0.2;
if (c < -50-x) {
c = width;
}
noStroke();
fill(255);
rect(d, 0, (10+x), height);
d = d +0.3;
if (d > (width+100)) {
d = -x;
}
}
void movieEvent(Movie m) {
m.read();
}
So as you can see I am running a video as a background. On top of this video there are several moving white and grey rectangles and lines.
My question is: How can I use the primitives all together to mask out a second video?
I would like to do it in a way that allows transparency in relation to the brightness of the mask (50% gray = 50% transparent).
Hope my question makes sense.
Best regards
Answers
Google is your friend
https://www.google.com/search?client=safari&rls=en&q=mask++site:processing.org&ie=UTF-8&oe=UTF-8#q=mask+video++site:processing.org
https://forum.processing.org/one/topic/using-rects-as-masks.html
https://forum.processing.org/one/topic/image-behind-image.html
Thank you very much _vk!
I feel like I have been googling forever. Sometimes i find it really hard to know what to search for, but thanks for pointing me in the right direction.
I got a my masks and videos up and running, but there seems to be some issues. There is a lot of flickering back and forth between the 2 videos, and a I get a very long list of errors that starts with:
java.lang.reflect.InvocationTargetException
I tried setting different a lower framerate but that didn't help. It looks like theres an issue with what is gets drawn on top of what and in what order.
Thanks again!
while (myMovie.width == 0 | myMovie2.width == 0) delay(100);
surface.setSize(myMovie.width, myMovie.height);
for Processing 3.size(myMovie.width, myMovie.height);
for Processing 1 & 2.Wow thanks, I am not sure I understand what you just wrote, but I will try to look it up in the reference.
Thanks GoToLoop!!
pixels[]
may happen of being updated under Movie's Thread at that exact moment from time to time! @-)synchronized ()
which does just that. :>synchronized
. You only need to "protect" mask() for the whole "fix" to kick in. :ar!synchronized ()
, we have to choose 1 shared object reference to be their "gatekeeper".this
reference for their own internalsynchronized
methods, we just need to follow suit.synchronized ()
.this
object reference inside class Movie. :-jsynchronized ()
block too! :PThanks for your kind help GoToLoop!
I managed to get it working, but it is not as efficient as I would like it to be.
Have you got some recommendations on how to optimize performance?
I am sorry if I didn't manage to implement all of your previous suggestions.
I am using Processing 3.
Although there's always some tuning here & there, I don't see anything obvious which could actually increase performance further.
However, since you're using Processing 3, you definitely should try newest FX2D renderer out, for both size() & createGraphics().