Colors in decoded frames are too bright

I’m playing around with the OpenGL decoder example. In this example video frames are decoded to an OpenGL texture and then rendered on the screen.

The problem is that the colors are a bit off. E.g. pure black is shown as RGB 18 18 18 (-> too bright). I tested that with several different video files (different codecs etc.).
For comparison I use VLC Player or Windows Media Player, which both show a perfect black (RGB 0 0 0).

I also added code to render a simple black quad into the decoded frame. This also comes out as perfectly black. So the problem seems to be in the decoded frame/its texture.

Maybe someone has an idea how that can happen?
Thanks!

Hi shiggel,
Will it be possible for you to share with me the instrumented application along with the input stream that demonstrates this issue. It will help us accelerate our investigation.

Thanks!

At the moment I don’t have access to the source code. But in the mean time I found out what is causing the problem (but I’m still not sure how to fix it).

The colors I see in the decoded frames range from 16,16,16 (should be black) to 235,235,235 (should be white). And that’s no coincidence, I think ;-)
As explained e.g. in this document https://www.renesas.com/eu/en/www/doc/application-note/an9717.pdf the Y values of the YCrCb input frame data range from 16 to 235. So it seems your example code does not take that into consideration, which leads to RGB values only between 16 and 235.

In the example code (cudaProcessFrame.cpp) there is the following function:

extern "C"
void setColorSpaceMatrix(eColorSpace CSC, float *hueCSC, float hue)
{
  float hueSin = 0.0f;// sin(hue);
  float hueCos = 1.0f;// cos(hue);

  if (CSC == ITU601)
  {
    //CCIR 601
    hueCSC[0] = 1.1644f;
    hueCSC[1] = hueSin * 1.5960f;
    hueCSC[2] = hueCos * 1.5960f;
    hueCSC[3] = 1.1644f;
    hueCSC[4] = (hueCos * -0.3918f) - (hueSin * 0.8130f);
    hueCSC[5] = (hueSin *  0.3918f) - (hueCos * 0.8130f);
    hueCSC[6] = 1.1644f;
    hueCSC[7] = hueCos * 2.0172f;
    hueCSC[8] = hueSin * -2.0172f;
  }
  else if (CSC == ITU709)
  {
    //CCIR 709
    hueCSC[0] = 1.0f;
    hueCSC[1] = hueSin * 1.57480f;
    hueCSC[2] = hueCos * 1.57480f;
    hueCSC[3] = 1.0;
    hueCSC[4] = (hueCos * -0.18732f) - (hueSin * 0.46812f);
    hueCSC[5] = (hueSin *  0.18732f) - (hueCos * 0.46812f);
    hueCSC[6] = 1.0f;
    hueCSC[7] = hueCos * 1.85560f;
    hueCSC[8] = hueSin * -1.85560f;
  }
}

As far as I understand this is used to convert the video frames from YCrCb color space to RGB color space. So this would have to be changed in order to convert the 16-235 Y values to correct 0-255 RGB values.

Hi shiggel,
There is a known bug in the color space conversion functionality in Video Codec SDK 8.1 and earlier. We would recommend you to move to Video Codec SDK 9.0.

Thanks.