I'm a computer guy. I've been programming since the early 80s, starting with BASIC on a Commodore Pet. I've worked on HPUX, BSD and various other *nix as well as Windows since 3.0. My new work provides Apple laptops, but I've never learned to use a Mac. How hard can it be?

Tuesday, April 1, 2014

Java Refresh and Photography

I admit that this is not particularly Mac related, but I've started playing with Java.  And, no, as a friend of mine asked, nothing to do with either Peet's or Starbucks.  Owing to the jobs I've had the last several years, I hadn't written a line of code in over 7 years, until today.  Maybe that's a slight exaggeration.  I may have done some programming in the first several months of the job I held from 2006-2013, but I don't think so.  If I did, then it has only been over 6 years.

Anyway, I decided today, while waiting for some processes to finish and, literally, having no other "work" to do, that it was time to start programming again.  One of the jobs I am considering taking may have some programming in Java, Javascript, Coffee, Pig, and or Python.  Of those, I've heard of 3 and used 2, one of them (Java) extensively.  I hadn't even heard of Coffee or Pig before.

I am also a photographer.  I call myself semi-pro - I'm fairly good, and I have gotten to the point of having decent equipment, but I don't do a lot with the many many pictures I take, I've almost no skill with in depth photo editing, and I don't shoot RAW.  See?  Semi-pro.

I also like to organize my pictures a certain way.  My friends who know me will not be shocked.  At this point, organizing them the way I want takes a fair amount of work, because I like to put all the pictures from a single month in a single directory, and then rename them all so the name is in the format yyyy-mm-dd-###.(extension).  Of course, it's slightly more complicated than that, because there are times when I don't put pictures from a given month in the same directory... for example, if I have a significant event (or more than one) where I take lots of pictures in a single month, I'll usually create a sub-directory in the month directory for each event.

OR, if the large group of pictures crosses from one month to another, such as when I'm on a trip that starts in May and ends in June (as often happens when I take my daughter to Yosemite), I'll usually put that in a separate directory entirely, that is in the YEAR directory along with the month directories.  Didn't mention the year directories before, did I?

Unfortunately, the renaming requires that I use an old Microsoft photo editing tool that will only do one day at a time - otherwise, the numbers don't restart at 1 each day.  The Microsoft tool isn't that bad.  It will organize all the pictures by date for me, and then I can sort them by time and batch rename them, but I do have to do each date, and if I change my mind about the exact format, I have to start over, which is a pain in the neck.

On top of that, it doesn't seem to take use the time to the millisecond.  This is important if I've taken a bunch of pictures in a short time, as when I do panoramas, rapid-fire action shots, or HDR.  I want the pictures to be named in the right order, but that won't necessarily happen if the exact time isn't used.

I have looked for other tools, and there are some batch renamers out there, but I haven't found one that does quite what I want, either with respect to naming pictures across multiple directories or using a close enough time.

Soooo... I have long wanted to write my own batch renaming program, which I've started on today.  So far, I'm up to remembering how to create a Java file with code, import packages (and set the classpath), compile (also that compilation is necessary), and run.  I learned how to list all the files in a specific directory and how to get certain attributes such as the create time.

As it turns out, at least with the Canon 7D I shoot with today, the creation time doesn't have milliseconds.  Fine.  Time to dig deeper and find out how to read other attributes beyond the standard OS data.  Hey, look!  The Google tells me that there's a package for that, by... Google: the metadata extractor.  It's pretty cool.  It'll handle numerous different kinds of photo files and by a variety of different cameras.

After a bit of digging, I was able to determine that the majority of the tags don't change from photo to photo, particularly if you're taking a slew of them in rapid succession when things like zoom, aperture, ISO, and shutter speed don't tend to change.  Those are, after all, the main things that you change when you take pictures with a single camera, besides the time.

Then I was able to determine that there is a tag in the standard Exif library that is the sub-second time record.  This is actually JUST the milliseconds (or maybe hundredths of seconds, since I've only see two digits so far).  One thing I was stuck on for a while was that the milliseconds, which I'll continue to call them for convenience, would sometimes drop within a single second of creation time even though the original file name didn't change.

So then I used the handy dandy exif library to get the original time from the exif rather than the file system's creation time.  That got me a table like the following:

file 82: IMG_8108.JPG  2014-02-16T20:46:10Z Sun Feb 16 12:46:09 PST 2014 11
file 83: IMG_8109.JPG  2014-02-16T20:46:10Z Sun Feb 16 12:46:09 PST 2014 24
file 84: IMG_8110.JPG  2014-02-16T20:46:10Z Sun Feb 16 12:46:09 PST 2014 37
file 85: IMG_8111.JPG  2014-02-16T20:46:10Z Sun Feb 16 12:46:09 PST 2014 50
file 86: IMG_8112.JPG  2014-02-16T20:46:10Z Sun Feb 16 12:46:09 PST 2014 62
file 87: IMG_8113.JPG  2014-02-16T20:46:10Z Sun Feb 16 12:46:09 PST 2014 75
file 88: IMG_8114.JPG  2014-02-16T20:46:10Z Sun Feb 16 12:46:09 PST 2014 88
file 89: IMG_8115.JPG  2014-02-16T20:46:10Z Sun Feb 16 12:46:10 PST 2014 1
file 90: IMG_8116.JPG  2014-02-16T20:46:10Z Sun Feb 16 12:46:10 PST 2014 13

I know it's a little hard to read, but if you look closely, you'll see that these are the 82nd through 90th files in the directory I'm testing with (and yes, these are all copied from my master photo directories), they were all taken at 20:46:10 UTC (formerly known as Zulu time, thus the Z), which translates into 12:46:10 PST.  The last 1 or 2 digit number is the aforementioned sub-second time, and you can see that the last 2 are lower than the one before them, which throws the order all out of whack if I use it, because the file names are presently in the right order (I checked the images themselves to be sure, and of course they are).

BUT WAIT!  The first 7 pictures were taken at 12:46:09 PST!  That time, the 2nd one in PST and a longer format, is the actual "original datetime" from inside the file, as written by the camera!  Hallelujah!  Now I know, at least with the Canon 7D, that I can sort these things correctly.

At this point, I think the next task is to change the program so that it can start at the top of (a copy of) my master photo storage and go through all of them, recording the make of camera, file name, original date time, and sub-second time, along with indications where those are not available - I know they're not in some cases, so I'll have to figure out why...

No comments:

Post a Comment