Thursday, December 13, 2012

[android-developers] Further Mediacodec API issues in Jellybean

Hello, 

I am using Samsung N7100 device to test encoding capabilities of mediacodec API, and I am not able to get any meaningful results. Basically, I am able to successfully  setup encoder, then I am able to enqueu input buffers, I am also getting 2 output buffers worth of data before the encoder gets stuck and no output buffer gets dequeued  anymore, causing input buffers to fail to enqueuing further data. I tried 3 supported device codecs (avc, 3gpp, mp4v-es) all with similar results. 

Here is how I setup: 

        codec = MediaCodec.createEncoderByType("video/avc");
MediaFormat format = MediaFormat.createVideoFormat("video/avc", WIDTH, HEIGHT);
format.setInteger(MediaFormat.KEY_BIT_RATE, 5000000);
format.setFloat(MediaFormat.KEY_FRAME_RATE, (float)7.5);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar  );
codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
codec.start();

Then I feed the encoder: 

int inputBufferIndex = codec.dequeueInputBuffer(TIMEOUT);
if (inputBufferIndex >= 0) {
convertRGBtoYUV420EncoderInput(rgbData, WIDTH, HEIGHT, codecInputBuffers[inputBufferIndex]);
codec.queueInputBuffer(inputBufferIndex, 0, codecInputBuffers[inputBufferIndex].capacity(), 0, 0);
}
else{
myLog.i("Cannot yet enque more data  #:" + inputBufferIndex);
}
 

And I get output data like so:

info = new MediaCodec.BufferInfo();
int outputBufferIndex = codec.dequeueOutputBuffer(info, TIMEOUT);
if (outputBufferIndex >= 0) {
byte[] dst = new byte[info.size];
codecOutputBuffers[outputBufferIndex].get(dst, 0, info.size);
                                codec.releaseOutputBuffer(outputBufferIndex, false);
                               }

 
When I set TIMEOUT to -1 the call to codec.dequeueOutputBuffer never returns after getting 2 output buffers worth of data (basically just AVC header). Also BufferInfo has only 0s and no usefull information, thus I dont get really any errors but buffers dont work. Is there anything else that needs to get setup e.g. filling input buffer with some further  codec config before I start feeding it real YUV video data???
Any help or working sample would be highly apreciated...

Thanks, 


-peter
 

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment