Reading & Writing cover data (MP4)

Yannis Calotychos ycalot at gmail.com
Fri Apr 29 21:37:30 BST 2022


I have managed to fix this
updated write code in obj-c below (just in case anyone is interested)

apologies for the noise
yannis


+ (BOOL)writeFile:(NSURL *)url coverData:(NSData *)coverData
{
	BOOL done = NO;
	MP4::File f(url.path.UTF8String);
	if( f.isValid() )
	{
		MP4::Tag *tag = f.tag();
		if( tag != nil )
		{
			if( tag->contains("covr") )
				tag->removeItem("covr");
				
			if( coverData )
			{
				ByteVector v((const char *) coverData.bytes, (unsigned int) coverData.length);
				MP4::CoverArt coverArt(MP4::CoverArt::JPEG, v);
				MP4::CoverArtList l;
				l.append(coverArt);
				
				f.tag()->setItem("covr", l);
			}
			
			bool b = f.save();
			done = b ? YES:NO;
		}
	}
	return done;
}




> On 29 Apr 2022, at 8:57 PM, Yannis Calotychos <ycalot at icloud.com> wrote:
> 
> 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/05c369a1/attachment-0001.htm>


More information about the taglib-devel mailing list