androidandroid-mediaplayercolor-spacehdr

Get the bit depth or the color space of a mp4 file in Android


I'm currently working on a video player on Android. The video player should support 8 bit content and 10 bit content. Because the flow in the app is different, I need to know before playing the video if the content is 10-bit BT2020. I've tried MediaMetadataRetriever but there is no information about the bit depth, color space, color primaries, transfer characteristics etc. Also, I got the same result using this project: https://github.com/wseemann/FFmpegMediaMetadataRetriever.

Is there a way to get some more information about the color space or bit depth in Android? Something similar to MediaInfo tool. https://mediaarea.net/en/MediaInfo


Solution

  • After some time I found out that I can use MediaExtractor then get the information that I needed from a MediaFormat object created with extractor.getTrackFormat(trackIndex). For HDR10 I check the color standard and the transfer function.

    mediaFormat.containsKey(MediaFormat.KEY_COLOR_STANDARD)
    ) {
        if (mediaFormat.getInteger(MediaFormat.KEY_COLOR_TRANSFER) == MediaFormat.COLOR_TRANSFER_ST2084
            && mediaFormat.getInteger(MediaFormat.KEY_COLOR_STANDARD) == MediaFormat.COLOR_STANDARD_BT2020
        ) {
            return true
        }
    }