CoffeeLexer
CoffeeLexer

Reputation: 101

Android AudioVideo Framework can not read metadata correctly

I've been trying to open *.mp4 media file on specific Android devices. Once I open it MediaFormat data has undefined language on audio tracks. If I then upload same app on different device, it decodes it correctly.

As of now, I tried MediaPlayer, MediaMetadataRetriever and MediaExtractor API's. Same issue is reproducible with C++ native code using AMediaExtractor API.

Example:

        val me = MediaExtractor()
        val fis = resources.openRawResourceFd(R.raw.mp4)
        me.setDataSource(fis.fileDescriptor, fis.startOffset, fis.length)
        val format = me.getTrackFormat(1)
        val language = format.getString(MediaFormat.KEY_LANGUAGE)

On Android 9 Razer Phone 2 this would return undefined, while any other of devices it works correctly and returns actual language info.

I've also reproduced same issue on Android 8.1.0 Asus Rog Phone

MIME for same track is audio/mp4a-latm. I've tried *.m4a audio file, but it has same issue.

Decoder on faulty devices seems to be OMX.google.aac, but I've found other devices with this decoder that work just fine.

MediaFormat data Good Device (Galaxy 21 Plus) Bad Device (Razer Phone 2)
max-bitrate 96000 96000
isDMCMMExtractor 1 1
sample-rate 48000 48000
track-id 2 2
mime audio/mp4a-latm audio/mp4a-latm
profile 2 Field Missing
bitrate 96000 96000
language dan und
aac-profile 2 2
track-fourcc -1 Field Missing
encoder-delay 2112 Field Missing
durationUs 725333 725333
channel-count 2 2
bits-per-sample 16 16
encoder-padding 705 Field Missing
max-input-size 524308 65538
csd-0 [17, -112] [17, -112]

File used is generated using FFMPEG CLI and has 8 audio tracks, but I've also extracted audio from it and used to test with same issue

Upvotes: 3

Views: 51

Answers (1)

dev.bmax
dev.bmax

Reputation: 11151

Razer Phone 2 is a relatively old device (released in 2018). And I don't have one to verify the hypothesis.

According to AOSP there was a change made in November 2018 to use AMediaFormat in MPEG4Extractor.cpp.

Specifically, AMEDIAFORMAT_KEY_LANGUAGE (string value "language") is used instead of kKeyMediaLanguage (string value "lang").

So I suspect that Razer Phone 2 stores the language in the media format map under the key "lang", but you are looking for "language".

Upvotes: 1

Related Questions