Question

Following this i have tried below code to initialize MediaCodec, but it failed! The github hosted project runs without any problem. The updated log is as below

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)

The code - Updated after fadden's answer

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");
Was it helpful?

Solution

Looks like you're not configuring all of the mandatory keys.

See the MediaFormat doc, and note where it says "all keys not marked optional are mandatory".

Update:

It's crashing on a failed assertion. Judging by the line number and the assert message, you're running jb-mr1 (Android 4.2, API 17); source file is here.

It's complaining about the "native window", which is another way of saying it doesn't like the surface you're passing in. Since you're configuring an encoder, you shouldn't be passing in a surface at all -- that's only for rendered output. Change mSurface to null.

If you want to provide input through a Surface, you need to use MediaCodec#createInputSurface(), which isn't available until API 18.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top