C++ Taglib Cover Art from MPEG 4 files

匿名 (未验证) 提交于 2019-12-03 07:50:05

问题:

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 image;      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)?

回答1:

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.



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