Getting the colour of a video texture

I am using a streaming video as a diffuse texture, and I’d like to detect when this video user is no longer streaming. When the stream is off, the video becomes a solid colour - (currently this is configured to be black, but could be any colour).

I’d like an efficient way of getting the current colour of the video texture over a small area such as 10x10 pixels, so I can detect if the video is streaming or not.

Ie, if the average colour is 0,0,0 then I know it’s currently off.

I’ve briefly looked into using readPixels on the diffuse texture but didn’t have much luck.

Does anyone have any suggestions?

Thanks,
Tom

Welcome aboard!

Using readPixel should work:

You shouldn’t do it every frame, however, as retrieving data from the GPU can be a slow process. But for your use case, I guess that doing it only a few times per second is enough (or even one time per second).

2 Likes

Thanks @Evgeni_Popov! I’ll give it a go and report back.
Thanks!

1 Like

This is working well. Thanks for pointing me in the right direction.

1 Like