4

I'd like to use MediaCodec to encode the data coming from the camera (reason: it's more low-level so hopefully faster than using MediaRecorder). Using Camera.PreviewCallBack, I capture the data from the camera into a byte-buffer, in order to pass it on to a MediaCodec object.

To do this, I need to fill in a MediaFormat-object, which would be fairly easy if I knew the MIME-code of the data coming from the camera. I can pick this format using setPreviewFormat() choosing one of the constants declared in te ImageFormat-class.

Hence my question: given the different options provided by the ImageFormat-class to set the camera preview-format, what are the corresponding MIME-type codes?

Thanks a lot in advance.

gleerman
  • 1,793
  • 4
  • 24
  • 38
  • 1
    This got easier in Android 4.3. See http://bigflake.com/mediacodec/#CameraToMpegTest – fadden Jul 24 '13 at 23:19
  • BTW, it's a superstition that using lower-level API may deliver better performance. The opposite is most likely true: instead of sending the pixels around, you can "short-circuit" the camera hardware to encoder hardware using MediaRecorder. – Alex Cohn Aug 22 '13 at 22:44
  • Correct me if I am wrong. Aegonis mentioned: "I'd like to use MediaCodec to encode the data coming from the camera (reason: it's more low-level so hopefully faster than using MediaRecorder). " But I have an impression that Camera Preview has a slower fps than the original Camera output raw data. – user1914692 Mar 03 '14 at 19:32
  • was the performance of this any better in the end? Did you manage to achieve good frame rates (i.e >15fps) ? – Dean Wild Feb 11 '15 at 14:13

1 Answers1

6

See example at https://gist.github.com/3990442. You should set MIME type of what you want to get out of encoder, i.e. "video/avc".

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Thanks for the example, they are hard to find. So how does MediaCodec determine the format of what is in the parameter of offerEncoder? (i.e. the data from the camera in my case) – gleerman Nov 16 '12 at 20:28
  • I had some additional questions. It seemed better suited to create a separate topic: http://stackoverflow.com/questions/13458289/encoding-h-264-from-camera-with-android-mediacodec . Would you mind having a look at it? Thanks – gleerman Nov 19 '12 at 16:43