AVAssetExportSession not exporting metadata

954 views Asked by At

I'm trying to use AVAssetExportSession to change the metadata of the file but any metadata I try to use doesn't seem to work. When I pass an empty array to [AVAssetExportSession setMetadata:Array]; the file gets written with its unedited metadata like it's supposed to but as soon as I put an AVMetadataItem in the array no metadata is written to the new file. Here is the code that I used:

//NSMutableArray *newArray = [NSMutableArray arrayWithArray:[exportSession metadata]];

AVMutableMetadataItem *addingNew = [[AVMutableMetadataItem alloc] init];
[addingNew setKeySpace:AVMetadataKeySpaceiTunes];
[addingNew setKey:AVMetadataiTunesMetadataKeyUserComment];
[addingNew setValue:[NSString stringWithFormat:@"This is my comment"]];

NSArray *newArray = [NSArray arrayWithObject:addingNew];

NSURL *fileURL = [NSURL fileURLWithPath: outputFile];

[exportSession setMetadata:metaMuteArray];
[exportSession setOutputURL:fileURL];
[exportSession setOutputFileType:AVFileTypeMPEG4];
[exportSession shouldOptimizeForNetworkUse:YES]; //false doesn't work either

[exportSession exportAsynchronouslyWithCompletionHandler:^{
    switch ([exportSession status])
    {
        case AVAssetExportSessionStatusCompleted:
            NSLog(@"Export sucess");
        case AVAssetExportSessionStatusFailed:
            NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
        case AVAssetExportSessionStatusCancelled:
            NSLog(@"Export canceled");
        default:
            break;
    }
}];
1

There are 1 answers

0
Tom O'Reilly On BEST ANSWER

I have answered my own question. The file of which I am changing the file information is in the MP4 format so I set the filetype output to MP4 as well. This wouldn't export the metadata, changing the setOutputFileType to AVFileTypeAppleM4V did the job just fine, interestingly the output file is still and MP4, not an M4V.