问题与设置和检索AVMetadataCommonKeyCreator的价值

我有一个iPhone的video录制应用程序。 我正在使用AVAssetWriter将录制的video数据写入文件。 我也有兴趣将自定义元数据embedded到文件中。 例如:我想确定我的应用程序是video的创build者。

因此,在创build资产AVMetadataCommonKeyCreator之后,我使用密钥AVMetadataCommonKeyCreator将创build器值添加到资产AVMetadataCommonKeyCreator器的元数据中。

代码片段如下:

 AVAssetWriter *assetWrtr = [[AVAssetWriter alloc] initWithURL:inURL fileType:AVFileTypeQuickTimeMovie error:&error]; self.assetWriter = assetWrtr; [assetWrtr release]; NSArray *existingMetadataArray = self.assetWriter.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 = AVMetadataCommonKeyCreator; item.value = @"My App"; [newMetadataArray addObject:item]; self.assetWriter.metadata = newMetadataArray; [newMetadataArray release]; [item release]; 

一旦录制完成,我正在尝试使用AVURLAsset读取文件的内容。

 NSURL *outputFileURL = [self.assetWriter outputURL]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:outputFileURL options:nil]; NSArray *keys = [NSArray arrayWithObject:@"commonMetadata"]; [asset loadValuesAsynchronouslyForKeys:keys completionHandler:^(void) { NSError *error = nil; AVKeyValueStatus durationStatus = [asset statusOfValueForKey:@"commonMetadata" error:&error]; switch (durationStatus) { case AVKeyValueStatusLoaded: NSLog(@"AVKeyValueStatusLoaded"); NSLog(@"commonMetadata:%@", [asset commonMetadata]); break; case AVKeyValueStatusFailed: NSLog(@"AVKeyValueStatusFailed"); break; case AVKeyValueStatusCancelled: NSLog(@"AVKeyValueStatusCancelled"); break; } }]; 

[asset commonMetadata]不返回任何AVMetadataItems 。 它返回一个空数组。 我能够设置其他元数据对象的值,如AVMetadataCommonKeyTitleAVMetadataCommonKeyModelAVMetadataCommonKeySource 。 这些值正确检索。 问题只AVMetadataCommonKeyCreator 。 请让我知道这种行为的原因。 是不是可以为AVMetadataCommonKeyCreator设置应用程序特定的值? 这个键究竟代表什么?

一年前我也有同样的问题。 当我使用AVFoundation编写audio文件时,我没有看到任何元数据。 我认为AVMetadataCommonKeyCreator不起作用。 我现在不能说,但事实如此。

我通过使用C库taglib http://taglib.github.com来解决这个问题,为iOS构build这个库真的很容易。 我想你可以删除一些文件,如果你不能编译它。

我还想确认AVMetadataCommonKeyCreator不会被保存到video资源的元数据中。 我试过的其他的( AVMetadataCommonKeyTitleAVMetadataCommonKeyDescription等)都可以工作。 我的基础SDK是iOS 8.2。

关于创build者密钥有什么特别之处吗? 苹果是否保留它用于其他用途? 是否还有其他的钥匙只限于我们(或者只是不工作)?

(我没有足够的时间来testing每一个AVMetadataCommonKeys ..)