3

I'm trying to applying an encoder by using MediaCodec. The MediaFormat I use is as follows.

 MediaFormat mediaFormat = MediaFormat.createVideoFormat("video/mp4v-es", 640, 480);
    mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 125000);
    mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 15);
    mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV422PackedSemiPlanar);
    mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5);

The demo runs well on virtual machine. However, it fails when I test it on the real machine(Samsung Galaxy Tab GT3113). The demo reports errors at the line codec.configure(mediaFormat, null /* surface */, null /* crypto */, MediaCodec.CONFIGURE_FLAG_ENCODE /* flags */); codec.start(); The logcat says:

06-24 15:16:54.582: E/ACodec(3146): [OMX.TI.DUCATI1.VIDEO.MPEG4E] does not support color format 19 06-24 15:16:54.582: E/ACodec(3146): [OMX.TI.DUCATI1.VIDEO.MPEG4E] configureCodec returning error -2147483648

06-24 15:16:54.582: E/MediaCodec(3146): Codec reported an error. (omx error 0x80001001, internalError -2147483648)

I have tried all the KEY_COLOR_FORMAT which are provied by Android, but none of them works. Can anyone help me? Thanks!

1
  • If you use "video/avc", it's highly likely that one of FormatYUV420Planar, FormatYUV420PackedPlanar, FormatYUV420SemiPlanar, FormatYUV420PackedSemiPlanar, and/or TI_FormatYUV420PackedSemiPlanar will work. For an OMX.TI.DUCATI1 codec, it'll be the latter. The formats are under-specified, but it may end up being the same memory layout as what you expected.
    – fadden
    Jul 10, 2013 at 0:35

1 Answer 1

4

Probably you're trying to use wrong encoder. Before starting encoder you should "probe" existing encoders using some kind of that:

HashMap<String, CodecCapabilities> mEncoderInfos;
void initEncoderInfos(){
    for(int i = MediaCodecList.getCodecCount() - 1; i >= 0; i--){
        MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
        if(codecInfo.isEncoder()){
            for(String t : codecInfo.getSupportedTypes()){
                try{
                    mEncoderInfos.put(t, codecInfo.getCapabilitiesForType(t));
                } catch(IllegalArgumentException e){
                    e.printStackTrace();
                }
            }
        }
    }
}

All info will be collected in mEncoderInfos. And after this you can use most suitable encoder.

In other words: you should not assume that some encoder("video/mp4v-es" in your case) does support some color format(MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV422PackedSemiPlanar in your case).

1
  • Note CodecCapabilities.colorFormats[] holds the list of color formats supported by the codec in question.
    – fadden
    Jul 10, 2013 at 0:31

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.