Does ML2 support hardware h.264 decoding through the MediaCodec API?


I'm decoding h264 streams from the user's desktop using FFMPEG/libavcodec, which currently does it on the CPU. I see the custom H264 decoding in the docs for ml_media_decoder, but I'm wondering if ML2 supports Android's MediaCodec (which I would be able to access through libavcodec). Or if there's a way I can just swap out avcodec_send_packet & avcodec_receive_frame for something in the ML2 API.


For anyone wondering, here's what I found using the isHardwareAccelerated method of MediaCodec :slight_smile:

1 Like

Hi @hollowaya, thank you for your message. Magic Leap 2 does support HW H264 decoding, it is listed above as OMX.mesa.video_decoder.avc and it should be available and functional through standard AOSP interfaces also using the mime type video/avc when creating the decoder. Also, the Magic Leap 2 API can also use it.

When you mean through AOSP interfaces, do you mean the AMediaCodec?
if so, I would appreciate if there were examples on how to use it to decode h264 frames.

Yes, AMediaCodec_createDecoderByType("video/avc"); should create the HW h264 decoder, i.e. OMX.mesa.video_decoder.avc

From this, any decoding example using the Android NDK should be fine (for example AImageReader is a possible mechanism to handle decoded buffers).

See also the example code here: android ndk - Fetch raw data from an Image acquired from an AImageReader - Stack Overflow

This post is super helpful but I'm curious if anyone has an example of how to use the mediacodec decoder with the FFmpeg libav* apis. I'm also using libavvodec on the ML2 and I tried following along with the hwaccel example from FFmpeg but when I list the available hw decoders, none show up. I made sure MediaCodec is compiled into the version of libavcodec I'm using and I already have the stream decoding working using the FFmpeg API (software decode). I'd much rather figure out how to enable hw acceleration rather than switch to using another API. Per the FFmpeg docs, it does support MediaCodec hw decoding.