9

I am successfully using MediaCodec to decode audio, however when I load a file with 24-bit samples, I have no way of knowing this has occurred. Since the application was assuming 16-bit samples, it fails.

When I print the MediaFormat, I see

{mime=audio/raw, durationUs=239000000, bits-format=6, channel-count=2, channel-mask=0, sample-rate=96000}

I assume that the "bits-format" would be a hint, however this key is not declared in the API, and is not actually emitted when the output format changes. I get

{mime=audio/raw, what=1869968451, channel-count=2, channel-mask=0, sample-rate=96000}

(By the way what is the "what" key? I notice if I interpret as a 4charcode, it is "outC"... just a flag that it is an output format?)

So what is the best recourse here? If I feed the ByteBuffer straight to the AudioTrack it plays static of course (assuming PCM 16).

If I know the value, then I can convert it myself! I understand from other questions that you cannot dictate the output format either.

yano
  • 4,095
  • 3
  • 35
  • 68
  • I haven't worked much with audio, but generally speaking MediaCodec requires you to tell it the format, not the other way around. MediaExtractor is responsible for parsing the audio file header. I *think* you want to divide KEY_BIT_RATE by (KEY_CHANNEL_COUNT * KEY_SAMPLE_RATE) to get the bits per sample. Are you using MediaExtractor to open the file? – fadden May 15 '15 at 15:34
  • Yes I'm using MediaExtractor to open the file. The first line MediaFormat I quote is all the data printed...as you can see there is no bit rate, otherwise I think your idea would work – yano May 15 '15 at 22:32
  • Did you ever find a solution to this? I'm facing the same problem... – NaxyMatt Jan 28 '18 at 02:09
  • Hi, did you find the solution? I'm trying to play audio with 24-bit PCM too. – Mauro Bilotti Sep 26 '18 at 22:08

0 Answers0