Video within a shape (or alpha mask)

Hello everyone!, I´m rather new into processing, but I have experience coding. I want to put the video streaming withing a an irregular shape (it doesn´t have to be a rectangle).

My approach, I did a b&w mask image with the same proportions of the windows. The white part of the mask is where I want to put the video pixels.

So these are the steps.

  • I get pixels from the video streaming

  • I scan the mask by row and columns, and if this locations corresponds to a white pixel, I put the pixel of the video to be rendered.

My problem, is that this approach doesn´t respect the shape of the mask at all.
Any advice is very appeciated, thanks a lot

1 Like

Is your video streaming has the same dimensions than your b&w mask?
Can you post a screenShot?

There are multiple examples of masking in the old forum. This one is recent:

Although this is applied to an image, you can apply it to a video object as it extends from PImage.


1 Like

Thanks @josephh and @kfrajer for your responses. I searched in the forum and wasn’t able to find something. I will read it. Regardless the dimension, I was going to check that in order to apply a scale factor for columns and rows.

As soon as I could try something, I will post about the results.

@rossig7 This problem reminds me of this example from P5js - but it masks the entire video frame which I don’t think that’s your goal for your project. The best of luck to you and these problems is what helps add to the functionality of processing in the future:-)

Some more examples using mask(). Check them out and consult the reference for specific details. Ask if you have any question: The first link is probly the one you are going after.



Sorry for my late response, I´ve been working on another project, as soon as I have time, I will tell you about my advances. Thank you all! I have a lot to read ahead.

Hello, I’ve been working with alpha video mask, and i have this sketch working
The process is
I have a qtre video Animation.
With ffmpeg I extract the alpha mask ej:
ffmpeg.exe -ss 00:00:00 -t 00:00:50 -i blender/ -vf alphaextract -y -r 60
and cut the orgininal longer file to the exact time
ffmpeg -i -ss 00:00:00 -to 00:00:50 -c copy

and now i convert the two videos in mkv
ffmpeg.exe -i -vcodec libx264 -pix_fmt yuva420p -y 00-50s_yuv_alpha.mkv
ffmpeg.exe -i -vcodec libx264 -pix_fmt yuva420p -y 00-50s_yuv.mkv

Reading this threat I using the Shader Example in processing Aamon Suggestion
See: File > Examples > Topics > Shaders > ImageMask

and changing images instead videos

this is the result:
(note: run in presentation mode)

1 Like

Thanks a lot for sharing…I will see your example. I couldn’t try it on P5 yet.

1 Like