3

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!

gleerman
  • 1,793
  • 4
  • 24
  • 38

3 Answers3

3
  1. Try the the CamcorderProfile API. Configurations exactly matching one of the ones retrieved from that are likely to work.

  2. 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.

Alex I
  • 19,689
  • 9
  • 86
  • 158
  • Your second hint did the trick, thank you! I'm having a color space problem now, but before asking any questions I will examine the CamcorderProfile API. Thanks a lot! – gleerman Nov 30 '12 at 16:20
  • I posted another question on the topic: http://stackoverflow.com/questions/13703596/mediacodec-and-camera-colorspaces-dont-match – gleerman Dec 05 '12 at 10:40
2

Please checkout below link :

http://developer.android.com/guide/appendix/media-formats.html

Check the section "Video Encoding Recommendations". The values are in pixels so make sure that the values are supported by the device resolution.

njzk2
  • 38,969
  • 7
  • 69
  • 107
Gaurav Navgire
  • 780
  • 5
  • 17
  • 29
1

I had the same issues, when I worked with MediaRecorder.

You can try to use CamcorderProfile, but from my experience, it doesn't guarantee stable work. Also in Android 2.* you can have only two profiles of CamcorderProfile.

These settings are device specific, and you can obtain the best for wide range of devices in experimental way.

EDIT: Also you can use H.263 instead of H.264, for your case it should work.

Taras
  • 2,526
  • 3
  • 33
  • 63