androidandroid-mediacodec

Exception: Failed to find matching codec OMX.google.h264.decoder, error 0x80000000


I wonder what are the possible causes for this exception.

Stack trace: java.io.IOException: Failed to find matching codec OMX.google.h264.decoder, error 0x80000000
        at android.media.MediaCodec.native_setup(MediaCodec.java)
        at android.media.MediaCodec.<init>(MediaCodec.java:1912)
        at android.media.MediaCodec.createByCodecName(MediaCodec.java:1890)

The app actually searches the codec list and ensures OMX.google.h264.decoder exists before trying to use it.

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
    MediaCodecList mRegularCodecs = new MediaCodecList(MediaCodecList.ALL_CODECS);
    for (MediaCodecInfo mci : mRegularCodecs.getCodecInfos()) {
        if (mci.getName().contains("OMX.google.h264.decoder")) {
            try {
                MediaCodec mc = MediaCodec.createByCodecName("OMX.google.h264.decoder");
            } catch (Exception ex) {
                //log mci.getName() to show it is indeed "OMX.google.h264.decoder"
            }
        } else {
            //do nothing
        }
    }
} 

This works fine usually. The exception is rare. Could anyone shed some light on this? Could this be a temporary glitch of the OS and the app should keep trying?


Solution

  • Even if a specific codec exists on the device it's not guaranteed to always be available.

    Here are a couple of reasons for it not being available:

    Considering this my recommendation is:

    1. Do not depend on a hardcoded type of codec but rather use whatever codec supports your given video format (see https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities#isFormatSupported(android.media.MediaFormat) for example)
    2. For many popular formats there are more than one codec types. If you fail to create / configure one type of codec try to move on to another type that supports your format.
    3. Be ready to handle the situation when no codec is available at the moment.