Alpha mask on videos

Hi all,

I’m new to OF. I’m currently working on an iPad application where i would like to play videos containing an alpha channel. I understood there’s no compatible codec to directly do it, so i’d like to play two H.264 videos, one containing RGB channels and another containing alpha channel, and use the second one as a transparency mask of the first one.

I searched for hours on the forum but i didn’t find any good solution : the only one i found is using ofVideoPlayer::getPixels() but it’s too heavy and the iPad becomes too slow (works with images but not with videos).

I guess i have to use blending modes of OpenGL, but how ? I’m also new to OpenGL :slight_smile:

Thanks a lot for your help !


I only browsed thru this shortly, but maybe some of those hints mentioned here might help you…/346/0

Thanks underdoeg for your answer.

Yes i saw this topic but as an OpenGL beginner i tested a lot of parameters in glBlendFunc() and i still don’t get it. I guess in the draw() function i need to first display the video with real RGB, so it becomes the ‘destination’ of glBlendFunc(). Then, i call glEnable(GL_BLEND) and display the video containing only the alpha channel (which is contained in R, G and B channels, so it’s white where it’s visible and black where it’s transparent).

So i have two questions : am i right ? And which parameters should i use in glBlendFunc() ?


first try and bind the texture and display it with quads (drawn to be window size)
then try and bind the mask and display it
then combine the two …

that is what i did to get it working with static images at least

i did not need to change the blend function in the end

Thanks for your link. I have a lot of errors on this code :

    glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 240.0f);    
    glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 240.0f);    
    glVertex3f(0.0f, 240.0f, 0);    
    glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);    
    glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f);    
    glVertex3f(0.0f, 0.0f, 0);    
    glMultiTexCoord2f(GL_TEXTURE0, 320.0f, 0.0f);    
    glMultiTexCoord2f(GL_TEXTURE1, 320.0f, 0.0f);    
    glVertex3f(320.0f, 0.0f, 0);    
    glMultiTexCoord2f(GL_TEXTURE0, 320.0f, 240.0f);    
    glMultiTexCoord2f(GL_TEXTURE1, 320.0f, 240.0f);    
    glVertex3f(320.0f, 240.0f, 0);    

GL_QUADS, glBegin(), glMultiTexCoord2f(), glVertex3f() are undeclared identifiers, i guess that’s because OF implements OpenGLES 1 on iOS ?

I’m currently merging multiple layers of video with embedded alpha using ofxAlphaVideoPlayer ( and Quicktime with Animation codec. Framerate isn’t *amazing*, but it works and it makes people smile :slight_smile:

Oh probably, sorry. I am yet to switch to ES. I know they took a lot of stuff out (like QUADS etc).

Have you tried using a shader? I’m pretty sure recent iOS devices support them (with ES2.0), it might make the processing a bit more responsive. I saw this which wont do exactly what you need but might help as a start

Thanks a lot guys,

@keeran : Codec Animation makes too heavy files (i need to store lots of movies in my iPad app)… I tried AlphaVideoPlayer but i doesn’t compile !

@pants : I’m working on it :slight_smile: but i have some problems and i’m afraid of the behavior of the app with OpenFrameworks and GPUImage (so with both OpenGLES 1.1 and OpenGLES 2.0 included).

I have to say i’m getting a bit crazy with this problem, but maybe i’m in the wrong way ? Is it possible to do it simply with glBlendFunc() ?