Renaming image files based on exif data

I purchased a fully manual Samyang 12 mm f/2.0 NCS CS (review, review) lens for my Sony Alpha 5000. This lens has no electronic interface and so camera doesn’t know what was the aperutre nor focal length. It simply puts 0 for them. (There is an in-camera app for that, but you’ll need to adjust aperture value every time you change it)

I wanted to create two separate albums, one per lens. Select best pics, edit those and then compare the results. Atm I would need to iterate over 200 photos manually and look for F0 aperture.

How do your automate this? Bash (and google) to the rescue!

There is a tool called exiv2. It can show the exif of your file. Eg

exiv2 20161002-150633.jpg
Error: Offset of directory Sony1, entry 0x2001 is out of bounds: Offset = 0x004f4076; truncating the entry
File name       : 20161002-150633.jpg
File size       : 6193152 Bytes
MIME type       : image/jpeg
Image size      : 5456 x 3632
Camera make     : SONY
Camera model    : ILCE-5000
Image timestamp : 2016:10:02 15:06:33
Image number    : 
Exposure time   : 1/200 s
Aperture        : F0
Exposure bias   : 0 EV
Flash           : No, compulsory
Flash bias      : 0 EV
Focal length    : 0.0 mm (35 mm equivalent: Unknown)
Subject distance: 
ISO speed       : 125
Exposure mode   : Manual
Metering mode   : Multi-segment
Macro mode      : 
Image quality   : n/a
Exif Resolution : 5456 x 3632
White balance   : Auto
Thumbnail       : image/jpeg, 10354 Bytes
Copyright       : 
Exif comment    :

Aperture : F0 is what I’ll be looking for. Now it’s only a bit of file iterating, piping and awk. Running following bash script in directory of photos fill copy files from Samyang lens with _f0 added to the name.

#!/bin/bash

for file in *.jpg
do
  result=$(exiv2 $file | awk '/Aperture/ {print $3}')
  if [ $result == 'F0' ]
    then
      cp "$file" "${file/.jpg/_f0.jpg}"
  fi
done

Now I have something like

 20161002-151850a_f0.jpg
 20161002-151850a.jpg

and I can create two albums, each per lens and compare. Of course you can alter the script to rename (create backup of photos first) to avoid duplication.

If you wonder how I got such time-date file names, read here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s