Video frame to unsigned char


I’m looking for a light-weight way to convert video frames (as it’s running) to unsigned char values. While also changing from RGBA to BGRA. Should I do this in a texture? Or skip?

End goal is to have unsigned char for bitmapping.


If you are using a ofVideoGrabber or some other thing that has pixels, you can use:

unsigned char* pointerToPixels = grabber.getPixels().getData();

This is a pointer to the first unsigned char of the internal array, so you’ll probably also need the size of that array which is found by calling:

std::size_t theSize = grabber.getPixels().size();
1 Like


I’ve actually solved this by drawing the video in an ofFbo and getting pixel data from there, since I figured I might need to do some altering to the actual video frames or draw overlays or something else for that matter.

Here’s the final code snippet:

// tempPix is ofPixels
tempPix.swapRgb(); // swapping rgb pixels since I need them swapped
unsigned char *pixels = tempPix.getData();

And if anyone’s interested in getting a color value at a certain pixel position (totally not related to original post).

ofColor tempColor = tempPix.getColor(posX, posY);
int red = tempColor.r;
int green = tempColor.g;
int blue = tempColor.b;