Modify Filename from Text File

Started by gonzalu, August 18, 2012, 01:08:06 PM

Previous topic - Next topic

gonzalu

Hello all,

First of all thank you to Phil Harvey for the tool; invaluable! Thank you to all of you for your contributions some of which I have put to good use.

I have a problem that I have been solving with the help of ExIFTool for some time now but have run into a snag today. I have a huge Lightroom Database with some 500,000 images cataloged in it. All edit information is contained within the catalog. I have no external sidecar XMP files.

One of the stored file locations had a failed drive and I was able to recover most if not all of the files using image recovery tools. However, the files are named sequentially and since Lightroom indexes via FileName, it can;t easily find or match originals to the catalog :-(

Using Adobe Bridge, I am able to parse files based on original date and put them into the right folders for Lightroom. Then, using ExIFTool and the commandline given to me by Horshack on "dpReview" forums, I am able to extract the original FILE NUMBER from the NEF file(s) and rename the file accordingly.

Slightly modifying the commandline, I am able to differentiate between camera models to pre-pend the camera model to the number as I originally do in-camera and have it match to what Adobe LR4.1 wants. For example:

D3G_2354.nef == Nikon D3 file
D80_5423.nef == Nikon D800 file

The problem I have just run into is that Nikon D2Xs files do NOT have a file number :-( This is now a problem as i have no way to rename the files back to their original name.

I thought of an alternative. By exporting metadata and original filename info from Lightroom 4, there may be a way to use that data to match on a common field and rename as per original file name.

Using the Lightroom Plug-in LR/Transporter, I was able to create a summary.txt file that contains a tab delimited list of filename,datetimeoriginal where datetimeoriginal is simply formatted as 13:15:25 ... for example

D2X_2377.NEF,10:44:23   D2X_2378.NEF,10:44:24   D2X_2379.NEF,10:44:24

I can't figure out how to use this information with ExIFTool to rename originals. I imagine:

:PsuedoCode:

read files from folder
  read datetimeoriginal
    lookup datetime original in external master file (txt file)
    match datetimeoriginal
    read filename from external masterfile
   rename file to filename from match
close file
go to next file and repeat


Unless there is another better or easier way :-) One problem I see is that my LR/Transporter plugin does NOT seem to output sub-second data. I need it because some bursts were shot at 8fps and there are quite a few shots within the second :tongue:

Thanks in advance for your help.

Manny Gonzalez
ThrustImages.com

gonzalu

I just thought of an alternative but I am not sure how to do it. I can use the "shuttercount" tag to key on but I would need to be able to offset the filename number to use.

Sort of like:

if shutter count number is:

83098, name the file DSC_2124
83099, name the file DSC_2125
83101, name the file DSC_2127


note the skipped file which was likely deleted...

Thank you

Phil Harvey

Hi Manny,

The problem with using ShutterCount is that some pictures may take multiple shutter actuations (ie. HDR), and some may take none (in-camera editing).  The D2X also writes an ImageCount tag which provides another option that may avoid this problem (but I'm not sure because I really don't know what this tag is for).

Adding/subtracting a constant value from a tag is easy to do with a user-defined Composite tag.  See the sample config file for examples.  Your conversions will be something like this:

    ValueConv => '$val - 1234', # (use your offset here instead of "- 1234")
    PrintConv => 'sprintf("%.4d",$val)',


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gonzalu

Thanks Phil :-) I am no coder so wish me luck :tongue:

THinking about what you said about shutter actuations, the D2Xs (as I notice) has a Shutter Count, an Image Count and a Deleted Count. The points you make are well taken but in my case, I can guarantee the batch I am working with did NOT have any in-camera edits nor in-camera HDR or otherwise. Just straight burst shooting (Aviation and Airshows and Sports is my main money maker, not much time to do fancy stuff in cam :smile:)

So anything on using an external file, database of sorts? Like I said, I can generate a tab delimited file with all the metadata in Lightroom. I figured since i have the real filename and a capture time (granted I need to get the author of LR/Transport plugin to also export subsecoriginaldatetime tag) I could use that to match extracted time from file, match to line in external metadata file and use the filename field to name it :-)

OK, let me go play with your suggestions and examples...

MUCH appreciated your help and tool and input!
Thank you

gonzalu

Sorry I forgot one more thing.

The ImageCount tag is an ultimate count when you subtract deleted files (I believe) so that ShutterCount minus DeletedCount equals ImageCount

