【问题标题】:Wrong result using GLSL to convert YUV to RGB使用 GLSL 将 YUV 转换为 RGB 的错误结果
【发布时间】: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);
}

【问题讨论】:

  • 我已经解决了这个问题。我的错。创建的纹理尺寸错误。但部分视频中仍存在绿线

标签: c++ opengl yuv


【解决方案1】:

YUV 输入的格式是什么 - 它是着色器所期望的平面数据(在单独的缓冲区中)吗?此外,这些矩阵似乎不正确 - 您是否引用了 gstreamer 中已经存在的示例,或者例如在 http://www.ogre3d.org/forums/viewtopic.php?f=5&t=25877

【讨论】:

  • 这不是答案。应该是评论。
  • YUV420 平面,3 个平面。我认为着色器和矩阵是正确的。我解码相同的视频并保存每个平面,并使用cat 生成一个 yuv 图像。我为此图像测试了我的着色器,结果图像是正确的。
  • 如果这个结果是正确的 - 您作为原始问题发布的图像是否来自另一个不起作用的着色器?设置有什么不同?
猜你喜欢
  • 1970-01-01
  • 2012-02-22
  • 2014-01-25
  • 2020-12-18
  • 2019-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
相关资源
最近更新 更多