1

In a Android 4.2, A23 processor, We are trying to implement hardware encoding on the camera using the standard MediaCodec api, but couldn;t figure out what is the correct color format to use, for example, when we use this color format: MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar, this one is the value returned by android api to use, it's supposed to work, the encode inits well, but logcat issues error

E/omx_venc( 108): do not support this format: 21

We have tried many different formats, none works well.

/**
 * Video encoding is done by a MediaCodec.
 */
protected void prepareHwEncoder() throws RuntimeException, IOException 
{
    Log.d(LOG_TAG, "Video encoded using the MediaCodec API with a buffer");     

    int encoderColorFormat = MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar;
    // .COLOR_FormatYUV420SemiPlanar;

    mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
    MediaFormat mediaFormat = MediaFormat.createVideoFormat(MIME_TYPE, imageWidth, imageHeight);
    mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
    mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate);  
    mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, encoderColorFormat);
    mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
    mEncoder.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);


}

any example code that works on the camera is highly appreciated.

1

1 Answer 1

0

You need to query the codec to determine what color formats it supports. Typical color formats are listed here. Note that all supported MediaCodec color formats have the U/V planes reversed relative to the Camera color formats.

You can find an example of this in the CTS EncodeDecodeTest -- see selectColorFormat().

Unfortunately, in Android 4.2, there's no guarantee that a reasonable color format is supported.

3
  • I should mention that MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar (21) is the color format returned by selectColorFormat(), so it seems this is the desired color format to feed, but it still throws error saying this color format is not supported. Using other color formats don't even get that far.
    – huisinro
    Apr 13, 2014 at 16:06
  • Ugh. It's entirely possible that MediaCodec is not usable on this device. I assume this is with "video/avc"?
    – fadden
    Apr 13, 2014 at 18:54
  • yes, the mime type is video/avc, seems AllWinnder does not implement the java mediacodec stuff
    – huisinro
    Apr 13, 2014 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.