Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decoding the output buffer from MediaCodec

I'm using the Android MediaCodec library to decode a video stored on the file system. I get an output buffer that looks legit (with proper bufferinfo.offset and size). Its format seems to be 256 (which is JPEG). I tried decoding it with BitmapFactory.decodeByteArray, but the result was null.

Does anyone know the correct way to ascertain the format of the output buffer? What's the correct way to start decoding the output byte arrays?

like image 377
Utkarsh Sinha Avatar asked Nov 02 '22 16:11

Utkarsh Sinha


1 Answers

The MediaCodec color formats are defined by the MediaCodecInfo.CodecCapabilities class. 256 is used internally, and generally doesn't mean that you have a buffer of JPEG data. The confusion here is likely because you're looking at constants in the ImageFormat class, but those only apply to camera output. (For example, ImageFormat.NV16 is a YCbCr format, while COLOR_Format32bitARGB8888 is RGB, but both have the numeric value 16.)

Some examples of MediaCodec usage, including links to CTS tests that exercise MediaCodec, can be found here. On some devices you will not be able to decode data from the ByteBuffer output, and must instead decode to a Surface.

like image 116
fadden Avatar answered Nov 12 '22 11:11

fadden