I am looking for an example of how to render a surface bitmap provided by MediaCodec so that I can encode and then move them to mp4 video.
The closest well-known example that I see is EncodeAndMuxTest . Unfortunately, with my limited knowledge of OpenGL, I was not able to convert an example using bitmaps instead of the raw OpenGL frames that it is currently creating. Here is an example of a frame generation method.
private void generateSurfaceFrame(int frameIndex) {
frameIndex %= 8;
int startX, startY;
if (frameIndex < 4) {
startX = frameIndex * (mWidth / 4);
startY = mHeight / 2;
} else {
startX = (7 - frameIndex) * (mWidth / 4);
startY = 0;
}
GLES20.glClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
GLES20.glScissor(startX, startY, mWidth / 4, mHeight / 2);
GLES20.glClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
}
-, , , , , ? , , , ( ).
: , generateSurfaceFrame , :
private int generatebitmapframe()
{
final int[] textureHandle = new int[1];
try {
int id = _context.getResources().getIdentifier("drawable/other", null, _context.getPackageName());
Bitmap bmp = BitmapFactory.decodeResource(_context.getResources(), id);
GLES20.glGenTextures(1, textureHandle, 0);
if (textureHandle[0] != 0)
{
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
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);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);
}
if (textureHandle[0] == 0)
{
throw new RuntimeException("Error loading texture.");
}
}
catch (Exception e) { e.printStackTrace(); }
return textureHandle[0];
}