问题描述
我有一个iPhone视频录制应用程序。我使用 AVAssetWriter
将录制的视频数据写入文件。我也有兴趣将自定义元数据嵌入到文件中。例如:我想将我的应用程序识别为视频的创建者。
I have a video recording app for the iPhone. I am using AVAssetWriter
for writing the recorded video data to a file. I am also interested in embedding custom metadata to the file. For eg: I want to identify my application as the creator of the video.
因此在创建资产编写者之后,我使用键<$ c添加创建者值$ c> AVMetadataCommonKeyCreator 到资产作者的元数据。
Hence after creating the asset writer, I am adding the creator value using the key AVMetadataCommonKeyCreator
to the metadata of the asset writer.
代码片段如下:
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读取文件内容。
Once the recording is done, I am trying to read the contents of the file using 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
。它返回一个空数组。
我能够设置其他元数据对象的值,如 AVMetadataCommonKeyTitle
, AVMetadataCommonKeyModel
, AVMetadataCommonKeySource
。正确检索这些值。问题仅出在 AVMetadataCommonKeyCreator
。请让我知道这种行为的原因。是否无法为 AVMetadataCommonKeyCreator
设置应用特定值?这个键实际上代表了什么?
However [asset commonMetadata]
does not return any AVMetadataItems
. It returns an empty array.I am able to set the values of other meta data objects like AVMetadataCommonKeyTitle
, AVMetadataCommonKeyModel
, AVMetadataCommonKeySource
. These values are retrieved properly. The problem is only with AVMetadataCommonKeyCreator
. Please let me know the reason for this behavior. Is it not possible to set app specific value for AVMetadataCommonKeyCreator
? What does this key actually represent?
推荐答案
一年前我遇到了同样的问题。当我使用AVFoundation编写音频文件时,我没有看到任何元数据。我认为AVMetadataCommonKeyCreator不起作用。我现在不能说,但事实并非如此。
I've same problems about one year ago. I didn't see any metadata when I've wrote audio file using AVFoundation. I think that AVMetadataCommonKeyCreator doesn't work. I can't say about now but it was so.
我通过使用C库taglib来解决这个问题
为iOS构建这个库真的很容易。如果你不能编译它,我想你可以删除一些文件。
I solve this problem by using C library taglib http://taglib.github.comit's really easy to build this library for iOS. I think you can delete some files if you can't compile it.
这篇关于设置和检索AVMetadataCommonKeyCreator的值时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!