0

I have a file with .amr extension, and I want to get it's sample rate and number of channels using Microsoft Media Foundation. Further, I want to decode and get the uncompressed data.

I can successfully get those from .aac .mp4 and other file types but not from from a .amr file (or 3.gp file which contains .amr track).

So, for other types I do:

IMFSourceReader *m_pReader;
IMFMediaType *m_pAudioType;

MFCreateSourceReaderFromURL(filePath, NULL, &m_pReader);
m_pReader->SetStreamSelection(MF_SOURCE_READER_ALL_STREAMS, false);
m_pReader->SetStreamSelection(MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);
m_pReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, &m_pAudioType);

UINT32 numChannels,sampleRate;
m_pAudioType->GetUINT32(MF_MT_AUDIO_NUM_CHANNELS, &numChannels);
m_pAudioType->GetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, &sampleRate);

Consider there are no any errors during this code.

For .amr files, some garbage is being written in the numChannels and sampleRate.

Does anyone have experience with this and knows how to recognize and/or get proper channels and sample rate for further decoding?

BTW, Windows Media Player plays this file with no problems.

Thanks in advance.

mbaros
  • 825
  • 8
  • 31
  • Omitting the *required* error checking is indeed a good way to end up with garbage. – Hans Passant Nov 28 '16 at 16:49
  • I did'nt wrote error checking here but i did in my code. I wanted to make the code simple and understandable – mbaros Nov 28 '16 at 16:50
  • 1
    MF does have support for AMR and media source reports relevant parameters. I suppose you should have posted more complete code and/or sample AMR file (if it does not reproduce with something well known like [this one](http://cdn.online-convert.com/example-file/audio/amr/example.amr)). – Roman R. Nov 28 '16 at 20:13

1 Answers1

0

So I found out that it supports decoding for .amr files not encoding.

Just before we get this properties:

UINT32 numChannels,sampleRate;
m_pAudioType->GetUINT32(MF_MT_AUDIO_NUM_CHANNELS, &numChannels);
m_pAudioType->GetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, &sampleRate);

We have to set a new media type to our Source Reader

m_pAudioType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio)
m_pAudioType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_Float)
m_pReader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, NULL, m_pAudioType);
mbaros
  • 825
  • 8
  • 31