Android使用mediacodec和Opengl es将图像转换为视频

时间:2016-10-10 11:04:26

标签: android opengl-es mediacodec

我从:http://bigflake.com/mediacodec/,EncodeAndMuxTest示例开始。使用opengl生成帧。我改变了generateSurfaceFrame()方法,如下所示:

private void generateSurfaceFrame(int frameIndex) 
{
   final int[] textureHandle = new int[1];
   GLES20.glGenTextures(1, textureHandle, 0);
   if (textureHandle[0] != 0) 
   {
        // decode image to bitmap
        final Bitmap bitmap = BitmapFactory.decodeFile("PathToMyImage.jpg");

        GLES20.glEnable(GL10.GL_TEXTURE_2D);
        // Bind to the texture in OpenGL
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

        // Set filtering
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,                    
        GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, 
        GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
        // Load the bitmap into the bound texture.
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

        // Recycle the bitmap, since its data has been loaded into OpenGL.
        bitmap.recycle();
    }
}

问题是我得到的是一个黑色背景的视频,我不知道我是否正确加载图像,或者如何使用Opengl绘制图像。 我将不胜感激。

谢谢。

0 个答案:

没有答案