简体   繁体   中英

How do I set .mp4 image

I'm trying to set the background image of an mp4, but there doesn't seem to be any solutions that work. How do I set the image of it from the NSData I have?

Data is setup like this:

// Basically the JSON data gives a url to a .mp4
NSArray *preview = [JSON valueForKeyPath:@"results.previewUrl"];
_previewData = [NSMutableData dataWithContentsOfURL:[NSURL URLWithString:[preview objectAtIndex:0]]];

To be clear, you're not setting "the background image" of an audio file. You're editing the metadata of it (thanks for clarifying in the comments).

You can use a library such as MP4Audio to do this without having to write the logic yourself:

To set the metadata for an audio file:

ANMovie* file = [[ANMovie alloc] initWithFile:@"test.m4a"]; // or .mp4
NSData* jpegCover = UIImageJPEGRepresentation(image);
ANMetadata* metadata = [[ANMetadata alloc] init];
metadata.albumCover = [[ANMetadataImage alloc] initWithImageData:jpegCover type:ANMetadataImageTypeJPG];
[file setMovieMetadata:metadata];
[file close];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM