我尝试使用 AVAssetExportSession
设置 AVFileTypeMPEG4
类型文件的元数据,但它
不起作用,如果我将文件类型更改为 AVFileTypeQuickTimeMovie
,它就起作用。但是我需要 mp4 文件,我找不到任何文档说 AVFileTypeMPEG4
文件不能设置元数据,有人设置元成功吗?
这是我使用的代码:
NSMutableArray *metadata = [NSMutableArray array];
AVMutableMetadataItem *metaItem = [AVMutableMetadataItem metadataItem];
metaItem.key = AVMetadataCommonKeySource;
metaItem.keySpace = AVMetadataKeySpaceCommon;
metaItem.value = @"Test metadata";
[metadata addObject:metaItem];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:composition presetName:AVAssetExportPresetMediumQuality];
exportSession.metadata = metadata;
exportSession.audioMix = audioMix;
exportSession.videoComposition = videoComposition;
exportSession.outputFileType = AVFileTypeMPEG4;//AVFileTypeQuickTimeMovie;
NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"testMetadata.mp4"];
exportSession.outputURL = [NSURL fileURLWithPath:outputFilePath];
[exportSession exportAsynchronouslyWithCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
if (exportSession.status == AVAssetExportSessionStatusCompleted) {
//todo
}else{
//todo
}
});
}];
最佳答案
尝试一下
metaItem.key = AVMetadataiTunesMetadataKeyDescription; metaItem.keySpace = AVMetadataKeySpaceiTunes;
尝试了其他键空间,但只有 itunes 对我有用。
关于ios - 如何通过 AVAssetExportSession 设置 AVFileTypeMPEG4 文件的元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26418627/