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