I am trying to modify the metadata of a .mov file. The way I found to do this was to use the AVAssetExportSession. This is the code I am using to try and modify the metadata:
AVURLAsset* a = [AVURLAsset URLAssetWithURL:videoPathURL options:nil];
AVAssetExportSession* exportSession = [[AVAssetExportSession alloc] initWithAsset:a presetName:AVAssetExportPresetHighestQuality];
exportSession.outputURL = videoPathURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
AVURLAsset* a = [AVURLAsset URLAssetWithURL:videoPathURL options:nil];
AVAssetExportSession* exportSession = [[AVAssetExportSession alloc] initWithAsset:a presetName:AVAssetExportPresetHighestQuality];
exportSession.outputURL = videoPathURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
AVMutableMetadataItem* metaItem = [[AVMutableMetadataItem alloc] init];
metaItem.keySpace = AVMetadataKeySpaceCommon;
metaItem.key = AVMetadataCommonKeyCreationDate;
metaItem.value = [NSDate date];
NSArray* metadata = @[ metaItem ];
exportSession.metadata = metadata;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
NSLog(@"error: %@", exportSession.error);
}];
However this always logs: Error Domain=AVFoundationErrorDomain Code=-11823 "Cannot Save" UserInfo={NSLocalizedRecoverySuggestion=Try saving again., NSLocalizedDescription=Cannot Save, NSUnderlyingError=0x1d0845430 {Error Domain=NSOSStatusErrorDomain Code=-12101 "(null)"}}
The file at videoPathURL
is a .mov.
Even when I remove the code:
AVMutableMetadataItem* metaItem = [[AVMutableMetadataItem alloc] init];
metaItem.keySpace = AVMetadataKeySpaceCommon;
metaItem.key = AVMetadataCommonKeyCreationDate;
metaItem.value = [NSDate date];
NSArray* metadata = @[ metaItem ];
exportSession.metadata = metadata;
I get the same log. I don't understand why this is not working.
This code is being run on an iOS 11.3.1 device, not on a simulator.