Removing geotagged info from a video

When I post pictures to eBay or somewhere else that I’ve taken at my house, I strip the geotagged information in it as I’m a bit paranoid. I wrote a small app which basically does this for JPG images. The core of the app is below.

However, how do you do this with videos as the iPhone geotags video? At first I tried emailing the video and then exporting it via QuickTime Player to 480p format. That didn’t seem to work as I think it was already 480p and therefore didn’t convert. Next, I imported the video into iPhoto, dragged it out to the desktop, opened it up in QuickTime Player and then exported to 480p. Since the initial video was 1080p, QuickTime Player actually had to do a conversion and the process stripped the geotagging info.

I’m sure I could have written an app to do this, but I haven’t played around enough lately with the QuickTime APIs to know how to do this.

The source code below is © 2011 Scott Gruby. Redistribution in source or object form is permitted granted that attribution is given to me.

- (void) processFile:(NSString *) inPath
{
    NSString *extension = [inPath pathExtension];
    if ([extension caseInsensitiveCompare:@"jpg"] == NSOrderedSame || [extension caseInsensitiveCompare:@"jpeg"] == NSOrderedSame)
    {
        NSURL *pictURL = [NSURL fileURLWithPath:inPath];
        CGImageSourceRef sourceRef = CGImageSourceCreateWithURL((CFURLRef) pictURL, NULL);
        if (sourceRef)
        {
            NSDictionary* metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(sourceRef,0,NULL);
            NSMutableDictionary *metadataAsMutable = [[metadata mutableCopy] autorelease];
            
            
            [metadataAsMutable setObject:(id)kCFNull forKey:(NSString *)kCGImagePropertyGPSDictionary];
            [metadataAsMutable setObject:(id)kCFNull forKey:(NSString *)kCGImagePropertyIPTCDictionary];

            CFStringRef UTI = CGImageSourceGetType(sourceRef); //this is the type of image (e.g., public.jpeg)
            
            //this will be the data CGImageDestinationRef will write into
            NSMutableData *data = [NSMutableData data];
            
            CGImageDestinationRef destination = CGImageDestinationCreateWithData((CFMutableDataRef)data,UTI,1,NULL);
            
            if(destination)
            {
                //add the image contained in the image source to the destination, overiding the old metadata with our modified metadata
                CGImageDestinationAddImageFromSource(destination,sourceRef,0, (CFDictionaryRef) metadataAsMutable);
                
                //tell the destination to write the image data and metadata into our data object.
                //It will return false if something goes wrong
                BOOL success = NO;
                success = CGImageDestinationFinalize(destination);
                
                if (success)
                {
                    //now we have the data ready to go, so do whatever you want with it
                    //here we just write it to disk at the same path we were passed
                    success = [data writeToURL:pictURL atomically:YES];
                }
                CFRelease(destination);
            }


            [metadata release];
            CFRelease(sourceRef);
        }
    }
}

2 Replies to “Removing geotagged info from a video”

    1. Thanks, Frank! Your app is an excellent start. I’d like to see ability to enter an address instead of using a map and I’d like to see it use the same filename when writing out the photo. There are some minor UI changes I’d like to see, but this looks like a decent tool for working with photos!

Leave a Reply to Frank Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.