Focal Lengths

One of the things that I’ve wished for in Lightroom is a focal-length histogram. I’d love to be able to select a bunch of pictures and ask “which focal lengths did I use most often?” I mean, I know which lenses I use most often, but which focal lengths do I actually use?

Fortunately, it’s not too hard to do this outside of Lightroom. Just turn on XMP auto-exporting and then use the usual set of Unix tools to summarize a few thousand XML files. I used something like this:

  $ find . -name '*.xmp' | xargs grep -h 'exif:FocalLength' | 
      cut -d '>' -f2 | cut -d '/' -f1 | sort -n | uniq -c

That finds all of the .xmp files in the current directory (and subdirectories), extracts their exif:FocalLength lines, then extracts the actual focal length number, sorts them numerically, and then counts how many occurrences of each focal length it sees.

I ran this over all of the pictures that I took while on vacation, and found a couple interesting patterns. First, I usually shoot with lenses at either their short or long end; the middle of the range gets a lot less use. My most common focal lengths were

Focal Length (lens)Number of shots
70mm (24-70 or 70-200)846
400mm (100-400)409
100mm (100-400)312
200mm (70-200)304
24mm (24-70)291
85mm (85/1.8)284

A graph is (as usual) a bit more informative:

I shoot a lot of pictures in the 24-100mm range. 70mm is the most common, but the 35, 45, 55, and 65mm lines are all pretty big. It looks like I use my 24-70mm lens in the middle of its range quite a bit, while my longer lenses mostly get used at their extremes.

Posted by Scott Laird Tue, 17 Apr 2007 15:11:30 GMT


  1. Daveed V. 29 days later:

    Interestingly I used the exact same sequence for the end of the command pipe (I assume there is a better way than all that grepping/cutting/etc. though?).

    However, instead of exporting lots of XMP files, I did the following (copy-pasted from my notes):

    (1) Download the SQLite browser from .

    (2) Run it and open your lrdb file with it.

    (3) Select the “Browse Data” tab, and in that tab ensure that the selected table is “Adobe_AdditionalMetadata” (apparently the default).

    (4) In the File menu, choose “Export -> Table as CSV file” and complete the export file selection. I used “~/md.txt”.

    (5) In a terminal window:

    grep ‘exif:FocalLength’ ~/md.txt | cut -d’>’ -f2 | cut -d ‘<’ -f1

    will list all focal lengths as a ratio. If the second part of that ratio is always “1” (which seems to be the case for my DSLR images, but not pictures from a ultracompact I have), then an quick statistic can be gotten with:

    grep ‘exif:FocalLength’ ~/md.txt | cut -d’>’ -f2 | cut -d ‘/’ -f1 | sort -n | uniq -c

    (6) Delete the CSV file (e.g., “rm ~/md.txt” in the terminal).

  2. alan about 1 month later:

    Daveed, your sql browser trick to avoid making XMP files worked great for me. The results of your second grep caused me a bit of confusion, however, because it finds and counts both FocalLength and FocalLengthin35mmFilm, leading to lots of results like:

    21 1320
    28 1320
    . . .
    50 855
    75 855

    Changing grep 'exif:FocalLength' to grep 'exif:FocalLength>' does the trick.

  3. 婚宴攝影 5 months later:

    Daveed, your sql browser trick to avoid making XMP files worked great for me.