Mediacodec.dequeueoutputbuffer Taking Very Long When Encoding H264 On Android
Solution 1:
Yes, there is something wrong with your code - you are waiting synchronously for the current frame to be output from the encoder before proceeding with the next frame. Most hardware codecs have a bit more latency than you would expect, and in order to get the proper throughput as the encoder is capable of, you need to use it asynchronously.
That is, after sending one input buffer for encoding, you should not wait for the encoded output buffer, but only check if there is output. You should then go on and input the next buffer, and again check for any available output. Only once you don't get an input buffer immediately, you can start waiting for output. This way, there's always more than one input buffer available for the encoder to start working on, to keep it busy to actually achieve the frame rate that it is capable of.
(If you are ok with requiring Android 5.0, you could take a look at MediaCodec.setCallback
, which makes it easier to work with asynchronously.)
There are even some codecs (mainly decoders though, if my memory serves me correctly) that won't even output the first buffer until you have passed more than a few input buffers.
Post a Comment for "Mediacodec.dequeueoutputbuffer Taking Very Long When Encoding H264 On Android"