Search code examples
androidandroid-mediacodec

Android MediaCodec not working


I'm trying to directly decode the H.264 encoded camera output of the Raspberry Pi camera module on an android device, but my code fails to properly decode the file. I get no output, and as the last frame I get a garbled image.

As I am parsing the input file myself (it is an H.264 byte-stream) into NAL units, I'm left with a question: when feeding them to the MediaCodec buffers, do I feed the NAL unit separator into the buffer as well?


Solution

  • The MediaCodec decoder requires an H.264 elementary stream, and wants one access unit per buffer. You also need to supply SPS/PPS before the first data packet (either through the BUFFER_FLAG_CODEC_CONFIG flag or by adding it to the MediaFormat).

    See also this question.