YUV to RGB conversion by fragment shader

后端 未结 5 1711
悲哀的现实
悲哀的现实 2020-11-30 01:10

I\'ve a problem with convertion of camera preview in Android from YUV format to RGB. The purpose of conversion is to apply some effects. I try to convert by fragment shader

5条回答
  •  没有蜡笔的小新
    2020-11-30 01:28

    Not sure if you have already fixed this problem.My answer

    1. By default Camera output is NV12, but in fragment shader YUV to RGB you are using YV12 -> RGB. You will have to do setPreviewFormat(ImageFormat.YV12);, or may be use some other shader
    2. There are 3 textures , make sure you do

      GLES20.glActiveTexture(GLES20.GL_TEXTURE2); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, muTextureName)

      before call to any glTexImage2D. and glTexSubImage2D

    3. You can also use glTexSubImage2D with every frame and glTexImage2D once.

    4. size of U and V is same , atleast for YV12,

      System.arraycopy(data, U_INDEX, uData, 0, LENGTH_4 * 2);

      should be System.arraycopy(data, U_INDEX, uData, 0, LENGTH_4); change the size accordingly in the code.

提交回复
热议问题