H.264 decoding with Android MediaCodec

I have a lot of problems with h.264 decoding from Android MediaCodec

. I am getting raw h.264 stream from drone via custom API (provided). The API gives me byte [] values.

Quite simply, I initialize the decoder MediaCodec

like this (I have SPS and PPS declared elsewhere):

int width = 640;
int height = 480;
videoFormat = "video/avc";

format = MediaFormat.createVideoFormat( videoFormat, width, height );
format.setString("KEY_MIME", videoFormat );

mCodec = MediaCodec.createDecoderByType( videoFormat );

format.setByteBuffer("csd-0", ByteBuffer.wrap( NAL_sps ));
format.setByteBuffer("csd-1", ByteBuffer.wrap( NAL_pps ));

mCodec.configure( format, null, null, 0 );      

      

I am not currently passing dequeuedOutputBuffer

mine Surface

so I can check what comes out.

The weird problem is that as soon as I get the correct output buffer from the decoder, the result is garbage. For my 640 x 480 test, the number of bytes I get from the decoder is correct (460800 bytes), which I assume is Semi Planar 4: 2: 0 (640x480x1.5). However, the values ​​represent all junk, i.e. 0x80 0x80 0x80

... for the entire byte array.

Does anyone know if there are h.264 limitations for what can decode MediaCodec

? I noted that according to the API MediaFormat

"all keys not marked as required are required". I tried to set all the "required" fields for MediaFormat

and still don't find any valid output.

I tried to decode the data directly on mine Surface

and noticed that most of the window is gray and sometimes I get multiple scan lines that look like a valid video and then back to gray.

Any idea what might be causing this behavior?

+3
android decoding codec 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?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1844
What is "Context" on Android?
6
Decoding mp4 / h.264 using MediaCodec without MediaExtractor, expected access block format
3
Android MediaCodec decodes raw h.264
1
Mediacodec Decoding h264 OutputBuffer Index Returns -1



All Articles
Loading...
X
Show
Funny
Dev
Pics