Batch changing EXIF date/time

Started by vladman, July 12, 2016, 07:14:26 AM

Previous topic - Next topic

vladman

Hi,

I really need some help, I tried to figure it out on my own, and searching here, but can't find specific info/steps I need to take in order to achieve what I'm trying to do.

I have 167 photos, which were taken over the course of 7 days on holiday. For some reason, all of them are missing the Date Taken info, and only have the Date Modified set to some date in 2009. In effect, they only differ in their file names, the Date Modified (and Time) is identical for all of them (and incorrect), and the Date Taken info is missing.

What I'd like to do:


  • Assign approximately the correct date to them, incrementally, by assigning the first day of holiday to the first 24 images, the second date to the next 24, etc (this way, the last day will have 23 pictures left,  this needs to be taken into account for the command line parameters to work?)
  • Assign approximately the correct time to them, incrementally, by assigning the time of, let's say 11:00 to the first of the 24 images on any given date, and then increment that by 10 minutes, or something like that for all images on that day, and then do the same for every following day

Can someone help me with this? I'd really appreciate it.

Many thanks,

Vlad.

Phil Harvey

#1
Hi Vlad,

What you are asking is tricky, but try this (assuming your holiday was on 2016:07:01):

1. exiftool "-datetimeoriginal=2016:07:01 00:00:00" -r DIR

2. exiftool "-datetimeoriginal+<filesequence" -r DIR

3. exiftool "-datetimeoriginal<${datetimeoriginal;s/ .*/ 11:00:00/}" -r DIR

4. exiftool "-datetimeoriginal+<0:${filesequence}0" -if "$datetimeoriginal =~ /^2016:07:01/" -r DIR

These commands must be executed in sequence.  The first command sets all times to the first day of your holiday.  The 2nd command increments the time of each subsequent image by one hour (effectively spreading them out so you have 24 pictures per day).  The 3rd command takes these all back to 11:00 on their corresponding day.  The last command advances the images on the first day of your vacation by 10 minutes per picture.  This last command will have to be repeated for each day of your vacation (changing the date in the command to "2016:07:02", then "2016:07:03", etc).

- Phil

Edit: Added missing "/" in command number 3.
...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 ($).

vladman

Hello Phil,

Thanks very much for taking the time to reply, I really appreciate it!

I will try your suggestions and see how I get on.

Many thanks again,

Vlad.

vladman

Hi Phil,

So I tried this today. The first two steps worked ok. After I tried executing your third command, each file in the directory returned the "Substitution replacement not terminated for DateTimeOriginal" error message. ??? It said 167 files updated at the bottom, but after checking, their times didn't change to 11:00, they all remained what they were following the previous step.

