Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change AVMetadataItem

I have some files, -m4a -mp4 -mp3 etc. I want to change these details

  • AVMetadataItem
  • AVMetadataCommonKeyArtwork
  • AVMetadataCommonKeyArtist

I can do with AVAssetExportSession, But I need to change the directory. Is there a way I can write directly on the file please?

I found this program, but does not work :(

NSError *error;
AVAssetWriter *assetWrtr = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:self.path] fileType:AVFileTypeAppleM4A error:&error];
NSLog(@"%@",error);

NSArray *existingMetadataArray = assetWrtr.metadata;
NSMutableArray *newMetadataArray = nil;
if (existingMetadataArray)
{
    newMetadataArray = [existingMetadataArray mutableCopy]; // To prevent overriding of existing metadata
}
else
{
    newMetadataArray = [[NSMutableArray alloc] init];
}


 AVMutableMetadataItem *item = [[AVMutableMetadataItem alloc] init];
item.keySpace = AVMetadataKeySpaceCommon;
item.key = AVMetadataCommonKeyArtwork;
item.value = UIImagePNGRepresentation([[UIImage alloc] initWithContentsOfFile:[[NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@".image"]]);

[newMetadataArray addObject:item];
assetWrtr.metadata = newMetadataArray;



[assetWrtr startWriting];
[assetWrtr startSessionAtSourceTime:kCMTimeZero];
like image 531
user1669335 Avatar asked Jan 18 '13 04:01

user1669335


1 Answers

change UIImagePNGRepresentation to UIImageJPEGRepresentation you need jpeg data not png.

like image 182
Cece Ron Avatar answered Oct 22 '22 14:10

Cece Ron