change tag based on difference in time tags?

Started by filmgeezer, January 08, 2020, 09:28:17 PM

Previous topic - Next topic

filmgeezer

Is there a way to compare date/time tags for a specific difference?

If I've got files that have times in different tags differing by exactly 4 minutes, I'd like to re-write them to match. (They may properly differ by 1 hour, so a simple "ne" comparison won't work).

Something like this pseudocode:
GPSDateTime = DateTimeOriginal
if DateTimeOriginal - GPSDateTime <= 4:00

Phil Harvey

Try this:

exiftool -if "$gpsdatetime - $datetimeoriginal == 4 * 60" -d %s "-gpsdatestamp<datetimeoriginal#" "-gpstimestamp<datetimeoriginal#" DIR

However, you must worry about time zones because DateTimeOriginal is normally in local time, and GPSDateTime is UTC.

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

filmgeezer

Thanks much. I'll take that into account as well. I'm using this to test for (and fix) some past screwups where I compensated for timezone by 4:00 instead of the intended 4:00:00  :o

I'm parsing the command with my small brain to try to fully understand it.

== is my comparison operator
4*60 because the difference between the two will come through in seconds
... because of the -d %s bit?
put datetimeoriginal(no print conversion) into gpsdatestamp
put datetimeoriginal(no print conversion) into gpstimestamp

Phil Harvey

You've got it.  See the Date format codes section of this page for an explanation of %s and other date/time format codes.

Note that GPSDateTime is a Composite tag based on GPSDateStamp and GPSTimeStamp, which is why both must be written.  See the GPS tags documentation for hints about writing GPSDateStamp and GPSTimeStamp.

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

filmgeezer

Ah, so I'm wasting my time trying to write:

-XMP:GPSDateTime

But I was OK because before that I wrote:

-GPSDateStamp and -GPSTimeStamp

Love Exiftool, but you can fill a large warehouse with what I don't know about it, even after having used it for a couple years.

Phil Harvey

I was assuming you wanted to write EXIF GPS tags.  XMP GPS tags are less common.

Yes, the subject of metadata is very complex because of all the different formats, which makes ExifTool sort of complex because it has to deal with all of these formats.

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

filmgeezer

I'm trying (and failing) to output just the datetimeoriginal - gpsdatetime as part of my testing.
Do I need to make a user-defined tag, or maybe I'm just failing my advanced formatting.

my command generates a Bareword warning, which sounds impressively impure. I'm sure my latest try will shock and amuse those who know better:

exiftool -p '${datetimeoriginal#;_*60} - ${gpsdatetime#;_*60}' .

Phil Harvey

There are a couple of things wrong with this:

1. The -p option takes a format string as an argument.  This is very different than a Perl expression.  Specifically, you can't do arithmetic (like your subtraction) in a format string (except inside the braces of an advanced formatting expression).

2. In the advanced formatting expression, you are multiplying by 60, but the value is an EXIF-formatted date/time string, not a number, so you can't do math on that either.  This is another reason why your subtraction won't work.

This post by StarGeek shows almost exactly what you want to do.

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