I’m trying to get Android 4.1’s new low-level media-features to work for H.264 encoding on an Asus Transformer TF300T tablet. I’m experiencing some strange behavior when I try to increase the resolution of the codec:
MediaFormat mediaFormat = MediaFormat.
createVideoFormat("video/mp4v-es", 320, 240); // WORKS
// MediaFormat mediaFormat = MediaFormat.
// createVideoFormat("video/mp4v-es", 640, 480); // DOESN'T WORK
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 125000);
mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 25);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5);
mediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mediaCodec.start();
In the latter case, I’m getting a IllegalStateException when calling mediaCodec.getInputBuffers();. Anyone who has any explanation (or even better: a fix)?
Thanks in advance!
Try the the CamcorderProfile API. Configurations exactly matching one of the ones retrieved from that are likely to work.
Clearly in your case there is some combination of resolution and other parameters that makes it not work. I wonder if it is the framerate? 25 is a bit odd, try 29.97 or 30, or maybe 15. I also wonder if it is the bitrate? It is is much too low for the resolution, try 500kbit/s.