Decoders/Encoders on Android

Taku Semba
3 min readJul 5, 2019
Decoders / Encoders on Android

Decoders and Encoders are very important components when handling media sources, and Android devices have multiple decoders/encoders on them. While Android supports a different kind of codecs and container formats, Android API provides ways to decode/encode those specific data.

MediaCodec can be used to access a certain encoder/decoder components on an Android device. For example, you can input raw video data to encode it into H264 encoded data, or pass AAC-encoded audio samples to decode and play the music.

However, how can I know that what kind of decoders/encoders are available on my device or what a retrieved decoder/encoder is capable of? (How much bitrate does it support? Can it handle 48000Hz audio data?)

That’s where MediaCodecList comes in. MediaCodecList allows you to query available decoders/encoders on your device.

Let’s see an example code to find decoders/encoders on my Pixcel3 device and capabilities of those.

encoders/decoders
capabilities of a decoder

As you can see, there are 68 decoders/encoders on my Pixcel3, and c2.android.avc.decoder , which is one of the found decoders on Pixcel3, supports a range of 1 to 48M bitrate and a range of 0 to 960 frame rate.

An easier way to query decoders/encoders

Sometimes, I have a situation where a specific Android device fails to decode video or audio samples with some DecoderInitializationException on ExoPlayer and want to know the capabilities of the decoder and other possible decoders that might be able to use.

It takes time to write code to query decoders using MediaCodecList or add breakpoints to stop where ExoPlayer is trying to query decoders, but there is an easier way for this.

Inside an Android device, you can find media_codecs.xml located etc/media_codecs.xml, (it seems to be in etc/media_codecs.xml, vender/etc/media_codecs.xml, odm/etc/media_codecs.xml if it’s after Android 8.1.)

You will see how MediaCodecList.cpp is trying to find decoders/encoders from the framework source code.

http://androidxref.com/4.4.2_r2/xref/frameworks/av/media/libstagefright/MediaCodecList.cpp#49

http://androidxref.com/8.1.0_r33/xref/frameworks/av/media/libstagefright/xmlparser/include/media/stagefright/xmlparser/MediaCodecsXmlParser.h#35

Now, let’s see what’s inside in media_codecs.xml.

vendor/etc/media_codecs.xml

You can confirm that there are multiple decoders/encoders, and those capabilities are listed up in the XML file.

AV1 support on Android Q

Google announced that Android Q supports AV1, which is a royalty-free video coding format and have much higher data compression than VP9 or HEVC/H.265.

What it means is that if you install Android Q on your device, AV1 decoder will be installed (I could not find AV1 encoders) and the AV1 decoder is described in the media_codecs.xml.

media_codecs_google_c2_video.xml

You can try to play AV1-encoded video on your Android Q device using ExoPlayer.

https://github.com/google/ExoPlayer/commit/a5616cb552a4c07e03f848d1f35f44d85b4a0564

References

--

--