All I really need in my case is the offset. Since each file has the number and I know what the first file should be based on a visual match of subsecondoriginaldatetime tag, I can just do a sequential match ... I have spot checked and for my particular case this time, it seems to work out.

I will try it first using excel and autofill and spot check further and test on a copy of the folder.

My problem is a huge one and your proposed issues with in-camera edits and HDR etc does make me worry... Although the problem is 500,000 image plus, at least I have them broken down by date and camera models. My newer cameras work out since they have the image number field so I can get those out of the way easily  and shrink the problem somewhat.

Thank you.

gonzalu

What I have done is not working :-( Pardon my ignorance. Iam more comfortable around TCP/IP routing and switching than code  :'(

I entered this into the composite section of the .ExifTool_config file


        # override ShutterCount tag to use an offset of 110739
        ShutterCount => {
            ValueConv => '$val - 110739', # (use your offset here instead of "- 1234")
            PrintConv => 'sprintf("%.4d",$val)',
        },


and get the following output

WITHOUT the composite tag
exiftool.exe -s -U -shuttercount -imagecount 00045986.nef


ShutterCount                    : 113126
ImageCount                      : 81164


WITH the composite tag
exiftool.exe -s -U -shuttercount -imagecount 00045986.nef


ShutterCount                    : 113126
ShutterCount                    : 113126
ImageCount                      : 81164

gonzalu

OK may have figured it out... just used a different name for the compound


        # override ShutterCount tag to use an offset of 110739
        ShutterCountMG => {
          Require => 'ShutterCount',
            ValueConv => '($val - 110739)',
        },

gonzalu

OK, All of a sudden this stopped working :-(

No matter what I try, I get the error:

Warning: [minor] Tag 'ShutterCountMG' not defined

This was working before :( Any ideas what I may be doing wrong? The ShutterCount tag is definitely in the file because I can see it if I just do exiftool -shuttercount filename.nef

Thanks in advance...

Phil Harvey

Is your config file still in the same location?  Where?  Are you running exiftool from the same location?

I just tried this and it still works with the current ExifTool.

Try this:

exiftool -config THE_CONFIG_FILE -shuttercount -shuttercountmg filename.nef

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gonzalu

#9
Thanks Phil... I'll try in a sec.

I tried by having exiftool.exe and config file in the same INSTALL directory which is c:\program files\exiftool\

Also tried it in the same directory as the files I am modifying... Let me force it and see if it works :-)

snip

OK just tried that and of course, NO ERRORS... it seems when the mechanic is in the house, the car will not make any noises!! ugh. So here is my commandline

~\>exiftool.exe -shuttercount -shuttercountmg 00006525.nef
Shutter Count                   : 106079

Tried it by forcing the config file on the commandline and also not forcing it...

the UserDefined tag is not working ?? :/

Phil Harvey

You won't get this warning unless you use the -p option, but the fact that ShutterCountMG isn't generated shows that your config file is no longer working for some reason.  See FAQ 11 for some help with this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gonzalu

Do you have access to my computer somehow? WTF? Now it is working... why is it working now? oh man, this is so confusing LOL... well, sorry for the false alarm I guess. I looked over the FAQ11 and everything was working as expected there. Then I tried the commandline again, and now it worked? Geesh...

OK, I may reopen this topic again if I get stuck, apologies in advance :P

Cheers and thanks again!

Phil Harvey

Something must have changed.  If it stops working again, take note of your current PATH and your current working directory.  Depending on how you run exiftool, changing either one of these may change the version of exiftool that you are running, and if you aren't running the version in c:\program files\exiftool\ then your config file won't get loaded.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gonzalu

I think I know what may have happened. I think the .ExifTool_config file must have gooten corrupted or mis edited when I changed the offset. What I then did after your pointer to the troubleshooter was to copy it all local to the files I was working on to make sure no path issues were involved. Still failed. I then downloaded a fresh copy of the config file sample from the web, and did a diff  on them... there was no appreciable difference but the CRC and byte count did not jive.

I created a fresh copy and that seemed to work... so something got screwy... and I am also a big believer in common logic and common sense, so yes, I do believe you that SOMETHING must have changed!

I put the full steps and sample config file on my blog for safe keeping and reference for the future :)

http://mannyphoto.blogspot.com/2012/08/working-with-exif-tools-to-rename-files.html