Plana YUV -> RGB using GLSL


I have a video in planar YUV format (Three planes in three different arrays) and I want to convert this into RGB and display it using shaders. Normally if it was packed (interleaved) format I would write one frame to a texture than decompose it the Y,U and V planes using a 2D samplers. But since there are 3 different arrays one way can be uploading them to three different textures converting it but I dont want to use 3 textures per video since I will display multiple videos (12) at a time. How can I write a shader which will take the whole planar YUV data (maybe by PBO), decompose into Y,U,V, convert to RGB and display it in a 2D rectangle.


Does your decoder support setting linesize ? (the pitche in byte to go to the next line). I it does, you can arrange your planes like this in your pbo :

and shift your texture coordinates. But, due to opengl’s filtering, you may have some artefacts to the texture’s edges. If you use SDL, here a video decoder that can do this for you :
But I think creating 36 textures isn’t really a problem…

Yes, the number of textures shouldn’t be a problem - the memory used is the same, and as long as you don’t expect to draw all those videos in one shader pass (probably can’t anyway), binding the right textures is fine. You also will probably help the GPU cache the texels you want to sample, as opposed to picking from three points on one texture, which would probably subvert the caching each shader unit does.

If you really feel you must, then upload a huge single channel texture and work out where to sample in the pixel shader. It’s not too hard.


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.