renaming files by setting FileName from DateTimeOriginal modified with ShiftTime

Started by tim_rylance, July 19, 2019, 03:51:40 PM

Previous topic - Next topic

tim_rylance

(This is somewhat related to my earlier query about simultaneously correcting the capture time and geotagging photos.)

I would like to correct the capture times of my photos and give each updated file a name based on the newly-corrected capture time, so that (say) foo.jpg -> 20190719-195400-foo.jpg.

I tried

exiftool -alldates+=00:00:32 -d %Y%m%d-%H%M%S-%%f.%%e '-FileName<${DateTimeOriginal;ShiftTime($_,"+00:00:32")}' foo.jpg

but the created filename used the unmodified DateTimeOriginal. 

My actual test was
pi@pi4:~/ShiftTime $ exiftool -ver
11.16
pi@pi4:~/ShiftTime $ wget -q https://upload.wikimedia.org/wikipedia/en/4/48/Blank.JPG
pi@pi4:~/ShiftTime $ exiftool -alldates="2019:12:25 12:00:00+0:00" -gps:all= Blank.JPG
    1 image files updated
pi@pi4:~/ShiftTime $ exiftool -s -datetimeoriginal Blank.JPG
DateTimeOriginal                : 2019:12:25 12:00:00
pi@pi4:~/ShiftTime $ exiftool -alldates-=00:01:00 -d %Y%m%d-%H%M%S-%%f.%%e '-FileName<${DateTimeOriginal;ShiftTime($_,"-00:01:00")}' Blank.JPG
    1 image files created
pi@pi4:~/ShiftTime $ ls
20191225-120000-Blank.JPG  Blank.JPG  Blank.JPG_original
pi@pi4:~/ShiftTime $ exiftool -s -datetimeoriginal 20191225-120000-Blank.JPG
DateTimeOriginal                : 2019:12:25 11:59:00
pi@pi4:~/ShiftTime $

and I was hoping for a filename of 20191225-115900-Blank.JPG.

Yet I know the ShiftTime is being run because I got Warning: Not enough arguments for Image::ExifTool::ShiftTime for 'DateTimeOriginal' until I added the $_ after realising that my exiftool is version 11.16 and predates the new ShiftTime API described by the latest online documentation.

And the ShiftTime appears to do the right thing
pi@pi4:~/ShiftTime $ perl -e 'use Image::ExifTool; $_ = "2019:12:25 12:00:00"; Image::ExifTool::ShiftTime($_,"-00:01:00"); print'
2019:12:25 11:59:00

Phil Harvey

Quote from: tim_rylance on July 19, 2019, 03:51:40 PM
exiftool -alldates+=00:00:32 -d %Y%m%d-%H%M%S-%%f.%%e '-FileName<${DateTimeOriginal;ShiftTime($_,"+00:00:32")}' foo.jpg

The problem is that you are trying to shift the formatted version of the date (ie. after the -d option).  This should work (add a "#" to use the unformatted time):

exiftool -alldates+=00:00:32 -d %Y%m%d-%H%M%S-%%f.%%e '-FileName<${DateTimeOriginal#;ShiftTime("+00:00:32")}' foo.jpg

Note that I have also using the single-argument version of ShiftTime, which is the technique used in the application documentation.

- 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 ($).