Media Foundation get encoded bitrate

陌路散爱 提交于 2019-12-25 07:54:56

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/41855473/media-foundation-get-encoded-bitrate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!