How to use MediaCodec without MediaExtractor for H264
I'm assuming you're reading a raw H.264 elementary stream and not an MP4 file.
It looks like you're feeding fixed-size blocks of data to the decoder. That doesn't work. You need to put a single access unit into each buffer.
Decode mp4/h.264 using MediaCodec without MediaExtractor, expected access unit format
The NAL length prefixes that specify the NAL unit length need to be converted to Annex-B startcodes (bytes 0x00, 0x00, 0x00, 0x01) before passing to MediaCodec for decoding. (Some decoders might actually accept the MP4 format straight away, but it's not too common.)
The SPS/PPS that is stored in the avcC atom in the file also needs to be converted to use Annex-B startcodes. Note that the avcC atom contains a few other fields that you don't need to pass on to the decoder. You can either pass the SPS and PPS packed in one buffer (with startcodes before each of them) with the BUFFER_FLAG_CODEC_CONFIG flag set before sending any actual frames, or pass them (with Annex-B startcodes) in the MediaFormat you use to configure the decoder (either in one ByteBuffer with the key "csd-0", or in two separate keys as "csd-0" and "csd-1").
If your file has got more SPS/PPS inside each frame, you should just be able to pass them as part of the frame, and most decoders should be able to cope with it (especially if it's the same SPS/PPS as before and not a configuration change).
Thus: Pass all NAL units belonging to one sample in one single buffer, but with all NAL unit length headers rewritten to startcodes. And to work with MP4 files that don't happen to have SPS/PPS inside the stream itself, parse the avcC atom (I don't know in which format mp4parser returns this) and pass the SPS and PPS with startcodes to the decoder (either via MediaFormat as "csd-0" or as the first buffer, with BUFFER_FLAG_CODEC_CONFIG set).
Related Topics
Convert Existing Project to Library Project in Android Studio
Android: How to Update a Imageview/Imagebutton with a Number to Show the Number of New Messages
Failed to Read Png Signature: File Does Not Start with Png Signature
How to Send Location of the Device on Server When Needed
Tapping Form Field in Webview Does Not Show Soft Keyboard
Dagger 2 Injecting Android Application Context
Can't Handle Both Click and Touch Events Simultaneously
Searchview in Optionsmenu Not Full Width
Using the New "Manifestmerger" Property in Android
After Update of as to 1.0, Getting "Method Id Not in [0, 0Xffff]: 65536" Error in Project
How to Change Background Image of Button When Clicked/Focused
Change Date String Format in Android
Nullpointerexception from Google Maps
Android Emulator - Trouble Creating User Accounts
Kitkat Kills: Not Allowed to Load Local Resource: File:///Android_Asset/Webkit/Android-Weberror.Png