# Video within a shape (or alpha mask)

**URL:** <https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663>\
**Category:** Project Guidance\
**Created:** [June 3, 2018, 4:54am UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663 "2018-06-03T04:54:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rossig7](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rossig7](https://discourse.processing.org/u/rossig7)\
**Post date:** [June 3, 2018, 4:54am UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663/1 "2018-06-03T04:54:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 3, 2018, 9:46am UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663/2 "2018-06-03T09:46:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 3, 2018, 3:24pm UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663/3 "2018-06-03T15:24:11Z")

</div>

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

> [masking PGraphics with PGraphics creates background where it's supposed to be transparent - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/28035/masking-pgraphics-with-pgraphics-creates-background-where-it-s-supposed-to-be-transparent#latest)

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

Kf

---

<div class="post-metadata">

**Author:** ![rossig7](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rossig7](https://discourse.processing.org/u/rossig7)\
**Post date:** [June 3, 2018, 6:55pm UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663/4 "2018-06-03T18:55:58Z")

</div>

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.  
Best

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [June 4, 2018, 12:27am UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663/5 "2018-06-04T00:27:22Z")

</div>

@rossig7 This problem reminds me of this example from P5js - [https://p5js.org/examples/dom-video-pixels.html](https://p5js.org/examples/dom-video-pixels.html) 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:-)

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 4, 2018, 12:37am UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663/6 "2018-06-04T00:37:05Z")

</div>

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.

> [How to copy a triangle out of an image - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/18819/how-to-copy-a-triangle-out-of-an-image)  
> [Masking a shape with another shape - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/23886/masking-a-shape-with-another-shape)  
> [How to create 2D lights for game ? - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/24534/how-to-create-2d-lights-for-game)  
> [How to draw a transparent PGraphics image? [SOLVED] - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/18818/how-to-draw-a-transparent-pgraphics-image-solved)

Kf

---

<div class="post-metadata">

**Author:** ![rossig7](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rossig7](https://discourse.processing.org/u/rossig7)\
**Post date:** [June 4, 2018, 8:27pm UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663/7 "2018-06-04T20:27:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![janebeta7](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/janebeta7/32/101_2.png) [@janebeta7](https://discourse.processing.org/u/janebeta7)\
**Post date:** [August 23, 2018, 11:54am UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663/8 "2018-08-23T11:54:47Z")

</div>

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/0001-14524.mov -vf alphaextract -y -r 60 0001-14524\_alpha.mov  
and cut the orgininal longer file to the exact time  
ffmpeg -i input.mov -ss 00:00:00 -to 00:00:50 -c copy 0001-14524.mov

and now i convert the two videos in mkv  
ffmpeg.exe -i 00-50s\_alpha.mov -vcodec libx264 -pix\_fmt yuva420p -y 00-50s\_yuv\_alpha.mkv  
ffmpeg.exe -i 00-50s.mov -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**

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/2661/use-a-video-as-mask)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.

and changing images instead videos

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

> **[maskingvideo-180823a.zip](https://www.dropbox.com/s/m3rv1r5motf8nd0/maskingvideo-180823a.zip?dl=0)**
>
> Shared with Dropbox

 ![maskvideo-000006](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/fe01e2da9ab963b245ec86cb797e0ec5cbd0a8e2.jpeg)

---

<div class="post-metadata">

**Author:** ![rossig7](https://avatars.discourse-cdn.com/v4/letter/r/4af34b/32.png) [@rossig7](https://discourse.processing.org/u/rossig7)\
**Post date:** [October 17, 2018, 8:07pm UTC](https://discourse.processing.org/t/video-within-a-shape-or-alpha-mask/663/9 "2018-10-17T20:07:00Z")

</div>

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