Android Mediacodec Decode H264 Raw Frame
Solution 1:
Getting -1 back from MediaCodec#dequeueOutputBuffer()
is normal. It just means it doesn't have any output ready yet.
It's not the case that you hand MediaCodec
a buffer of encoded data and immediately get a decoded buffer back. You hand it a buffer of data, which gets sent to the mediaserver
process, which feeds it into the hardware AVC decoder, which may still be initializing or maybe just likes to sit on a few frames. When the decoding process completes, the decoded data gets passed back through mediaserver
to your app process.
The trick is, the queueInputBuffer()
call returns immediately. In normal operation the input side of the decoder will run several frames ahead of the output side. When you're done feeding input you set the end-of-stream flag, and when you see EOS set on the output you know you've reached the end.
You can find various working examples on bigflake and in Grafika. The DecodeEditEncodeTest and EncodeDecodeTest examples work exclusively with raw H.264, the others use MediaExtractor
and MediaMuxer
to handle MP4 file wrappers.
Post a Comment for "Android Mediacodec Decode H264 Raw Frame"