ExifTool Forum

General => Metadata => Topic started by: CorM on September 08, 2017, 08:57:07 AM

Title: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: CorM on September 08, 2017, 08:57:07 AM
Hi,

I am using the Exiftool with great pleasure, but stumbled into a problem renaming and moving images and video's to their respective original date/time taken.
example:
..../2013/04/2013-04-21_150649-1.jpg
..../2013/04/2013-04-21_150649-2.jpg

they look to be taken on the same date/time, hence the sequence number for duplicates.
using exiftool -a -G1 -s -time:all ..../2013/04/2013-04-21_150649-1.jpg displays:

[System]        FileModifyDate                  : 2013:04:21 15:06:49+02:00
[System]        FileAccessDate                  : 2017:09:05 12:21:29+02:00
[System]        FileInodeChangeDate             : 2017:09:04 13:46:53+02:00
[ExifIFD]       DateTimeOriginal                : 2010:07:10 18:28:50
[ExifIFD]       CreateDate                      : 2010:07:10 18:28:50
[ExifIFD]       SubSecTimeOriginal              : 00
[ExifIFD]       SubSecTimeDigitized             : 00
[XMP-xmp]       CreateDate                      : 2010:07:10 18:28:50
[XMP-microsoft] DateAcquired                    : 2012:12:13 03:33:14
[Composite]     SubSecCreateDate                : 2010:07:10 18:28:50.00
[Composite]     SubSecDateTimeOriginal          : 2010:07:10 18:28:50.00

As you can see the renaming and moving is done here by using the wrong (not the oldest) date/time tag.

Question: is it possible to let Exiftool determine which tag from the metadata is the oldest and rename and move the image accordingly
or do i have to script it (which i did, but still having questions) to sed/awk the oldest tag and use this to remane/move
problem is that i have lots of pictures to be renamed/moved and they differ in oldest date/time tag.
Most have to be renamed with the CreateDate tag, while some (approx. 1/3) must be renamed with FileModifyDate

I would like to have a single exiftool command or an enhanced script that determines which tag is to be used 

here the script (Bash)

#!/bin/bash
#
# Break on error
#
set -e
#
basePath="/media/melsec/Cor_1_Tb/Prive"
exifPath="$basePath/Exiftool/Image-ExifTool"
#
find ./Pictures -type f -name '*.txt' | xargs rm
#
FILES=$(find ./Pictures -type f -name '*.*')
for foto in $FILES
do
   echo $foto
   $exifPath/exiftool -a -G1 -s -time:all $foto |
   sed '/Date/!d' |
   awk -F"[:]" 'NR == 1 || $2$3$4 <= min {line = $0; min = $2$3$4}END{print line}' > $foto.txt
done

# print all files with content into one output file
rm total.txt
find ./Pictures -type f -name '*.txt' -exec grep "" {} + >> total.txt


I hope i have explained my question explicit enough,  hoping for some assistance.
Cheers, Cor
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: StarGeek on September 08, 2017, 08:52:53 PM
I don't believe that it's possible to create a simple in-line command to do this, but take a look at this thread (https://exiftool.org/forum/index.php?topic=7986.0) where there is a user-defined tag to get the OldestDateTime out of a predetermined selection of time stamps.  You could expand the list to include any tags that aren't already listed.
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: CorM on September 11, 2017, 10:49:53 AM
Thanx StarGeek, i will look into this thread.
noticed the comment from Phil and will explore the Composite tags option for my problem.
In case it won't solve my problem I'll com back to this topic, when success the kudo's are for you (and Phil of course)
Cor
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: CorM on September 12, 2017, 11:17:01 AM
Well, tried the option with Composite tags and used the config by Hayo Baan, the kudo's are going to him aswell.
It works exactly as i wanted it.
Perfect solution for my problem, thanx for the assistance in solving this issue.

Cor
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: CorM on September 13, 2017, 09:23:18 AM
Hmmm, noticed something peculiar with the solution.
listing the oldest date works fine, but using it within the script to recursively rename the files things go wrong!
this is my code for renaming:

$exifPath/exiftool -config $exifPath/config_files/oldest_datetime.config -ext '*' -r '-filename<OldestDateTime' -d '%Y-%m-%d_%H-%M-%S%%-c.%%le' $sourceDir


in short i use the oldestDatTime tag as input for the filname with the format "%Y-%m-%d_%H-%M-%S%%-c.%%le"
so i expect image to be named 2006-11-04_15-35-32.jpg (with a counter for double filenames)
but instead it is renamed to: "2006:11:04 15:35:32" not following the given format (and without extension)
Hayo mentioned in the other thread that the OldestDateTime tag could be used to set e.q. DateTimeOrignal tag
of course I could do that and then use that tag for renaming, but I rather not alter any of the original metadata tags, but directly use OldestDateTime for the renaming (and moving it to the new directory "-Directory<OldestDateTime" in the format -d "$fotoPath/%Y/%m"

Again some help is wanted, Cor
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: StarGeek on September 13, 2017, 12:03:19 PM
Ah, yes.  I know exactly what's wrong.  Unfortunately, I can't remember exactly how to fix it.  It needs an extra line of code in the user defined tag.

The problem is that even though OldestDateTime looks like a date to us, to exiftool it's a string.  It needs to be tagged internally so that exiftool recognizes it as a timestamp so that way the -d option will affect it.  Unfortunately, I don't play around with the internals of exiftool enough to know the answer right off.

I can't check for the answer at the moment, so let me get back to you.
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: StarGeek on September 13, 2017, 01:00:52 PM
Found it (https://exiftool.org/forum/index.php/topic,6630.msg33103.html#msg33103).

Try changing
                return $oldest;
            },


to
                return $oldest;
            },
            PrintConv => '$self->ConvertDateTime($val)',


I think that's the proper placement for it.
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: CorM on September 15, 2017, 02:55:51 PM
Well thanks a million, this solves my problem completely
using the OldestDateTime now works like a normal tag so I am able to rename and move all the pictures to a new location based upon Year/month taken.

StarGeek and Hayo (answering my personal message in dutch) are getting credit for this, hopefully it helps out others with the same issue.

Cor
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: Hayo Baan on September 17, 2017, 03:15:16 PM
Excellent! Good to know StarGeek's addition worked.

@Phil, perhaps the oldestdatetime config file can/should be added to the full distribution (including the additional line)?
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: Phil Harvey on September 18, 2017, 12:13:50 PM
Quote from: Hayo Baan on September 17, 2017, 03:15:16 PM
@Phil, perhaps the oldestdatetime config file can/should be added to the full distribution (including the additional line)?

Hi Hayo,

I'm assuming that you mean add this to example.config?  The problem is that the tags used to derive OldestDateTime in the other thread are very specific.

- Phil
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: Hayo Baan on September 18, 2017, 03:17:42 PM
I actually meant to add it to the config_files directory. Yes, the order and used tags are pretty specific. It would, however, still serve as a great starting point for people wanting similar functionality. So I'd think it would be a very welcome addition to the config_files directory.
Title: Re: mixed date/time stamps in pictures metadata from numerous subdirectories
Post by: Phil Harvey on September 18, 2017, 07:08:58 PM
Good idea.

- Phil