I am trying to convert a video PHAsset to NSData for upload, but each attempt to save the data of the asset seems to lose the location metadata. Here is what I have tried:
Get the AVAsset from PHAsset, and use its URL:
The AVAsset itself has metadata in both the retrievedAsset.metadata and retrievedAsset.commonMetadata fields. I can see that GPS coordinates are part of that data.
[[PHImageManager defaultManager] requestAVAssetForVideo:asset
options:options
resultHandler:^(AVAsset *retrievedAsset, AVAudioMix *audioMix, NSDictionary *info) {
}
In the completion block above, retrievedAsset is actually an AVURLAsset, which has a local URL of the media data. That URL has a path extension of .MOV, if I just copy the data at the location to my temp directory for upload, then view the .MOV file inside my apps container, the resulting .MOV file shows no location data.
I have also tried using AVAssetExportSession to try and set the metadata specifically in the export.
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:retrievedAsset presetName:AVAssetExportPresetHighestQuality];
// My output url has a path extension of .MOV, and I set the file type to QuicktimeMove,
// because the original AVURLAsset had a .MOV extension, but I am not sure if that is correct.
// I have also tried making the MP4 with no luck.
exporter.outputURL = url;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
// In here I have tried to use retrievedAsset.metadata, retrievedAsset.commonMetadata
// I have also tried to create a custom AVMetaDataItem with GPS coordinates
[exporter setMetadata:cutomMetaData];
[exporter exportAsynchronouslyWithCompletionHandler:^{
// The data is successfully exported to a .MOV at my specified URL, but always appears to not contain any location metadata.
}];
Is there any way I can get the original PHAsset metadata into the final movie file?