【发布时间】:2014-02-25 09:21:55
【问题描述】:
我正在编写着色器以在我的视频播放项目https://github.com/wang-bin/QtAV 中显示 yuv 图像。着色器似乎是正确的,因为我已经在单个 yuv 图像上进行了测试。但是如果我在 GLWidgetRenderer 中应用我的着色器,结果总是错误的。
在没有我的着色器的情况下显示的第一张图像。第二个是使用着色器时的结果。对于某些视频,结果类似于第三张图片,带有许多绿线。
我认为我的 C++ 代码中有一些错误。但我找不到它们,因为我对 OpenGL 不是很熟悉
那可能是什么原因呢?
c++ 代码在这里:https://github.com/wang-bin/QtAV/blob/master/src/GLWidgetRenderer.cpp
yuv 2 rgb 着色器https://github.com/wang-bin/QtAV/blob/master/src/shaders/yuv_rgb.f.glsl:
#ifdef GL_ES
// Set default precision to medium
precision mediump int;
precision mediump float;
#else
#define highp
#define mediump
#define lowp
#endif
// u_TextureN: yuv. use array?
uniform sampler2D u_Texture0;
uniform sampler2D u_Texture1;
uniform sampler2D u_Texture2;
varying lowp vec2 v_TexCoords;
//http://en.wikipedia.org/wiki/YUV calculation used
//http://www.fourcc.org/fccyvrgb.php
//GLSL: col first
// use bt601
const mat4 colorMatrix = mat4(1, 1, 1, 0,
0, -0.344, 1.773, 0,
1.403, -0.714, 0, 0,
0, 0, 0, 1)
* mat4(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, -0.5, -0.5, 1);
void main()
{
// use r, g, a to work for both yv12 and nv12
gl_FragColor = clamp(colorMatrix* vec4(texture2D(u_Texture0, v_TexCoords).r,
texture2D(u_Texture1, v_TexCoords).g,
texture2D(u_Texture2, v_TexCoords).a,
1)
, 0.0, 1.0);
}
【问题讨论】:
-
我已经解决了这个问题。我的错。创建的纹理尺寸错误。但部分视频中仍存在绿线