I run this simple test MediaCodecon LG G2 with Android 4.4.2:
public class MyActivity extends Activity {
private static final String MIME_TYPE = "video/avc";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, 1280, 720);
int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
if (codecInfo.isEncoder()) {
String[] types = codecInfo.getSupportedTypes();
for (int j = 0; j < types.length; j++) {
if (types[j].equalsIgnoreCase(MIME_TYPE)) {
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(MIME_TYPE);
for(int colorFormat : capabilities.colorFormats) {
if (colorFormat == MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar) {
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar);
format.setInteger(MediaFormat.KEY_BIT_RATE, 1000000);
format.setInteger(MediaFormat.KEY_FRAME_RATE, 15);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 10);
MediaCodec mMediaCodec = MediaCodec.createByCodecName(codecInfo.getName());
mMediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mMediaCodec.start();
MediaCodec.BufferInfo mBufferInfo = new MediaCodec.BufferInfo();
mMediaCodec.dequeueOutputBuffer(mBufferInfo, 1000);
return;
}
}
}
}
}
}
}
}
And the following error occurs:
04-21 18:08:29.531 6513-6513/com.example.mediacodec I/OMXClient﹕ Using client-side OMX mux.
04-21 18:08:29.531 6513-6513/com.example.mediacodec E/OMXMaster﹕ A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one.
04-21 18:08:29.531 6513-6513/com.example.mediacodec I/﹕ @@@VOLOG Info THD 4001A154: VOOMXPlugin.cpp VOOMXPlugin 59 open libvoOMXOne.so successfully. 0X5BB9A5B8
04-21 18:08:29.541 6513-6513/com.example.mediacodec E/﹕ VOLOG Info THD 4001A154 voCOMXBaseConfig.cpp Open 368 The config file vomeOne.cfg could not be opened!
04-21 18:08:29.541 6513-6513/com.example.mediacodec I/SoftAVCEncoder﹕ Construct SoftAVCEncoder
04-21 18:08:29.541 6513-6536/com.example.mediacodec I/OMXClient﹕ Using client-side OMX mux.
04-21 18:08:29.541 6513-6536/com.example.mediacodec E/OMXMaster﹕ A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one.
04-21 18:08:29.541 6513-6536/com.example.mediacodec I/﹕ @@@VOLOG Info THD 60471CD0: VOOMXPlugin.cpp VOOMXPlugin 59 open libvoOMXOne.so successfully. 0X5BB9A370
04-21 18:08:29.541 6513-6536/com.example.mediacodec E/﹕ VOLOG Info THD 60471CD0 voCOMXBaseConfig.cpp Open 368 The config file vomeOne.cfg could not be opened!
04-21 18:08:29.541 6513-6536/com.example.mediacodec I/SoftAVCEncoder﹕ Construct SoftAVCEncoder
04-21 18:08:29.541 6513-6536/com.example.mediacodec E/SoftAVCEncoder﹕ internalSetParameter: StoreMetadataInBuffersParams.nPortIndex not zero!
04-21 18:08:29.541 6513-6536/com.example.mediacodec E/OMXNodeInstance﹕ OMX_SetParameter() failed for StoreMetaDataInBuffers: 0x80001001
04-21 18:08:29.541 6513-6536/com.example.mediacodec E/ACodec﹕ [OMX.google.h264.encoder] storeMetaDataInBuffers (output) failed w/ err -2147483648
04-21 18:08:29.541 6513-6536/com.example.mediacodec I/ACodec﹕ setupVideoEncoder succeeded
04-21 18:08:29.541 6513-6537/com.example.mediacodec E/SoftAVCEncoder﹕ Failed to initialize the encoder: -8
04-21 18:08:29.551 6513-6536/com.example.mediacodec E/ACodec﹕ [OMX.google.h264.encoder] ERROR(0x80001001)
04-21 18:08:29.551 6513-6535/com.example.mediacodec E/MediaCodec﹕ Codec reported an error. (omx error 0x80001001, internalError -2147483648)
04-21 18:08:29.551 6513-6513/com.example.mediacodec D/AndroidRuntime﹕ Shutting down VM
04-21 18:08:29.551 6513-6513/com.example.mediacodec W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x417a8e48)
04-21 18:08:29.551 6513-6513/com.example.mediacodec E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.mediacodec, PID: 6513
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mediacodec/com.example.mediacodec.MyActivity}: java.lang.IllegalStateException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException
at android.media.MediaCodec.dequeueOutputBuffer(Native Method)
at com.example.mediacodec.MyActivity.onCreate(MyActivity.java:49)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
The same error can be reproduced on the Sony Xperia ZR. Both devices also support COLOR_FormatYUV420SemiPlanar, and it works well with the same parameters. I tried to run EncodeDecodeTestfrom the package android.media.cts, and it succeeds, but it looks like it only checks the first supported color format of the first supported codec, which in this case COLOR_FormatYUV420SemiPlanar.
source
share