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?
No one has answered this question yet
Check out similar questions: