Issue with setting and retrieving the value of AVMetadataCommonKeyCreator
Asked Answered
L

2

9

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?

Larianna answered 25/4, 2011 at 10:46 Comment(2)
I'm still having the same issue on iOS7 for what matter, AVMetadataCommonKeyCreator won't be saved. Time to report it to Apple I guess.Meghannmegiddo
Cannot get any kind of metadata to save to any file format with AVAssetWriter in iOS 8.1. @Meghannmegiddo did anything come from your report?Tardif
S
2

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.

I solve this problem by using C library taglib http://taglib.github.com it's really easy to build this library for iOS. I think you can delete some files if you can't compile it.

Swindell answered 27/10, 2012 at 20:3 Comment(0)
R
1

I would also like to confirm that AVMetadataCommonKeyCreator will not be saved to the metadata of a video's asset. The other ones I have tried (AVMetadataCommonKeyTitle, AVMetadataCommonKeyDescription, etc) do work. My base SDK is iOS 8.2.

Is there something special about the creator key? Is Apple reserving it for some other use? Are there other keys that are restricted to us (or just don't work)?

( I have not had the luxury of time to test every one of the 23 AVMetadataCommonKeys.. )

Robinet answered 24/3, 2015 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.