How do I use TagLib to read/write coverart in different audio formats?

后端 未结 4 1969
温柔的废话
温柔的废话 2021-02-02 02:40

I would like to use TagLib to read/write coverart especially for mp3 AND ogg files, but I couldn\'t find any examples. Could someone point me to some examples? Where should I lo

4条回答
  •  一整个雨季
    2021-02-02 03:24

    I got it to work for mp3 files. See if you can adapt it for ogg

    Good luck.
    PS::This tagging stuff is way harder than it should be. We need to find another lib.

    /*********************************************************************************************************************************
     *Description: A simple program using taglib to extract pictures attached to mp3 id3v2 tags
     *Author: Dr Deo [at] stackoverflow *dot* com
     *AOB: I hope you will find this useful and are free to use it for anything, but there is no waranty and use at your own risk :)
     *********************************************************************************************************************************
    */
    #include
    #include
    
    /*taglib specific includes*/
    #include//ByteVector
    #include//mp3 file
    #include//tag
    #include//frame
    #include //attachedPictureFrame
    
    using namespace std ;
    using namespace TagLib::ID3v2 ;
    
    int main(int argc, char * argv[])
    {
        if(argc !=2)
        {
            cout<<"usage: drag an mp3 file on to the program and it will extract the attached image"<frameListMap()["APIC"];//look for picture frames only
            if(!listOfMp3Frames.isEmpty())
            {
                FrameList::ConstIterator it= listOfMp3Frames.begin();
                for(; it != listOfMp3Frames.end() ; it++)
                {
                    pictureFrame = static_cast (*it);//cast Frame * to AttachedPictureFrame*
    
                    //Warning. format of picture assumed to be jpg. This may be false, for example it may be png.
                    FILE * fout;
                    fopen_s(&fout, "outputFile.jpg", "wb");
                    cout<<"processing the file "<< argv[1] <picture().data(), pictureFrame->picture().size(), 1, fout);
                    fclose(fout);
                    cout<<" The picture has been written to \t outputFile.jpg  \nRemember that the file type .jpg is just assumed for simplicity"<

提交回复
热议问题