Adjusting Timestamps from a GoPro

Underwater with a GoPro A friend lent me his GoPro HERO4 Silver Edition [GoPro Website][Wikipedia] last month for our trip to Ishigaki, and it was awesome! Snorkeling in the clear blue waters off Iriomote never looked better than at 1080P/60FPS with a near-fisheye lens. Love this camera!

However…

While the GoPro can set its time automatically if you use their App or Software, the GoPro I was using had had its time set manually, and the time was a bit off. Specifically, 17 hours and 17 minutes off.

The best way to change the timestamp of a group of photos

…is probably by using whatever tool is built-in to your favorite photo management software. This is often as simple as selecting a photo and choosing “Adjust Date and Time.” But why do things the easy way when we can play around in the terminal?

Before we start

Don’t run these commands on your actual data! Seriously. Make a copy for testing, and make sure you’re satisfied with the results first. You could easily loose your data, or end up with a bunch of files with even less correct timestamps that when you started. Second, EXIF data may or may not include timezone information. So, even after you think you’ve adjusted the dates perfectly, you may find everything getting out of sync when you import your photos into another program. And finally, note that there are cases where EXIFTool isn’t able to modify every timestamp. So, even in the best case you may end up with a mix of dates in your metadata.

A bit more about timezones

As mentioned above, EXIF data may or may not include timezone information. In the absence of a clear guidance, you many find software interpreting EXIF dates as UTC time (and hence automatically adding in the local timezone offset) or as local time. I found that the photo management software I’m using interpreted metadata on my MP4 files from the GoPro as being in UTC time, wheres metadata on JPGs from the same GoPro was interpreted as local time. Your millage may vary.

Adjusting EXIF on JPGs with EXIFTool

This was the easy part: 1. Install: brew install exiftool 2. Offset dates by 17 hours 17 minutes: exiftool -overwrite_original_in_place -preserve -AllDates+='0:0:0 17:17:0' *.JPG Simple, right? And pretty snappy too!

Kind-of adjusting metadata on MP4s

The above command runs without errors on MP4 files from the GoPro. However, a quick examination of the results shows that while (QuickTime tags) “Create Date” and “Modify Date” are adjusted, the MP4 “Track Create Date”, “Track Modify Date”, “Media Create Date”, and “Media Modify Date” tags are left untouched! A quick glance at the Supported File Types table entry for MP4 files takes us to note 4, confirmed by several forum posts:

Note 4

This is certainly less than ideal but, hey, it turned out to be ‘good enough’ for my purposes. Incidentally, I found I also needed to specify a different time offset. Since the photo management software I’m using seems to be interpreting (correctly?) QuickTime metadata on MP4 files as being in UTC time and making a local timezone adjustment on its own, I only needed to add an additional 8 hours 17 minutes:

exiftool -overwrite_original_in_place -preserve -AllDates+='0:0:0 8:17:0' *.MP4

A quick script to adjust file timestamps

The right way to adjust filesystem timestamps is probably to use exiftool. That said, I decided to go with a more general solution using the SetFile utility on built-in to OS X. Enter the world’s simplest bash script:

#!/usr/bin/env bash
FILES=$(ls *.{JPG,MP4})
for filename in $FILES
do
	# Offset is approximately 17 hours 17 minutes
	NEWDATE=$(date -j -v+17H -v +17M -f "%m/%d/%Y %H:%M:%S" "$(GetFileInfo -m $filename)" +"%m/%d/%Y %H:%M:%S")
	echo $filename - $NEWDATE
	# Adjust modification time:
	SetFile -m "$NEWDATE" "$filename"
	# Adjust creation date
	SetFile -d "$NEWDATE" "$filename"
done

While this script script is quite straightforward and achieved the results I was interested in, it isn’t particularly fast—about 12-13 on average on my MacBook. But more on that next time…