How can I aggregate focal length EXIF data across a large photo library programmatically?
Asked 9/22/2022
2 views
2 answers
0
I want to analyze a large collection of image files to see which focal lengths I use most often, mainly to help with lens buying decisions. Rather than using a GUI cataloging app, I’m looking for a programmatic approach that reads EXIF metadata directly from files in a folder tree and summarizes focal length usage. I’m especially interested in simple command-line starting points for someone with limited Bash or Python experience.
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
3y ago
2 Answers
3
On my collection using Unix shell commands and exiftool:
Sorted by focal length:
find . -name 'IMG_????.JPG' -exec exiftool -FocalLength -p '$FocalLength' {} + | sort -n | uniq -c
Sorted by frequency:
find . -name 'IMG_????.JPG' -exec exiftool -FocalLength -p '$FocalLength' {} + | sort -n | uniq -c | sort -n
In slo-mo:
find . -name 'IMG_????.JPG: all matching files under current directory (you may have to change the pattern for other naming schemes). Using this kind of pattern avoids counting twice (JPG and CR2 for me).-exec exiftool -FocalLength -p '$FocalLength': extract focal length{} +: process as much as possible is oneexiftoolinvocation| sort -n: sort numerically (so '90 mm' is before '100 mm')| uniq -c: replace consecutive equal occurrences by single line with count| sort -n: (optional) sort on count
Output:
271 10.0 mm
9 10.2 mm
5 10.5 mm
3 10.8 mm
65 11.0 mm
10 11.3 mm
7 11.6 mm
3 11.9 mm
34 12.0 mm
9 12.2 mm
7 12.5 mm
3 12.8 mm
33 13.0 mm
[snip]
3 33.0 mm
1 33.3 mm
215 34.0 mm
653 35.0 mm
6 36.0 mm
119 37.0 mm
75 38.0 mm
[snip]
192 58.0 mm
5 60.0 mm
187 63.0 mm
7 65.0 mm
1661 70.0 mm
12 74.0 mm
12 79.0 mm
9 84.0 mm
15 90.0 mm
12 96.0 mm
745 100.0 mm
15 109.0 mm
12 116.0 mm
367 120.0 mm
15 123.0 mm
[snip]
191 251.0 mm
247 273.0 mm
194 297.0 mm
185 323.0 mm
181 352.0 mm
686 400.0 mm
1 417.0 mm
1 454.0 mm
12 495.0 mm
32 560.0 mm
2'30" elapsed on 12000 pictures (Core [email protected], from SSD)
With a strong influence of my two macro prime lenses (35mm and 100mm), my 17-70mm often used as its longest, and my 120-400mm often used at either end, and the occasional 120-400mm on 1.4x extender.
Originally by user75947. Source · Licensed CC BY-SA 4.0
user75947
3y ago
0
Generated from our catalog & community — verify before relying on it.
A practical starting point is exiftool, combined with standard shell tools. It can recursively read EXIF focal length metadata from your files, then you can sort and count the results.
Examples from the community:
find . -name 'IMG_????.JPG' -exec exiftool -FocalLength -p '$FocalLength' {} + | sort -n | uniq -c
That gives counts by focal length. To sort by frequency:
find . -name 'IMG_????.JPG' -exec exiftool -FocalLength -p '$FocalLength' {} + | sort -n | uniq -c | sort -n
Another option is exiftool plus awk, which can output simple CSV-style results:
exiftool -FileName -FocalLength -p '$FileName:$FocalLength' -r . 2>/dev/null | awk -F: '!/xmp/ {gsub(/ mm/,""); a[$2]+=1} END {for (k in a) print k","a[k]}'
Notes:
- Adjust the filename pattern to match your library.
- Be careful not to double-count RAW+JPEG sidecars or XMP files.
- Once you have counts, you can graph them in a spreadsheet or plotting tool.
If you prefer a GUI-based method, digiKam can also filter images by focal-length ranges and ratings.
Recommended products
UniqueBot
AI3y ago
Your Answer
Related Questions
How can I search a large image collection for EXIF/IPTC/XMP tags without Lightroom?
Software to analyze my photos and show which focal lengths I use most
How can I label and catalog original artwork safely for archival storage?
ExifTool on Windows: move images whose file modified date is later than DateTimeOriginal
How can I organize and find a large photo library using filenames, tags, and free/open-source tools?