I am looking for an example on how to render a bitmap to the surface provided by MediaCodec so I can encode and then mux them into mp4 video.
The closest well know example I see is this EncodeAndMuxTest. Unfortunately with my limited OpenGL knowledge I have not been able to convert the example to use bitmaps instead of the raw OpenGL Frames it currently generates. Here is the example's Frame generation Method.
private void generateSurfaceFrame(int frameIndex) {
frameIndex %= 8;
int startX, startY;
if (frameIndex < 4) {
// (0,0) is bottom-left in GL
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);
}
Can someone please show me how to modify this to render a bitmap instead or point me to an example that does this? I'm assuming that this is all I need to do in order to get bitmaps to render to the surface (but I may be wrong).
Edit: this is the method I replaced generateSurfaceFrame with that doesn't create any input to the encoder surface so far:
private int generatebitmapframe()
{
final int[] textureHandle = new int[1];
try {
int id = _context.getResources().getIdentifier("drawable/other", null, _context.getPackageName());
// Temporary create a bitmap
Bitmap bmp = BitmapFactory.decodeResource(_context.getResources(), id);
GLES20.glGenTextures(1, textureHandle, 0);
if (textureHandle[0] != 0)
{
// 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, bmp, 0);
}
if (textureHandle[0] == 0)
{
throw new RuntimeException("Error loading texture.");
}
//Utils.testSavebitmap(bmp, new File(OUTPUT_DIR, "testers.bmp").getAbsolutePath());
}
catch (Exception e) { e.printStackTrace(); }
return textureHandle[0];
}