简体   繁体   中英

Media Foundation get encoded bitrate

I am trying to get the encoded bitrate of an audio file (mp4, m4a, aac) using Media Foundation.

What I did is:

PROPVARIANT prop;
IMFSourceReader* reader;

MFCreateSourceReaderFromURL(filePath, NULL, &reader);
reader->GetPresentationAttribute(MF_SOURCE_READER_MEDIASOURCE, MF_PD_AUDIO_ENCODING_BITRATE,
                                                                                     &prop);

The second line ends with an error and with empty PROPVARIAT.

However, when I do:

reader->GetPresentationAttribute(MF_SOURCE_READER_MEDIASOURCE, MF_PD_DURATION, &prop);

It works fine.

Does anyone know what is the issue and/or are there any other approaches to get the encoded bitrate of an audio track?

Audio bitrate is a property of a track, not of a media file. Hence, you'd normally want to choose a specific track (yes, typically it's the first audio track even if the file is audio-only single track file) and query its attributes.

Presentation description would get you attributes like this (I list just a few relevant):

  • Key MF_MT_MAJOR_TYPE , vValue MFMediaType_Audio
  • Key MF_MT_SUBTYPE , vValue MFAudioFormat_AAC
  • Key MF_MT_AVG_BITRATE , vValue 125601
  • Key MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION , vValue 0
  • Key MF_MT_AAC_PAYLOAD_TYPE , vValue 0

If you only need an informational value, such as presented by Windows shell:

在此处输入图片说明

and you don't need Media Foundation otherwise (that is, just to access the value), you can use shell property handler to do this job for you. You would just request PKEY_Audio_EncodingBitrate property and the handler would leverage Media Foundation to retrieve that for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM