Reading & Writing cover data (MP4)

Yannis Calotychos ycalot at gmail.com
Fri Apr 29 18:57:37 BST 2022


Hello,

I am having strange issue reading / writing cover data in MP4 (AAC or ALAC).
I am using code adapted from test_mp4.cpp (see below).

1. taglib can read cover data saved by other apps. (e.g. iTunes)
2. taglib can’t read cover data written with taglib
3. Other apps (i.e.iTunes, MusicBrainz Picard) can read cover data written with taglib.

with latest release. (i am pretty sure this used to work in previous releases)
thank you for any help
yannis

_________________________________________________________________________


//// READ
NSData *readCoverForFile(MP4::File &f, int index)
{
	MP4::Tag *tag = f.tag();
		
	if( tag->contains("covr") )
	{
		MP4::Item item = tag->item("covr");
		MP4::CoverArtList coverArtList = item.toCoverArtList();
		if( index < coverArtList.size() )
		{
			MP4::CoverArt coverArt = coverArtList[index];
			return [NSData dataWithBytes:coverArt.data().data() length:coverArt.data().size()];
		}
	}

	return nil;
}

	
//// WRITE
static void setCoverForFile(MP4::File &f, NSData *coverData, const char *mime)
{
	MP4::Tag *tag = f.tag();
	
	if( tag->contains("covr") )
		tag->removeItem("covr");

	if( coverData )
	{
		// Create cover art
		ByteVector v((const char *) coverData.bytes, (unsigned int) coverData.length);
		MP4::CoverArt coverArt( (MP4::CoverArt::Format)typeJPEG, v);
		
		// Create cover art item (a CoverArtList instance)
		MP4::CoverArtList coverArtList;
		coverArtList.append(coverArt);
		MP4::Item coverItem(coverArtList);

		// Insert to tag map
		tag->setItem("covr", coverItem);
	}

	f.save()
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/taglib-devel/attachments/20220429/0b6018f2/attachment.htm>


More information about the taglib-devel mailing list