继此我曾尝试下面的代码初始化MediaCodec,但它失败了! GitHub的托管项目运行没有任何问题。 更新日志如下
01-27 02:02:25.125: I/OMXClient(8956): Using client-side OMX mux.
01-27 02:02:25.140: I/ACodec(8956): setupVideoEncoder succeeded
01-27 02:02:25.140: E/OMXNodeInstance(1910): OMX_GetExtensionIndex failed
01-27 02:02:25.140: A/ACodec(8956): frameworks/av/media/libstagefright/ACodec.cpp:3234 CHECK_EQ( (status_t)OK,mCodec->initNativeWindow()) failed: 0 vs. -2147483648
01-27 02:02:25.140: A/libc(8956): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 8990 (CodecLooper)
代码 - 法登的答案后更新
format = MediaFormat.createVideoFormat("video/avc", 480, 800);
format.setInteger(MediaFormat.KEY_BIT_RATE,400000 );
format.setInteger(MediaFormat.KEY_FRAME_RATE, 25);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5);
coder = MediaCodec.createEncoderByType("video/avc");
// coder = MediaCodec.createDecoderByType("video/avc");
if(format != null)
coder.configure(format, mSurface, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
Log.e("After","Configure");