video.loadPixels() does not seem to work

Hi all!

I did a lot of code dabbling on this video capture tutorial sometime around 2017 : https://www.youtube.com/watch?v=rNqaw8LT2ZU using p5js version v0.5.11 . All seem to work even around early 2018 but when i revisited my code now, video.loadPixels() does not seem to work. Updated p5js library to version v0.7.2 but still no go.

Anyone having similar experience / workaround ?

Thanks.

Looks like it’s a know bug in v0.7.2. If you’d like to use loadPixels() on a video I think the easiest thing is just to switch back to v0.7.1 and wait for v0.8.0 where it’ll probably be fixed.

Hi Rjsan, I faced the same problem yesterday. But I was working on Processing P3 with this Code from the video in link. Luckily, I have fixed it :slight_smile:
I was facing error in the “loc” variable in this command, video.loadPixels(loc). The error was “arrayindexoutofboundsexception: 307200”

If you are facing the same do the following:
int loc = x + y * video.width; ………………….(1)
color currentColor = video.pixels[loc];…………(2)
you must know and confirm that code(1) is accurately entered as it is written here. If it is correct, then you will not get the “arrayindexoutofboundsexception: 307200” error.

Example:
Camera resolution=640x480

here,
640 = width i.e. “x=639 maximum” [because bits start from 0]
480 = height i.e. “y=479 maximum” [because bits start from 0]
then,
loc = x + y * video.width;
loc = 639 + (479 * 640)
=307199 maximum.
We get the “arrayindexoutofboundsexception: 123…” error, if our loc value is greater then the Max. calculated value of loc. It is may be only due to
1) Wrong equation Entered. [this equation must be same as code(1)]

Thanks figraham/Hassan , appreciate the input. Will look more into this.

2 Likes