Tiger: Spotlight and EXIF

Posted by Scott Laird Sat, 30 Apr 2005 08:49:53 GMT

According to Apple, Spotlight is supposed to be able to index EXIF data. Unfortunately, none of my JPEGs’ EXIF data has been indexed. Even worse, some of the Spotlight metadata fields are obviously bogus, showing obvious bugs in Spotlight’s implementation.

To test Spotlight’s EXIF abilities, I used a JPEG from my D60 that I had annotated with EXIF and IPTC data using iView Media Pro. Using the mdls command-line tool, I asked for details on one of my images, and saw something like this:

halloween-2004-173.JPG -------------
kMDItemAttributeChangeDate = 1970-01-02 17:40:06 -0800
kMDItemFSContentChangeDate = 2004-10-30 22:43:23 -0700
kMDItemFSCreationDate  = 2004-10-30 22:43:23 -0700
kMDItemFSCreatorCode   = 0
kMDItemFSFinderFlags   = 0
kMDItemFSInvisible     = 0
kMDItemFSLabel         = 0
kMDItemFSName          = "halloween-2004-173.JPG"
kMDItemFSNodeCount     = 0
kMDItemFSOwnerGroupID  = 20
kMDItemFSOwnerUserID   = 501
kMDItemFSSize          = 1712816
kMDItemFSTypeCode      = 0
kMDItemID              = 3341125
kMDItemLastUsedDate    = 2004-10-30 21:43:23 -0700
kMDItemUsedDates       = (2004-10-30 21:43:23 -0700)

Notice that all of the metadata provided is simply generic file data–none of this is image-specific. There is no EXIF data, and no indication that Spotlight knows that this is an image. Also, the kMDItemAttributeChangeDate is weird–it’s not impossible that I’d lost my clock and not noticed for two days, but it’s unlikely.

Worse, after making a minor change to the JPEG and then waiting for the re-indexer to run, the Attribute Change Date became completely bogus, changing nearly every time I ran mdls. Here are a few sample values:

kMDItemAttributeChangeDate = 1969-12-31 16:00:06 -0800
kMDItemAttributeChangeDate = 125748-10-16 05:23:09 -0800
kMDItemAttributeChangeDate = 1976-10-14 07:29:24 -0700

I particularly like the way that it jumps from 6 seconds after the Unix epoch to 123000 years into the future and then back into the 70’s again.

Even after telling iView Media Pro to re-write all of the EXIF and IPTC data in the file, mdls still doesn’t show any EXIF details. This is disappointing–I’d hoped to be able use Spotlight to locate images in my photo collection, possibly searching by date, time, focal length, lens, location, subject, and so on.

As I see it, one of two things can be happening here. Either this is a bug in 10.4.0 or Spotlight’s indexing system works in two passes–first indexing files’ existence, and then looping back around to index the data inside the file. It looks like mdimport is still running on something on my box, even though the Spotlight dropdown claims to be finished.

Update: I think it’s running in two passes. If I manually run mdimport on my JPEG, then a bunch of EXIF data shows up in mdls:

halloween-2004-173.JPG -------------
kMDItemAcquisitionMake     = "Canon"
kMDItemAcquisitionModel    = "Canon EOS D60"
kMDItemAperture            = 6
kMDItemAttributeChangeDate = 2005-04-29 18:49:35 -0700
kMDItemBitsPerSample       = 32
kMDItemCity                = "Woodinville"
kMDItemColorSpace          = "RGB"
kMDItemContentCreationDate = 1903-12-31 16:00:00 -0800
kMDItemContentModificationDate = 2004-10-30 22:43:23 -0700
kMDItemContentType         = "public.jpeg"
kMDItemContentTypeTree     = ("public.jpeg", "public.image", "public.data", "public.item", "public.content")
kMDItemCopyright           = "2004 Scott Laird"
kMDItemCountry             = "USA"
kMDItemDisplayName         = "halloween-2004-173.JPG"
kMDItemEXIFVersion         = "2.2"
kMDItemExposureMode        = 1
kMDItemExposureTimeSeconds = 0.005
kMDItemFlashOnOff          = 1
kMDItemFocalLength         = 23
kMDItemFSContentChangeDate = 2004-10-30 22:43:23 -0700
kMDItemFSCreationDate      = 2004-10-30 22:43:23 -0700
kMDItemFSCreatorCode       = 0
kMDItemFSFinderFlags       = 0
kMDItemFSInvisible         = 0
kMDItemFSLabel             = 0
kMDItemFSName              = "halloween-2004-173.JPG"
kMDItemFSNodeCount         = 0
kMDItemFSOwnerGroupID      = 20
kMDItemFSOwnerUserID       = 501
kMDItemFSSize              = 1712816
kMDItemFSTypeCode          = 0
kMDItemHasAlphaChannel     = 0
kMDItemID                  = 3341125
kMDItemISOSpeed            = 7.64386
kMDItemKind                = "JPEG Image"
kMDItemLastUsedDate        = 2004-10-30 22:43:23 -0700
kMDItemPixelHeight         = 3072
kMDItemPixelWidth          = 2048
kMDItemRedEyeOnOff         = 0
kMDItemResolutionHeightDPI = 180
kMDItemResolutionWidthDPI  = 180
kMDItemStateOrProvince     = "WA"
kMDItemUsedDates           = (2004-10-30 22:43:23 -0700)
kMDItemWhiteBalance        = 1

This still isn’t perfect, though–I’m not quite sure where kMDItemISOSpeed = 7.64386 came from–it’s really ISO 100. Similarly, mdls reports the Aperture as 6 when it should be f/8. On the other hand, the focal length and shutter speed are correct, although it’s sort of weird to see shutter speed expressed as decimal seconds.

Update 2: It’s definitely a two-pass thing. After leaving my laptop running overnight, all of my JPEGs now have a full set of metadata associated with them. The ISO numbers and apertures are still wrong, but the rest of the data’s all there. So, it looks like Spotlight tries really hard to get basic data into the DB, and then makes a second pass filling in more details as time permits. Good to know–I haven’t seen this documented anywhere.

Posted in  | Tags , , ,  | 7 comments

Comments

  1. Nevin said 2 days later:

    What a shame about the bogus aperture and ISO values: I was really excited about this for a few minutes till I chanced upon this oddity.

    At least I can still run queries like “all images taken with my 20D this year at focal lengths greater than 50mm.”

  2. Scott Laird said 2 days later:

    It’s obviously just a bug; if they fix the JPEG indexer in 10.4.1, it’s trivial to have it re-index all JPEGs. Just run ‘mdimport -R /System/Library/Spotlight/Image.mdimporter’, and it’ll do the right thing all on its own. I assume that the 10.4.1 upgrade will kick that off without any user intervention.

    Scott

  3. William A. Carrel said 14 days later:

    What would really be impressive is if they bothered to have support for the “MakerNote” fields. At least on Nikon’s digital SLRs it records a variety of information about the lens used and settings that don’t have a generic EXIF equivalent. Hacking up support for it is a little tedius in most tools but possible… http://www.carrel.org/2004/09/05/nikon-makernote-support-for-jhead/

    I imagine some people would see a lot of value in being able to formulate a spotlight query like Lens=300mm AND Date<1/5/05…

  4. mick angel said 24 days later:

    I’ve noticed the incorrect ISO speeds.

    I thought at first it was simply a number translation issue, but I have two images that are ISO 100 and ISO 200 and spotlight gives them both a “kMDItemISOSpeed” of 10.64386.

    The 10.4.1 update didn’t fix this for me, and I have tried re-indexing to no avail.

    Did you ever get to the bottom of this or find a workaround?

    Mick.

  5. Mick Angel said 2 months later:

    As per subject line - ISO values are still wrong in 10.4.2

    Obviously this isn’t high on the list (if it’s on the list at all) at Apple.

  6. online pocker said 7 months later:

    That’s a good one :)
    online pocker

  7. mick angel said 8 months later:

    this was finally fixed in 10.4.4

Comments are disabled