google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

Output container bitrate values from `MetadataRetriever` (for parity with `android.media.MediaMetadataRetriever`) #10276

Open besarmemishi opened 2 years ago

besarmemishi commented 2 years ago

Question

I wonder why for some audio/video files (https sources) the bitrate returns -1, while the Android MetadataRetriever returns correct bitrate.

Example


val trackGroupArray = MetadataRetriever.retrieveMetadata(
            context,
            mediaItem
).await()

  for (arrayIndex in 0 until trackGroupArray.length) {
            val trackGroup = trackGroupArray[arrayIndex]

            for (groupIndex in 0 until trackGroup.length) {
                val sampleMimeType = trackGroup.getFormat(groupIndex).sampleMimeType

                if (sampleMimeType?.contains("audio") == true) {
                    return trackGroup?.getFormat(0)?.bitrate   // bitrate -1
                }
            }
        }

Version

com.google.android.exoplayer:exoplayer:2.17.1

icbaker commented 2 years ago

-1 is Format.NO_VALUE - so this suggests that ExoPlayer's MetadataRetriever didn't read a bitrate value from the provided media.

Have you read the caveats on Format.averageBitrate and Format.peakBitrate as to when you will see NO_VALUE (since bitrate is just one or other of these values)?

ExoPlayer metadata extraction is motivated by the information needed for playback. For non-adaptive playback (e.g. just an MP4 file) the bitrate isn't very useful, because there are no adaptive track selection decisions to be made - so it's often not read from these sorts of files.

while the Android MetadataRetriever returns correct bitrate.

I assume you mean android.media.MediaMetadataRetriever here?

icbaker commented 2 years ago

I'm marking this as an enhancement to output these values from MetadataRetriever. Just to set expectations: we currently have no plans to work on this.

besarmemishi commented 2 years ago

Yes, I meant `android.media.MediaMetadataRetriever``

I am using Exo MetadataRetriever as it is extremly faster comparing to MediaMetadataRetriever.

When I receive -1 which happens for most of .mp3 files, also the Format.averageBitrate and Format.peakBitrate are -1

Url: https://download.samplelib.com/mp3/sample-15s.mp3

image

OxygenCobalt commented 1 year ago

May be willing to work on this in the future if I get enough time. How feasible is it to get an approximate bitrate for VBR progressive containers @icbaker? One of the big reasons I want this to be added is so that I can show a correct approximate bitrate for VBR files, something that MediaExtractor doesn't do.

Tolriq commented 1 year ago

For the record Exoplayer already extract the mp3 bitrate, in mp3extractor.java readInternal you can just add .setAverageBitrate(synchronizedHeader.bitrate).

Wanted to check for more formats and it's not that hard for Alac and FLAC (at least approximate).

I also wanted to expose bit per sample for FLAC but I'm not sure if adding a new field to MetaData would have been accepted.