简体   繁体   English

如何设置.mp4图像

[英]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. 我正在尝试设置mp4的背景图像,但似乎没有任何有效的解决方案。 How do I set the image of it from the NSData I have? 如何从我拥有的NSData设置图像?

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: 您可以使用MP4Audio之类的库来执行此操作,而无需自己编写逻辑:

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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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