我只是自己弄清楚了这一点。
视频文件中的元数据不包含比特率。它仅包含有关对播放没有任何影响的媒体的额外信息。因此,即使 Phonon::MediaObject::metaData() 在没有加载视频的情况下工作,它也无济于事。
我最终使用了 libformat,它是 ffmpeg 库的一部分来获取比特率。这是代码。
如果您复制并粘贴它,它应该可以工作。
在此处下载 FFMpeg:http ://dranger.com/ffmpeg/tutorial01.html
第一个教程将告诉您如何链接:http ://dranger.com/ffmpeg/tutorial01.html
#include <QString>
#include <QMultiMap>
#include <stdio.h>
#include <libavformat/avformat.h>
#include <libavutil/dict.h>
void processMedia(const char* mediaFile)
{
AVFormatContext *pFormatCtx = NULL;
AVDictionaryEntry *tag = NULL;
// Register all formats and codecs
av_register_all();
// Open video file
if(avformat_open_input(&pFormatCtx, mediaFile, NULL, NULL)!=0)
return;
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
return;
//Get Bitrate
float bitRate = pFormatCtx->bit_rate;
//Get Meta
QMultiMap<QString, QString> metaData;
while ((tag = av_dict_get(pFormatCtx->metadata, "", tag,
AV_DICT_IGNORE_SUFFIX)))
{
QString keyString(tag->key);
QString valueString(tag->value);
metaData.insert(keyString, valueString);
printf("%s=%s\n", tag->key, tag->value);
}
// Close the video file
av_close_input_file(pFormatCtx);
}