Help - Search - Members - Calendar
Full Version: writing tags using mp4v2
Hydrogenaudio Forums > Lossy Audio Compression > AAC > AAC - Tech
unclenorton
Hello!

I am using mp4v2 library to read and write mp4 metadata. The interface of the library is pretty simple, that is: allocation of structure, getting/setting the required filters, freeing the structure, and storing the file. However, for me, it doesn't work as simple as it seems. The problem is that, while reading is ok, functions like MP4TagSet*** do not seem to work. The only scenario in which they do, is when I use the deprecated MP4SetMetadata*** functions *alongside*. This is rather strange, because: a) the values stored are those from MP4TagSet function; b) Not all the fields are set.

This is the code I use. Rather obvious, but still...

CODE
    MP4FileHandle MP4hFile = MP4_INVALID_FILE_HANDLE;

    MP4hFile = MP4Create(destname, MP4_DETAILS_ERROR, 0);

    ifstream tagfile(tagname);
        const MP4Tags* tags;
    if (tagfile.good())
    {
        string sbuf;
        int tagid = 0;
        tags = MP4TagsAlloc();
        MP4TagsFetch(tags, MP4hFile); // in case tags are present already

        while (getline(tagfile, sbuf))
        {
            //(tagfile, sbuf);
            switch (tagid)
            {
            case 0:
                MP4TagsSetName(tags, sbuf.c_str());
//                MP4SetMetadataName(MP4hFile, sbuf.c_str());
                break;
            case 1:
                MP4TagsSetArtist(tags, sbuf.c_str());
//                MP4SetMetadataArtist(MP4hFile, sbuf.c_str());
                break;
            case 2:
                MP4TagsSetAlbum(tags, sbuf.c_str());
//                MP4SetMetadataAlbum(MP4hFile, sbuf.c_str());
                break;
            case 3:
                MP4TagsSetReleaseDate(tags, sbuf.c_str());
//                MP4SetMetadataYear(MP4hFile, sbuf.c_str());
                break;
            case 4:
                MP4TagsSetComments(tags, sbuf.c_str());
//                MP4SetMetadataComment(MP4hFile, sbuf.c_str());
                break;
            case 5:
                MP4TagTrack * trk;
                trk->index = atoi(sbuf.c_str());
                MP4TagsSetTrack(tags, trk);
//                MP4SetMetadataTrack(MP4hFile, atoi(sbuf.c_str()), atoi(sbuf.c_str()));
                break;
            case 6:
                MP4TagsSetGenre(tags, sbuf.c_str());
//                MP4SetMetadataGenre(MP4hFile, sbuf.c_str());
                break;
            }
            tagid++;
        }
        MP4TagsStore(tags, MP4hFile);
        MP4TagsFree(tags);

    }
    tagfile.close();
    delete [] fnbuf;

(..)

    MP4Close(MP4hFile);

    MP4Optimize(destname, NULL, 0);

}


This code yields no result, as the MP4Metadata*** functions are commented out.

Have I missed something important?
unclenorton
It is rather odd nobody has any idea of what this could be, despite the thread being viewed almost 400 times. Anyway, I have found a solution here. To cut it short, the new convenience framework didn't create metadata atoms if there were none already. Installing a trunk revision 355 of mp4v2 resolved the problem.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.