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.
Hence after creating the asset writer, I am adding the creator value using the key AVMetadataCommonKeyCreator
to the metadata of the asset writer.
Code snippet is as follows:
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];
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;
}
}];
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?
AVAssetWriter
in iOS 8.1. @Meghannmegiddo did anything come from your report? – Tardif