I've been thinking, would it not be easier to achieve what I'm trying to do by creating separate folders for each day of the holiday, and manually placing all the pictures as I see fit into each one, and then working on each folder separately? I think it may simplify the commands required, but I still need your help (if you don't mind)!  :-\

Thanks very much!

Vlad.

P.S. I'm trying to understand better how ExifTool works, as I'm following your instructions. I know this is basic, but what does "-r" in your commands do? I tried searching in FAQs and elsewhere and couldn't find it. Also, how does the second command work, as I don't see anywhere in it number "1", which is by how many hours it advances the time tag of each picture. Finally, is ExifTool able to handle different regional settings automatically (it seems to me that it is, but can you confirm)? As I'm in the UK, our date format is DD/MM/YYYY, and in your commands, the format is YYYY:MM:DD. Thank you!  :)

Hayo Baan

Quote from: vladman on July 13, 2016, 05:17:07 AM
Hi Phil,

So I tried this today. The first two steps worked ok. After I tried executing your third command, each file in the directory returned the "Substitution replacement not terminated for DateTimeOriginal" error message. ??? It said 167 files updated at the bottom, but after checking, their times didn't change to 11:00, they all remained what they were following the previous step.

There's a missing slash at the end of the regular expression:
3. exiftool "-datetimeoriginal<${datetimeoriginal;s/ .*/ 11:00:00/}" -r DIR

Quote from: vladman on July 13, 2016, 05:17:07 AM
I've been thinking, would it not be easier to achieve what I'm trying to do by creating separate folders for each day of the holiday, and manually placing all the pictures as I see fit into each one, and then working on each folder separately? I think it may simplify the commands required, but I still need your help (if you don't mind)!  :-\

This I think is a wise idea; the automatic approach would just put 24 images in a day and that is likely not appropriate.

Quote from: vladman on July 13, 2016, 05:17:07 AM
P.S. I'm trying to understand better how ExifTool works, as I'm following your instructions. I know this is basic, but what does "-r" in your commands do? I tried searching in FAQs and elsewhere and couldn't find it. Also, how does the second command work, as I don't see anywhere in it number "1", which is by how many hours it advances the time tag of each picture. Finally, is ExifTool able to handle different regional settings automatically (it seems to me that it is, but can you confirm)? As I'm in the UK, our date format is DD/MM/YYYY, and in your commands, the format is YYYY:MM:DD. Thank you!  :)

-r is used to recurse into subdirectories. As you have all images in one directory, this isn't necessary.

The trick in the second command is that Phil adds the file sequence number (a number increased for each following file) to the original time (which was 0:00:00)

By default exiftool uses YYYY:MM:DD for dates, you can change this with the -d command line option, e.g., -d '%d/%m/%Y %H:%M:%S' (change single quotes to double quotes if you're on windows).

Hope that answers your questions.
Hayo Baan – Photography
Web: www.hayobaan.nl

vladman

Hayo, thank you! I'll give it all a go and let you know how I get on.

Phil Harvey

Quote from: Hayo Baan on July 13, 2016, 07:12:18 AM
The trick in the second command is that Phil adds the file sequence number (a number increased for each following file) to the original time (which was 0:00:00)

And the real trick is in the 4th command: "-datetimeoriginal+<0:${filesequence}0"

In the second command, the shift string was simply hours ("HH") so FileSequence could be used directly, but to shift minutes the syntax is "0:MM" (see the Time Shift documentation).  And to shift by 10 minutes at a time FileSequence must be multiplied by 10, which was done by adding a "0" after the FileSequence number in the shift string.

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

vladman

Hi Phil and Hayo (and anyone else reading this  :)),

I got it all done, with your huge help. I ended up creating separate folders for each day of the holiday, and moved a number of pictures into each one. Then I simply applied the following two commands on each folder, slightly modified from Phil's original suggestions, in sequence:

exiftool "-datetimeoriginal=2016:xx:xx 11:00:00" -r DIR (sets the date for that day, and time to 11:00 for all pictures in the folder)
exiftool "-datetimeoriginal+<0:${filesequence}0" -r DIR (increments the time by 10 minutes for each picture in the folder)

I doubt I would've been able to do this without your help, especially with the clever second command. So thank you very much!  :D

vladman

Hi, I was wondering if I can ask for a bit more help.

So I managed to get the Date Taken sorted, but they all still now show Date Created date as the date and time when I did this work with them, so don't sort properly in a folder, if sorted by date, as that goes by Date Created (I think), rather than Date Taken.

How could I (hopefully it's not complicated) copy the Date (and time) Taken info to Date Created field for all of them?  If there's something I'm wrong about with this idea and approach, please educate me!

Many thanks (again).

Vlad.

Hayo Baan

Actually, file sorting by date is usually done on the modification date/time of the file so if you want to enable that in e.g., the Finder or Windows Explorer, that is the tag you want to set with the DateTimeOriginal. This is quite easily done with exiftool: exiftool -filemodifydate"<datetimeoriginal" FILE/DIR (add -r if you want to include subdirectories as well).

Hope this helps,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

vladman

Thank you again Hayo, I'll give it go!  :)

vladman

Hi, I went ahead and did this, running the command as per Hayo's instruction: exiftool -filemodifydate"<datetimeoriginal" *.* (having previously navigated to the directory containing all the images)

It seemed to work, but it reported this: "Warning: [minor] Bad format (1792) for MakerNotes entry 0 - DSCN0395.JPG 167 image files updated". Not sure what that's about, I had a look at that picture, and it seems fine, I can open it, the dates are ok, etc. Not sure if I need to worry about it.

Thanks for the help again!

Hayo Baan

Great to hear it worked :)

From the warning, ExifTool determined there was a small issue (an invalid entry) with the makernotes in the file DSCN0395.JPG.

If you run exfitool on it and compare the data with a similar (but fully OK) file, you should be able to determine if you need to worry about e.g., data loss. Other than that it is likely there will be no issue with the file (the most important thing, the image itself, was OK).

Cheers,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl