开发者

C++ Taglib Cover Art from MPEG 4 files

开发者 https://www.devze.com 2023-03-16 09:43 出处:网络
As a side/fun project I\'m building an audio player (Qt application), and one of the hurdles is displaying embedded cover art.With *.mp3 files this ended up not being too much of an issue, mainly than

As a side/fun project I'm building an audio player (Qt application), and one of the hurdles is displaying embedded cover art. With *.mp3 files this ended up not being too much of an issue, mainly thanks to the example provided here:

static QImage imageForTag(TagLib::ID3v2::Tag *tag)
{
    TagLib::ID3v2::FrameList l = tag->frameList("APIC");

    QImage im开发者_StackOverflow社区age;

    if(l.isEmpty())
        return image;

    TagLib::ID3v2::AttachedPictureFrame *f =
        static_cast<TagLib::ID3v2::AttachedPictureFrame *>(l.front());

    image.loadFromData((const uchar *) f->picture().data(), f->picture().size());

    return image;
}

However, how can embedded cover arts be extracted for MPEG 4 files (particularly *.m4a)?


Here is how to do it:

TagLib::MP4::File f(file);
TagLib::MP4::Tag* tag = f.tag();
TagLib::MP4::ItemListMap itemsListMap = tag->itemListMap();
TagLib::MP4::Item coverItem = itemsListMap["covr"];
TagLib::MP4::CoverArtList coverArtList = coverItem.toCoverArtList();
if (!coverArtList.isEmpty()) {
    TagLib::MP4::CoverArt coverArt = coverArtList.front();
    image.loadFromData((const uchar *)
    coverArt.data().data(),coverArt.data().size());
}

image is from the Qt QImage class, and "file" is simply a char* variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号