How to use OpenGL shader to convert RGB to YUV420

I know how to encode a shader that converts flat data (YUV420 image) to packed (RGB image) using a fragmented shader, but how can I encode RGB for YUV420. I do not need a YUV420 image for rendering, but pass it to the h264 compression code.

+5
source share
2 answers

From http://www.fourcc.org/fccyvrgb.php :

Convert RGB to YUV

Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16

Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128

Cb = U = - (0.148 * R) - (0.291 * G) + (0.439 * B) + 128

OpenGL 1/256. , , -.

mat4 RGBtoYUV(0.257,  0.439, -0.148, 0.0,
              0.504, -0.368, -0.291, 0.0,
              0.098, -0.071,  0.439, 0.0,
              0.0625, 0.500,  0.500, 1.0 );

YUV = RGBtoYUV * RGB;

http://en.wikipedia.org/wiki/YUV

+8

YUV , (, ).

, . , ARB_framebuffer_object. , . , , , , .

, framebuffer, 3 renderbuffer ( ) 3 vec4.

RED, .

( ), YUV (, SSE), .

, . , , contiguos.

+3

All Articles