Currently, my encoding a 30 FPS video consisting of 90 frames using Mediacodec takes 2100-2400 ms. I'm using the code found here, except with the generateSurfaceFrame(i) part being replaced with:
private void generateFrame(Bitmap bitmap, Rect source)
{
long drawFrameStartTime = System.currentTimeMillis();
Canvas canvas = mInputSurface.lockCanvas(null);
canvas.drawRect(0, 0, mSquareDim, mSquareDim, clearPaint);
//Process the canvas below
try
{
canvas.drawBitmap(bitmap, source, new Rect(0, 0, mSquareDim, mSquareDim), antiAliasPaint);
}
//Process the canvas above
catch(Exception e) {Log.e("renderExc", e.toString());}
finally {mInputSurface.unlockCanvasAndPost(canvas);}
long drawFrameEndTime = System.currentTimeMillis();
Log.i("frame_draw_time", (drawFrameEndTime - drawFrameStartTime)+"");
}
And the putting the frames into the MediaMuxer part with the code found and adapted from here - the one using the CircularBuffer class from Grafika. The muxer had to be released independently from the rest using that code.
I'm still concerned about Mediacodec's other bottlenecks when it comes to speed, though, and I'm targeting API 18 (minimum) at the moment. My questions are:
- Should I start using Asynchronous mode, and how much faster can it be than Synchronous mode?
- Is drawing the frames with OpenGL faster than the Surface-Canvas method described above?
- Are there other bottlenecks in Mediacodec I should be concerned about?
Full source code will be provided when asked.