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?)
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.
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
etc/media_codecs.xml, (it seems to be in
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.
Now, let’s see what’s inside in
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
You can try to play AV1-encoded video on your Android Q device using ExoPlayer.