EXIFTOOL - Set datetime from filename
Asked Answered
M

3

7

I have many photos named with a date format but the EXIF dates don't match.

e.g. 2016-12-16_20-20-29.jpg

Running them through EXIFTOOL I can almost overwrite the dates but it doesn't match the exact date format.

exiftool "-datetimeoriginal<filename" ./

This sets the date to the correct calendar day but ignores the time.

exiftool "-datetimeoriginal<filename" -d "%Y-%M-%D_%H-%M-%S.%%e" ./

I believe the -d parameter sets a data format but this returns as error of Warning: Error parsing time in ExifIFD:DateTimeOriginal (PrintConvInv)

Is this the correct method to use?

Magnolia answered 2/1, 2017 at 12:25 Comment(0)
F
12

Your first command should work correctly. From Exiftool FAQ 5:

ExifTool is very flexible about the actual format of input date/time values when writing, and will attempt to reformat any values into the standard format unless the -n option is used. Any separators may be used (or in fact, none at all). The first 4 consecutive digits found in the value are interpreted as the year, then next 2 digits are the month, and so on. [The year must be 4 digits. Other fields are expected to be 2 digits, but a single digit is allowed if the subsequent character is a non-digit.] "

The example given following that paragraph is almost the same as your first command.

The -d option isn't needed for this type of operation.

Example output

C:\>exiftool -datetimeoriginal "X:\!temp\2016-12-16_20-20-29.jpg"

C:\>exiftool "-datetimeoriginal<filename" "X:\!temp\2016-12-16_20-20-29.jpg"
    1 image files updated

C:\>exiftool -datetimeoriginal "X:\!temp\2016-12-16_20-20-29.jpg"
Date/Time Original              : 2016:12:16 20:20:29
Flamenco answered 2/1, 2017 at 18:16 Comment(4)
You are correct! It didn't work as my previous attempts had corrupted the exif data and that's what the error response was.Magnolia
but for some reason, exiftool completely ignores the -d parameter for date/time tags like "MediaCreateDate" and "TrackCreateDate". I'm (not?) hoping it's just too stupid to realize that "Date" in the EXIF tag indicates it's a date.Exigible
@Exigible Do you have an example command? Maybe a sample file you can link? I tested it here with exiftool -TrackCreateDate -MediaCreateDate -d "%Y" on some mp4 files and it worked correctly except in the case of an all 0 time stamp 0000:00:00 00:00:00.Flamenco
@Flamenco Ah... yeah, all the files I tried it on returned the all zero example you gave.Exigible
M
10

To follow up on StarGeek's good answer.

It turns out I had corrupted my exif data and that is why the command didn't succeed.

To fix it I first cleared the data

exiftool -all= −overwrite_original ./

then I was able to run the command again to set the date from the filename. An added bonus was that I discovered the property -alldates which updated every date within the meta data excluding the file write / mod dates.

exiftool "-alldates<filename" −overwrite_original ./

.n.b −overwrite_original prevents the creation of backup files

Magnolia answered 5/1, 2017 at 15:46 Comment(1)
Some additional info. Rather than clearing all the metadata in the file, you could have tried to recover as much as possible with this command: exiftool -all= -tagsfromfile @ -all:all -unsafe Also, -alldates only affects the three most common EXIF date/time tags: DateTimeOriginal, CreateDate, and ModifyDate. To change all datetime tags, use -Time:all You can also use −overwrite_original to avoid backup files. It's a bit safer as it makes a copy first, then replaces the original file, rather than directly overwriting the original file.Flamenco
C
1

Set to oldest date from Exif meta or file name

Step 0 - install exiftool from below

Installing ExifTool

👉 Step 0.1

Save the oldest_datetime_config in the home folder C:\Users\YOURUSERNAME or in your home directory ~ or in the same folder where you have installed exiftool. This step is important for the following steps to be successful.

You can find these in a script here but I have found that running the commands in the pic folder I mentioned in the options below are much much faster than running these through python script exif-scripts/setToOldestDate.py For faster processing you can run these commands directly in powershell from the pic folder you are planning.

If you are running WSL then run these commands from poweshell and not WSL are the file system read write from the windows virtualization will blow up your ram and will slow down the process to a halt.

🦺 Note that these scripts are recursive and will affect all the subfolders are well.

Well … now — pick your options:

Option 1 - In case you need to pick the date from the file name.

This is pretty flexible and fuzzy parser from exiftool but if you want it to be absolutely sure then you can remane the file to include yyyymmdd_hhmmss and remove all the other number before it (after is OK).

exiftool "-FileModifyDate<filename" −overwrite_original -S -m -progress -ee -q -q ./

Option 2 - set all the dates to the oldest date

exiftool -overwrite_original "-FileModifyDate<OldestDateTime" "-ModifyDate<OldestDateTime" "-DateTimeOriginal<OldestDateTime" "-CreateDate<OldestDateTime" "-GPSDateTime<OldestDateTime" -S -m -progress -ee -q -q ./

Option 3 - set the name of the file in PXL_yyyymmdd_hhmmss-[number-if-conflict].extension

exiftool "-filename<OldestDateTime" -d PXL_%Y%m%d_%H%M%S%%-c.%%e -S -m -ee -progress -q -q ./

to push all the files in the current directory use

adb push -a . /sdcard/DCIM/Camera/

-a is to preserve the attributes.

⌛ Refresh Android Media Store

As a last step, you need to refresh the android media store database to let google photos know which new files to backup. Currently it does not always detect automatically so why wait for that. Install Refresh MediaStore and run it after the adb push is complete from the phone. Then you can open Google Photos and see that the backup is starting.

Christo answered 1/8, 2022 at 1:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.