Search code examples
android-mediaplayerexoplayer

Can I configure Exoplayer to pick H265 streams over H264 ones, when it has hardware support?


I'm using Exoplayer to playback HLS streams. Since the streams need to support a wide variety of devices, the HLS stream file contains both HEVC (H265) and AVC (H264) formatted video. The idea being that older devices without hardware support for HEVC should play the H264 streams, and devices with hardware support for the newer, better H265 format should use those.

This doesn't seem to happen on a default "SimpleExoplayer". An example stream with both formats can be found at: https://tungsten.aaplimg.com/VOD/bipbop_adv_example_hevc/master.m3u8

So here's the question: Can I configure Exoplayer for a HLS stream that offers video in both HEVC(H265) and AVC(H264) formats so that it plays the HEVC stream on devices that support it via hardware?

(As a first step, it would also be interesting to me how to find out whether a device has hardware support for a given codec. I found a variety of ways to list available codecs on Android devices, but I didn't see anything that tells me if it's hardware-supported or not.)


Solution

  • Yes you can do it, ExoPlayer internally uses mediaCodec to decode the stream. Consider below. enter image description here

    inorder to MediaCodec to pick your hardware decoder, you need to add your codec configuration in media_codecs.xml file located in device folder. Like below based on your mime type.

     <MediaCodec name="OMX.*.h264.decode" type="video/avc" >
            <Limit name="size" min="48x48" max="3840x2176" />
            <Limit name="alignment" value="2x2" />
            <Limit name="block-size" value="16x16" />
            <Limit name="blocks-per-second" min="1" max="783360" />
            <Limit name="bitrate" range="1-120000000" />
            <Feature name="adaptive-playback" />
            <Feature name="secure-playback" required="true" />
            <Limit name="concurrent-instances" max="32" />
        </MediaCodec>