本文介绍了Taglib从任意文件C ++读取ID3v2标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用TagLib C ++ API从任意音频文件中读取ID3v2元数据.该文件不一定是 .mp3 文件,并且可以是其他常见的音频格式.我有以下内容:

I'm trying to use the TagLib C++ API to read ID3v2 metadata from an arbitrary audio file. This file is not necessarily an .mp3 file, and may be of the other common audio formats. I have the following:

std::string readId3v2Tag(std::string filePath, std::string tagName) {
    // read from file
    TagLib::FileRef f(filePath.c_str());
    if (!f.isNull() && f.file()) {
        // get tags from property map
        TagLib::PropertyMap tags = f.file()->properties();
        if (tags.find(tag) != tags.end()) {
            return std::string(tags[tag][0].toCString());
        }
    }
}

但是,当我输入ID3v2框架名称时,它不会返回任何内容.我相信这是因为 f.file()-> properties()映射包含TagLib的标签格式.我必须能够按名称访问ID3v2帧.

However, when I input an ID3v2 frame name, it doesn't return anything. I believe this is because the f.file()->properties() map contains TagLib's tag format. I must be able to access ID3v2 frames by name.

有人告诉我要使用 ID3v2 类,但是我看不到如何从文件中访问它,并且在阅读API文档时遇到了麻烦.有人知道该怎么做吗?

I have been told to use the ID3v2 class, however I don't see how to access this from a file, and am having trouble reading the API docs. Does anyone know how to do this?

推荐答案

始终阅读手册:它告诉您不要使用 file()方法.同样, properties()不会为您提供ID3v2标签框架-您应该迭代所有这些框架以查看其键和值.

Always read the manual: it tells you to not use the file() approach. Also properties() won't give you ID3v2 tag frames - you should iterate all of them to see their keys and values.

相反

  • 使用 MPEG :: File (请参阅手册)和从那里开始/继续阅读
  • 通过 ID3v2Tag()(请参见手册)
  • frameList()(请参阅手册)
  • use MPEG::File (see manual) and from there go/read on
  • over ID3v2Tag() (see manual)
  • to frameList() (see manual).

一旦明确术语,这将非常简单:文件可以具有零到多个标签,其中ID3v2标签可以具有一到多个.但是,仅文件本身还可以具有多个未绑定到标签的属性(即音频持续时间,位深度...)-难怪您搜索的所有 frame 名称都没有不会显示在文件的属性中.

It's pretty straightforward once the terms are clear: a file can have zero to multiple tags, where a ID3v2 tag can have one to multiple frames. The file alone however can also have multiple properties that are unbound to tags (i.e. audio duration, bit depth...) - no wonder that none of your frame names you search for won't show up in the file's properties.

这篇关于Taglib从任意文件C ++读取ID3v2标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 13:42