[英]How to read XingHeaders, VBRIHeaders and sampleCount from MP3 files using TagLib-C++
Is there a way to determine if an audio file has a variable bitrate, and extract the sampleCount() through the LibTag? 有没有办法确定音频文件的比特率是否可变,并通过LibTag提取sampleCount()? I need to find out 'cause the Qt QMediaPlayer class incorrectly calculates audio files duration with variable bitrate, and the only way to correct is discover if the audio has a variable bit rate and divide the length for sampleCount() duration.
我需要找出原因,因为Qt QMediaPlayer类错误地计算了具有可变比特率的音频文件的持续时间,而纠正的唯一方法是发现音频是否具有可变比特率并为sampleCount()持续时间除以长度。
Since the documentation TagLib is a bit confusing, I managed to create just the fileref 由于文档TagLib有点混乱,我设法只创建了fileref
void MainWindow::playerOnMediaStatusChanged(QMediaPlayer::MediaStatus status)
{
if (status == QMediaPlayer::BufferedMedia) {
QString mediafile = playlist->currentMedia().canonicalUrl().toString();
TagLib::FileRef fr(reinterpret_cast<constwchar_t*>(mediafile.utf16()),true);
//…
}
}
But I don't know how do for discover if the audio has a variable bit rate and its sampleCount() 但是我不知道如何发现音频是否具有可变的比特率及其sampleCount()
Yes, I know there is this topic , but is related to Sharp language 是的,我知道有这个话题 ,但是与夏普语言有关
Can you help me? 你能帮助我吗?
Thanks in advance 提前致谢
You need to be working with a TagLib::MPEG::File
to be able to access the XingHeader
. 您需要使用
TagLib::MPEG::File
才能访问XingHeader
。 Here's an example: 这是一个例子:
static void printXingHeader(const char *fileName)
{
TagLib::FileRef ref(fileName);
TagLib::MPEG::File *file = dynamic_cast<TagLib::MPEG::File *>(ref.file());
if(!file)
return;
TagLib::MPEG::Properties *properties = file->audioProperties();
const TagLib::MPEG::XingHeader *xingHeader = properties->xingHeader();
if(!xingHeader)
return;
std::cout << "total frames: " << xingHeader->totalFrames()
<< " total size: " << xingHeader->totalSize()
<< std::endl;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.