Skip to content

manipulating EXIF headers on the command line

This afternoon, I undertook some fall cleanup of my computer's hard drive, a task but became urgent as I start running out of space. Last night, I ran WinDirStat – Windows Directory Statistics to figure out what was hogging up the disk space. I was not surprised to learn my photos, videos, and podcasts ( which I was downloading from iTunes, sometimes indiscriminately) were taking up gigabytes. Every time I buy a new digital camera, I end up taking high-resolution photos, which just exacerbates the problem.

As I was cleaning up my hard drive and backing up photos to an external drive, I found a lot of old photos that I had yet to upload to Flickr. I work hard to properly timestamp my photos so that I can make use of Flickr's ability to let me browse my photos by not only when I upload them but also when I took them. The key is to have the right timestamps in the EXIF headers of my photos. Flickr would then read and use those headers to figure out when the pictures were taken.

The problem is that some of my photos, specifically the ones that came from an old webcam, did not have a timestamp in the EXIF headers. In that case, I could still upload the photos into Flickr and then manually adjust each of the photo's timestamps using Flickr. To avoid using such a tedious and error-prone process, I had written a script in Python that would write the EXIF timestamp from each photo, using the modification date of the photo as an approximation for when the photo was taken.

The last time I looked, I could not find a Python library for doing extensive EXIF manipulation. I ended up trying to different commandline utilities: jhead and exiv2. Today, I modified my script to use exiv2. Let me record a few one-liners that I found useful for the task:

exiv2 filename

reads off the EXIF headers for the file

exiv2 -pt filename

writes out in fuller detail the EXIV headers

exiv2 -da filename

deletes the EXIF headers

exiv2 -k -M"set Exif.Image.DateTime Ascii 2002:01:02 22:15:26" Pict0001.JPG

sets the timestamp for Pict0001.jpg while preserving the file timestamp.

What I'd like to find out now is how to write a timestamp into a video file? My understanding is that EXIF doesn't apply to video files — so what is EXIF for video?

Post a Comment

You must be logged in to post a comment.