我使用ffmpeg解码xxx.mp4
并得到YUV420p AVFrame
。然后我通过着色器渲染了yuv数据,但是它是如此的绿色!
uTextureYLocation = glGetUniformLocation(program, uTextureY);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, yTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, avFrame->width, avFrame->height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, avFrame->data[0]);
glUniform1i(uTextureYLocation, 0);
uTextureULocation = glGetUniformLocation(program, uTextureU);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, uTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, avFrame->width / 2, avFrame->height / 2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
avFrame->data[1]);
glUniform1i(uTextureULocation, 1);
uTextureVLocation = glGetUniformLocation(program, uTextureV);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, vTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, avFrame->width / 2, avFrame->height / 2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
avFrame->data[2]);
glUniform1i(uTextureVLocation, 2);