PDA

View Full Version : YUV video data to RGB converstion in Qt



keshavsingh
05-08-2017, 06:01 AM
Hello All,

I am trying to convert and render YUV data(in three buffers i.e FrameY, FrameU and FrameV ) to RGB by using the below formula which i have googled, the problem is that the video is being rendered but there is a prominent green shade on top of the video. Can you please help me where I am doing wrong.


Shader Program:

glShaderProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, // glShaderProgram is the pointer of the QOpenGLShaderProgram*
"attribute highp vec4 vertex;\n"
"attribute highp vec4 texCoord;\n"

"varying highp vec2 coords;\n"

"\n"
"void main() {\n"
" gl_Position = vertex;\n"
" coords = texCoord.xy;\n"
"}\n");

// Add Fragment Shader - fourcc: 420
glShaderProgram->addShaderFromSourceCode(QOpenGLShader::Fragment,
"varying highp vec2 coords;\n"
"uniform highp sampler2D texture_y;\n"
"uniform highp sampler2D texture_u;\n"
"uniform highp sampler2D texture_v;\n"
"\n"
"void main() {\n"
"\n"
" highp float y = texture2D(texture_y, coords).r;\n"
" highp float u = texture2D(texture_u, coords).r;\n"
" highp float v = texture2D(texture_v, coords).r;\n"
"\n"
" y = 1.1643 * (y - 0.0625);\n"
" u = u - 0.5;\n"
" v = v - 0.5;\n"
"\n"
" highp float r = y + 1.5958 * v;\n"
" highp float g = y - 0.39173 * u - 0.81290 * v;\n"
" highp float b = y + 2.017 * u;\n"
"\n"
" gl_FragColor = vec4(r, g, b, 1.0);\n"
"\n"
"}\n");



Thanks & Regards,
Keshav