Extract dates from files in UTC

Started by maxardis, May 20, 2024, 06:52:02 AM

Previous topic - Next topic

maxardis

Hello,

What I would like is to generate dates(*) in UTC (in ISO format) from exif tags for all files in directory without modifying files.

Similarly to a tool like sha1sum I would like to write something like: exiftool (magic options here...) ./directory/* and get output to stdout like so:

2024-01-01T10:10:10  ./directory/file1.jpg
2024-01-01T10:11:10  ./directory/file2.jpg
2024-01-02T10:10:10  ./directory/file3.jpg
...

Output similar to sha1sum but instead of hashes I get dates.

(*) When I say dates what I mean exactly is combination of tags exif:DateTimeOriginal + exif:OffsetTimeOriginal.


What I was able to figure out is:

$ exiftool -d '%Y-%m-%dT%H:%M:%S' -p '${exif:DateTimeOriginal}${exif:OffsetTimeOriginal} ${directory}/${filename}' ./dir/*

This gives me almost what I want.  It gives me the information to stdout in format similar to sha1sum, it gives me dates in ISO format, but it doesn't give me the dates in UTC.

By googling around I can see that there is something like ShiftTime() function that maybe I could use, but unfortunately I cannot make it work.  So I am here for your help.


I am trying to do this:

exiftool -p '${exif:DateTimeOriginal;ShiftTime(${exif:OffsetTimeOriginal}, -1)} ${directory}/${filename}' ./dir/*

And what I get is a warning: Warning: Bareword "OffsetTimeOriginal" not allowed while "strict subs" in use for 'exif:DateTimeOriginal'.  I don't understand that message and I don't know what I am doing wrong, nor how to fix it.

Hope you can help me here.  Thank you in advance.

StarGeek

Quote from: maxardis on May 20, 2024, 06:52:02 AMI am trying to do this:

exiftool -p '${exif:DateTimeOriginal;ShiftTime(${exif:OffsetTimeOriginal}, -1)} ${directory}/${filename}' ./dir/*

And what I get is a warning:
Warning: Bareword "OffsetTimeOriginal" not allowed while "strict subs" in use for 'exif:DateTimeOriginal'.  I don't understand that message and I don't know what I am doing wrong, nor how to fix it.

Nice attempt, but it isn't that simple to access a different tag within the processing of another tag. The error message is directly from the underlying Perl processor. Accessing a second tag from within a tag can be done, but I think this would be a better way.

First, instead of using DateTimeOriginal, use SubSecDateTimeOriginal.  This is a Composite tag that combines DateTimeOriginal, OffsetTimeOriginal, and SubSecTimeOriginal.  Then the DateFmt helper function is used to convert that to a Unix time stamp, the internal exiftool function of ConvertUnixTime is used to convert that to a normal date in the standard EXIF format (colons instead of hyphens), and DateFmt is used again to convert that into the format you're looking for.

Example
C:\>exiftool -G1 -a -s -SubSecDateTimeOriginal y:\!temp\Test4.jpg
[Composite]     SubSecDateTimeOriginal          : 2024:05:20 12:00:00-07:00

C:\>exiftool -p "${SubSecDateTimeOriginal;DateFmt('%s');$_=ConvertUnixTime($_);DateFmt('%Y-%m-%dT%H:%M:%S')}" y:\!temp\Test4.jpg
2024-05-20T19:00:00

You don't mention your OS, but you appear to be on Mac/Linux.  The above command would be for Windows CMD, so you'll have to swap double/single quotes.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

maxardis

That works perfectly.  Thank you very much.

Just one question.  I cannot seem to find any mention of ConvertUnixTime() in man pages nor by googling (only mentioned on some other threads on this forum).  And you also say that it is an internal function.  So I guess it means that it might "disappear" with some future version of exiftool right?  It is kind of a hack, sort of, right?

Quote from: StarGeek on May 20, 2024, 12:13:34 PMYou don't mention your OS, but you appear to be on Mac/Linux

I am on Linux if that is important, yes.  I can translate Windows CMD into Linux one no problem.  It's pretty much the same

StarGeek

Quote from: maxardis on May 20, 2024, 02:21:13 PMJust one question.  I cannot seem to find any mention of ConvertUnixTime() in man pages nor by googling (only mentioned on some other threads on this forum).  And you also say that it is an internal function.  So I guess it means that it might "disappear" with some future version of exiftool right?  It is kind of a hack, sort of, right?

Yes, the only way to know about it is to dig through the source code or have seen Phil use it in the past.  I seriously doubt it will disappear, as it is a basic part of so much of the exiftool code and would most likely require a huge rewrite of a lot of code to remove it. And Phil strives hard to make sure any changes are backwards compatible. For example, the -AddTagsFromFile option no longer appears in the documentation, as it has been replaced with a different format, but it still will work if you use it.

Hack? I wouldn't say so. It's more of a function that isn't documented outside of the source code

Quote
Quote from: StarGeek on May 20, 2024, 12:13:34 PMYou don't mention your OS, but you appear to be on Mac/Linux

I am on Linux if that is important, yes.  I can translate Windows CMD into Linux one no problem.  It's pretty much the same

It's important when it comes to quoting, as double quotes on Linux/Mac will change something like $DateTimeOriginal from an exiftool tag into a shell variable.  It's also important with something like the asterisk, as using it as an exiftool wildcard such as -*Date will cause file globbing on Mac/Linux unless single quotes are used '-*Date'
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

maxardis

Ok, everything is clear.  Thank you once again.  Have a nice day.