I'm copying CR2 files from a camera card to a destination in my photo library in a bash script (mac). This string seems to be working great for my purposes:
exiftool -r -P "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" $CAMERACARDPATH
... giving me filenames that look like this: 20140508-205107-MDT-5DM30004.CR2
My trouble comes when I want to shift the time info in the new filenames, but do not want to change the raw files at all. If my camera is set to GMT, and I'm shooting in Denver (while it's MDT), I want the filenames to reflect the local time, but I do not want the GMT-based timestamps in the file to be altered.
I've tried several variations on this...
exiftool -r -P "-FileName<DateTimeOriginal-=6" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" $CAMERACARDPATH
exiftool -r -P "-FileName<DateTimeOriginal-=0600" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" $CAMERACARDPATH
... and so forth, but don't seem to be getting anywhere.
Sorry for the beginner's question. Any guidance someone can provide would be most appreciated.
Hi George,
You are having trouble because ExifTool doesn't have the ability to do this.
Either you need to make a user-defined tag with a shifted date/time (which is tricky and you would have to change the definition to change the amount of shift), or you can go through some intermediate file, and use 3 commands, like this:
exiftool -r -o "$TEMPFOLDER/%f.xmp" -datetimeoriginal $CAMERACARDPATH
exiftool $TEMPFOLDER -datetimeoriginal-=6
exiftool -r -P -tagsfromfile "$TEMPFOLDER/%f.xmp" "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" $CAMERACARDPATH
I think this should work, but I didn't test it to be sure I didn't make a mistake.
- Phil
Edit: The -globalTimeShift option provides a better solution... see my later post
Thanks, Phil. Your suggestion using tagsfromfile looks interesting. I'll try that.
Appreciate your help,
George
Phil, your suggested command strings work pretty well. The only snag is that I have occasionally run into a Canon camera card that has multiple image folders on it. When this happens it usually means you'll have duplicate filenames across the folders, which causes collisions as EXIFTool is trying to write the XMP files.
I've solved it by looping through the folders on the card (100EOS5D, 101EOS5D, 102EOS5D, etc.), changing the filenames during the copy, and then clearing out the contents of the TEMPFOLDER at the end of each loop.
Admittedly, this will only happen infrequently, but I was alerted to it as a potential problem the other day. Just a few frames after my camera rolled over from 9999 to 0001 it crashed for some reason. I had to take the battery out to revive it and that (or the crash) reset the counter, just as manually resetting the counter or creating a new folder on the camera would do.
Anyway, looping through the folders works. Thanks again for the help.
An alternative is to create the same directory structure for the temporary files, something like this:
1. cd $CAMERACARDPATH
2. exiftool -r -o "$TEMPFOLDER/%d%f.xmp" -datetimeoriginal .
3. exiftool -r $TEMPFOLDER -datetimeoriginal-=6
4. exiftool -r -P -tagsfromfile "$TEMPFOLDER/%d%f.xmp" "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -o "$DESTINATIONFOLDER" .
Additionally, you could add "_%e" ("$TEMPFOLDER/%d%f_%e.xmp") to the temporary file names to handle the case with same-named files with different extensions in the same directory.
- Phil
Edit: Forgot a -r in command 3.
> Edit: Forgot a -r in command 3.
Caught that. :-)
Now you've given me more work to do. Many thanks for your helpful suggestions.
G.
I'm having trouble finding documentation on how I can set a specific extension using "_%e" option.
When copying files into another folder, in the case of a filename collision I would like to change the default "-10" or "-11" extension that is added to the incoming files.
Any pointers would be much appreciated.
George
Hi George,
This is explained in detail in the -w option section of the application documentation (https://exiftool.org/exiftool_pod.html).
- Phil
Well, I guess I'm dense enough that I probably need an example.
It seems the -w option is to write or overwrite the output text files (in this case XMP), if I'm reading that correctly. In any case, once I'm finished with a successful copy with rename, I delete the temp XMP files. And it's during a subsequent copy with rename into the same destination, that I need to worry about filename collisions. (For those cases where I might add new photos to a card that I've already imported, I want exiftool to skip those that already exist, if possible.)
Does this make sense? Thanks again from an impaired, amateur coder.
Yes, this makes sense. You won't be using the -w option, but the file name formatting is the same for all ExifTool features.
I guess I'm not really clear on what you're doing now and how you want to change it, so I can't give you a specific example... I don't know what you are talking about when you mention "-01" and "-11" extensions.
- Phil
The code as you suggested is working well:
cd /Volumes/EOS_DIGITAL
exiftool -r -o "$TEMPFOLDER/%d%f.xmp" -datetimeoriginal .
exiftool -r $TEMPFOLDER -datetimeoriginal$TZOFFSET
exiftool -r -P -tagsfromfile "$TEMPFOLDER/%d%f.xmp" "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S$TZOFFSETFORFILENAMES-%%f.%%e" -o "$DESTINATIONFOLDER" .
This gives me file names in the destination that look like this:
20140421-134855-0600-5DM30058.CR2
20140421-135122-0600-5DM30059.CR2
20140421-135131-0600-5DM30060.CR2
And then I am deleting the entire temp folder for that copy and renaming session. All of this works great unless I run the script on the same card twice, or if I don't reformat the card, add photos to it, and then try to run the script on that card to just copy the new images from it. So I either need a way to have exiftool skip files that already exist in the destination with the same name, or allow duplication with an additional extension, giving file names that look like this:
20140421-134855-0600-5DM30058.CR2
20140421-134855-0600-5DM30058-2.CR2
20140421-134855-0600-5DM30059.CR2
20140421-134855-0600-5DM30059-2.CR2
20140421-135122-0600-5DM30060.CR2
20140421-135131-0600-5DM30060-2.CR2
Thanks for any pointers you can provide.
George
Hi George,
Quote from: George Jardine on May 14, 2014, 09:15:48 AM
So I either need a way to have exiftool skip files that already exist in the destination with the same name, or allow duplication with an additional extension.
Currently, it will skip files that already exist (giving appropriate error messages).
To duplicate the files as you indicated, add a "%-c" in step 4:
exiftool -r -P -tagsfromfile "$TEMPFOLDER/%d%f.xmp" "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f%%-c.%%e" -o "$DESTINATIONFOLDER" .- Phil
Thanks again. Appreciate the help.
George
Phil, now I'm tweaking things, and I'm finding a very weird anomaly. I'm absolutely sure this is not your problem, but I wondered if you would venture an opinion on what's going on.
When I run the scripts using either EXIFTool (as we've been talking about in this thread) or using cp -Rpv to copy the files on my iMac, the modification dates are never updated, as desired.
But when I run the very same scripts (I've tested copies performed by both cp and EXIFTool) on my MBP laptop, I find 20 or 30% of the new copies DO have updated modification files. And of course it's never the same files. Sometimes it's just a handful, other times dozens (out of 170 in this test). In these tests, I'm using the same camera card, same source photos, same card reader, same cable, everything. Both Macs are running 10.8.5.
So it seems pretty strange that both copy methods work as expected on one machine, but on the laptop, there are always at least a few random files copied with updated modification times. (Always modified to the exact moment of the copy.)
Is this my worst nightmare? (Bad hardware?) Any thoughts on what might be causing this?
Thanks again for your help,
George
Hi George,
This may be a bug in OS X. I have seen problems before with the filesystem modification time not getting set correctly. I have tried to find a work-around, but couldn't. One user has submitted a bug report to Apple, but I haven't heard back. See this thread (https://exiftool.org/forum/index.php?topic=5664.0) for details.
- Phil
Update: Tried both scripts on another (older) MacBook, and both scripts showed random, changed modification dates there too. I changed the cp line to use rsync, and now files copied from the card with rsync have preserved modification dates, on both laptops. But after the rsync copy, when I update the filenames using EXIFTool, I get random updated modification dates on one machine (the newer, 2011 laptop) but not on the older 2008 laptop.
Hi George,
Back to the original topic...
I must be getting old. I was reading the exiftool documentation (which I recommend to everyone), and discovered the -globalTimeShift feature that I had forgotten about. This feature is designed with your workflow in mind. So the clumsy 3-step process may be avoided, and this command will do what you want:
exiftool -r -P "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -globaltimeshift -6 -o "$DESTINATIONFOLDER" $CAMERACARDPATH
Sorry I didn't think of this earlier.
- Phil
Quote from: Phil Harvey on May 18, 2014, 10:14:31 AM
exiftool -r -P "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -globaltimeshift -6 -o "$DESTINATIONFOLDER" $CAMERACARDPATH
- Phil
Phil,
This is very useful. I must be greedy, but is there a way to do rename instead of copy? I have tons of video files on a NAS. Due to the size and number of files, the copy process is extremely slow.
I was thinking of using Windows scripting to rename the files if exiftool can extract the date/time from file and pass it to my script.
To move instead of copy, just don't use the -o option. Instead, use -directory="DESTINATION FOLDER" to move the file, or write a full path to FileName.
But this will only help speed things up if both directories are on the same device. It wouldn't help for the original intent of this thread, which it seems was to copy files from a camera's memory card.
- Phil
Ok, I admit I'm a scripting newbie. But I managed to build a Windows script (Rename.vbs) to do the job.
My scenario is: I have many MOV files from iPhone with the names of IMG_0001.MOV, IMG_0002.MOV, etc. I wanted to rename them with the date/time of the video taken, in the format of "yyyy-mm-dd hh-mm-ss.mov" (e.g. "2015-06-13 10-30-25.mov"). I wanted to use local time instead of UTC (GMT time).
The workflow is very simple:
1) Get the file names in "./Media" folder (where all the MOV files are).
2) For each file, use "exiftool -ContentCreateDate" command to extract the creation date/time, which has the time in local time format.
3) Use the exiftool output to construct the filename I want.
4) Rename the file
Here's the file structure:
C:\Temp\exiftool.exe
C:\Temp\rename.vbs
C:\Temp\Media\IMG_0001.MOV
C:\Temp\Media\IMG_0002.MOV
...
To run the program, open a command prompt at "C:\Temp" and type "cscript rename.vbs".
Set objFSO = CreateObject("Scripting.FileSystemObject")
' .\Media is where I keep the *.MOV files
objStartFolder = ".\Media"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set objShell = CreateObject("WScript.Shell")
Set colFiles = objFolder.Files
For Each objFile in colFiles
' Use exiftool to get the ContentCreateDate tag
Set objWshScriptExec = objShell.Exec("exiftool -ContentCreateDate " & objFile)
Set objStdOut = objWshScriptExec.StdOut
strOutput = objStdOut.ReadAll
strYear = mid(strOutput, 35, 4)
strMonth = mid(strOutput, 40, 2)
strDay = mid(strOutput, 43, 2)
strHour = mid(strOutput, 46, 2)
strMinute = mid(strOutput, 49, 2)
strSecond = mid(strOutput, 52, 2)
strNewName = strYear & "-" & strMonth & "-" & strDay & " " & strHour & "-" & strMinute & "-" & strSecond & ".mov"
strCmd = "%COMSPEC% /c ren " & objFile & " " & chr(34) & strNewName & chr(34)
objShell.Exec (strCmd)
Next
Like I said, you don't need to script this. This is common mistake number 3 (https://exiftool.org/mistakes.html#M3).
- Phil
Thanks Phil for pointing this out.
Yes, the clumsy script can be replaced with a single command:
exiftool "-FileName<ContentCreateDate" -d "%Y-%m-%d %H-%M-%S%%-c.%%le" .\media
I guess the point is - if the media file has 'ContentCreateDate' tag available, that seems to be the best option to retrieve the local time. Using "globalshift" might produce wrong time if media files are from different timezones.