Getting started with video manipulation

Hello everyone :slight_smile:

This is my first post! I am a musician mainly working with SuperCollider and I thought I would try to expand a bit into visuals. I have connected SuperCollider with OF just fine through OSC and have managed to achieve basic video manipulation (speed, scrubbing etc) through the ofVideoPlayer Class but I am having problems getting to the next level by manipulating the actual pixels or otherwise achieving transformations.

My perception is that I need to either get the pixels with .getPixelsRef or the texture with .getTextureRefs and then do whatever I want in a for loop. Is that right? And if yes could someone please give me a simple example that I can work from? I really tried hacking around and looked at the examples without any luck.

Here is my last attempt:

  
     
    ofPixelsRef pix = myVideo.getPixelsRef();  
    // put some stuff in the pixels  
    int i = 0;  
    while( i < pix.size()) {  
        char c = pix[i];  
        pix[i] = 0;  
        i+=3;  
    };  
    myVideo.draw(250,100, myVideo.width, myVideo.height);  

Thank your for your time :slight_smile:

Dionysis

You’re doing the right thing to get access to the pixels in the but the video actually has its own texture (i.e. the pixels on the graphics card) that it draws when you call draw().

What you want to do is have another ofImage around that you can play with, something like this:

  
  
int i = 0;  
while( i < pix.size()) {    
    image.getPixelsRef()[i] = video.getPixelsRef()[i] * 2.f; // double-brightness  
    i++;   
}  
  
image.update(); // this puts the ofPixels into the texture on the graphics card  
image.draw(); // now you're drawing the new texture you made.  
  

This works because “video.getPixelsRef()[i]” returns an ofColor instance that you can play with however you want.

Ah thank you Joshua :slight_smile:

I am at work but I will try it first thing when I go home. Looks really straightforward though. Just what I needed!

Could you clarify one thing for me? You said that “video.getPixelsRef()” returns an ofColor instance (which is great!) but in the documentation it says:

  
ofPixelsRef ofVideoPlayer::getPixelsRef()  

which would imply that it is returning an instance of ofPixelsref. Isn’t that right? Where should I have checked to find out that it actually returns the ofColor instance?

Best

Dionysis