Android MediaCodec decodes raw h.264

I am having a very difficult time with MediaCodc. I used to use it to decode a raw h.264 stream and found out a significant amount. At least I thought I have.

My h.264 stream is in Appendix B. Looking at the original data, the structure of my NAL packet code types is as follows:

[0x09][0x09][0x06] and then 8 packets of [0x21].
[0x09][0x09][0x27][0x28][0x06] and then 8 packets of [0x21].

      

This is not how I get them. I am trying to build a complete access unit from these raw NAL types.

The first thing that weird to me is the double [0x09], which is the Delimiter Access Unit package. I'm pretty sure the h.264 document only states 1 AUD per access unit. BTW, I can write raw data and play it back using ffmpeg with and without additional AUD. At the moment I am detecting this message and deleting the first one before sending the whole access block to the MediaCodec.

Second, I have hardcoded the messages of the SPS / PPS byte array [0x27 / 0x28] and I set them to the MediaFormat which is used to initialize the MediaCodec, similarly:

format.setByteBuffer("csd-0", ByteBuffer.wrap( mySPS ));
format.setByteBuffer("csd-1", ByteBuffer.wrap( myPPS ));

      

The video stream provider tells me that the video is 1280 x 720, however when I convert it to mp4 file the metadata says it is 960 x 720. Another oddity.

By changing these different parameters, I still cannot get in my stream the valid index of the buffer that is processing the decoder output (dequeueOutputBuffer returns -1). I also changed the timeout for this to no avail. If I manually set SPS / PPS as the first NOT packet using the above example, I get that "output buffers have been changed", which is pointless since I am using API 20. But everything else I get is -1.

I read about encoding the h.264 warning emulation bytes. I can remove this byte and send to MediaCodec. Doesn't seem to matter. Also, the documentation for MediaCodec does not explicitly state whether the EPB code expects or not ...?

Apart from the video resolution, the only thing that differs from my previous success is the presence of the SEI packet type [0x06]. I'm not sure if I should be doing something special with this or not?

I know that a lot of people who have used MediaCodec have had problems with it, mainly because the documentation is not very good. Can anyone suggest any other advice as to what I might be doing wrong?

+3
android h.264 mediacodec


source to share


No one has answered this question yet

Check out similar questions:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
7
How can I feed H.264 NAL units in Android MediaCodec for decoding?
6
Decoding mp4 / h.264 using MediaCodec without MediaExtractor, expected access block format
3
Android Decode raw h264 stream with MediaCodec
1
Android MediaCodec not working
1
h264 Raw video stream format
1
Mediacodec Decoding h264 OutputBuffer Index Returns -1



All Articles
Loading...
X
Show
Funny
Dev
Pics