I'm trying to clear all exif and GPS data from a video file in iOS, there was an answer for image, but I can't really find any for a video file. Using the suggested answer for removing those information will render the video data as invalid.
NSData *data = [[NSFileManager defaultManager] contentsAtPath:@"/path/to/video.MOV"];
data = [self dataByRemovingExif:data];
NSString *uuid = [[NSUUID UUID] UUIDString];
NSString *tempVidPath = [NSString stringWithFormat:@"/private/var/mobile/Media/DCIM/%@.MOV", uuid];
[data writeToFile:tempVidPath atomically:YES];
UISaveVideoAtPathToSavedPhotosAlbum(tempVidPath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
//The methods
- (NSData *)dataByRemovingExif:(NSData *)data{
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)data, NULL);
NSMutableData *mutableData = nil;
if (source) {
CFStringRef type = CGImageSourceGetType(source);
size_t count = CGImageSourceGetCount(source);
mutableData = [NSMutableData data];
CGImageDestinationRef destination = CGImageDestinationCreateWithData((CFMutableDataRef)mutableData, type, count, NULL);
NSDictionary *removeExifProperties = @{(id)kCGImagePropertyExifDictionary: (id)kCFNull,
(id)kCGImagePropertyGPSDictionary : (id)kCFNull};
if (destination) {
for (size_t index = 0; index < count; index++) {
CGImageDestinationAddImageFromSource(destination, source, index, (__bridge CFDictionaryRef)removeExifProperties);
}
if (!CGImageDestinationFinalize(destination)) {
NSLog(@"CGImageDestinationFinalize failed");
}
CFRelease(destination);
}
CFRelease(source);
}
return mutableData;
}
- (void)video:(NSString*)videoPath didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo{
if (error)... //show alert
}
Is there any workaround for a video file? I wanted to remove especially the GPS information, private API solution is acceptable.