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!

4

1 回答 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).

于 2013-06-30T06:03:35.933 回答