2

I am using the new MediaCodec API on Jelly Bean to decode an h264 stream. Using the code snippets in the developer page , instantiated a decoder by name (taken from media_codec.xml), passed a surface and configured the codec.

The problem I am facing is, dequeOutputBuffer always returns -1.
Tried with a negative timeout to wait indefenitely, no luck with that.
Whenever I get a -1, refreshed the buffers using getOutputBuffers.

Please note that the same issue is seen when a custom app is used to parse the data from a media source and provide to decoder.

Any inputs on the above will be helpful

fadden
  • 51,356
  • 5
  • 116
  • 166
Lakshmi
  • 21
  • 3

4 Answers4

1

I had faced same problem. Incrementing presentationTimeUs parameter of queueInputBuffer() on each call solved the issue.

For example, codec.queueInputBuffer(inputBufferIndex, 0, data.size, time, 0) time += 66 //incrementing by 1 works too

Al Mamun
  • 944
  • 9
  • 27
0

If anyone else is facing this problem (as I did today) while starting with MediaCodec make sure to release the output codecs after you're done with them:

mediaCodec.releaseOutputBuffer(index, render); 

or else the codec will run out of available buffers pretty soon.

Ademar
  • 5,657
  • 1
  • 17
  • 23
lkjh
  • 1
0

It may be necessary to feed several input buffers before obtaining data in output buffer.

ivan_onys
  • 2,282
  • 17
  • 21
0

-1 is INFO_TRY_AGAIN_LATER, meaning the output buffer queue is still being prepared and you just need to call dequeueOutputBuffer again.

Try using a work loop that calls dequeueOutputBuffer in a loop similar to ExoPlayer:

    while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
    if (feedInputBuffer(true)) {
      while (feedInputBuffer(false)) {}
    }

where drainOutputBuffer is a method that calls dequeueOutputBuffer.

Peter Tran
  • 1,626
  • 1
  • 17
  • 26