1

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.

Tommy Muir
  • 61
  • 8
  • 1
    Does the destination file already exist? Try removing it or choosing a new name. AVFoundation notoriously does not like overwriting existing files. – Rhythmic Fistman Oct 30 '18 at 22:10

1 Answers1

0

In the end I found a way to set the metadata of the video after the video was saved to the photos library rather then before. Once I saved it to the photos library, I got the PHAsset of the video and stored it in PHAsset* vid then used the code:

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    PHAssetChangeRequest* request = [PHAssetChangeRequest changeRequestForAsset:vid];
    request.creationDate = [NSDate date];
} completionHandler:^(BOOL success, NSError *error) {}];

to change the creationDate metadata of the video.

Tommy Muir
  • 61
  • 8