Split video into 9 pieces

Hey everyone

I’m loading a video with ofVideoPlayer and I want to split this video into 9 cells being drawn at different places in the application.

I’m wondering what the fastest way to do it is, and if anyone have an example on how to do this.

Right now I’m creating 9 different textures, grabbing the pixels from the video frame, and then trying to load the pixels data into the different textures.

I guess you can do this much easier in OpenGL, but I can’t figure out how.



Hey Ronze,

attached is a little example for you. it uses glVertex + texture arrays, so hopefully that’s not super confusing… but it should be way more efficient for what you’re trying to do.

the example just has four quads, but if you change the NUM_QUADS variable at the top of testApp.h, you can add as many quads as you choose. you’ll see how to set the points in the setup() function.

in the interest of size, there’s no video file in the uploaded file… so it won’t really do too much until you add a video file.

one note: if you draw quads bigger than the actual video (e.g. a 1024 x 768 quad for a 800x600 video), you will see errors with the way this is set up. it’s definitely fixable, but if you don’t want to adjust the code too much, just set up the video you’re drawing to the final size you want!

good luck!



Hey Brett

Thank you so much! That was just what I was looking for.

  • Rune

This is an awesome example.

I needed the ability to draw the texture quads different places on the screen, so I edited the code to make this happen. You can find the code on GitHub:


I think this is something that could be great to have in the OpenFrameworks code: To have a texture and be able to only draw a part of the texture on the screen. Sort of like this:

ofRectangle cropArea;  
cropArea.x = 100;  
cropArea.y = 30;  
cropArea.width = 50;  
cropArea.height = 50;  
myTexture.draw(0, 0, cropArea);  

looks nice!
keep in mind, if you re-add the setPoint code, you can do quads of different shapes, not just rectangles. it also wouldn’t be a ton of code to expand it to masking with polygons of multiple points.

glad the example helped!