ExifTool Forum

ExifTool => Newbies => Topic started by: paradiddles on July 09, 2017, 08:55:26 PM

Title: Setting the EXIF Dates from Filename (with different formatting)
Post by: paradiddles on July 09, 2017, 08:55:26 PM
So I have read several posts about this and searched but came up empty handed on my specific scenario.  I recently had to convert several old movie files into a different format to play.  In doing so all my EXIF data was changed to reflect the day I did the conversion.  The only thing I have left is that the filename were kept the same which have the original date and time the video was taken in them.  All of these videos files are set in this format "03.30.2007 (07.59.42 AM).m4v" (without the quotes).  Is there a way to use EXIF and the -alldates modifier to add the filename dates and times to each EXIF date.  Thank you in advance to anyone that can help.   
Title: Re: Setting the EXIF Dates from Filename (with different formatting)
Post by: StarGeek on July 09, 2017, 09:57:58 PM
Tricky, but I think I have it.  You would use this in place of just Filename:
${filename;s/(\d\d)\.(\d\d)\.(\d{4})/$3$1$2/;s/(?<=\()(\d\d)(?=.*PM)/${1} +12 /ei}

Example using exiftool "-AllDates<${filename;s/(\d\d)\.(\d\d)\.(\d{4})/$3$1$2/;s/(?<=\()(\d\d)(?=.*PM)/${1} +12 /ei}" .  Make sure and test it before running it on your main files.
C:\>exiftool -g1 -a -s -alldates X:\!temp\aa\03*
======== X:/!temp/aa/03.30.2007 (07.59.42 AM).MOV
---- QuickTime ----
CreateDate                      : 2017:04:13 10:57:52
ModifyDate                      : 2017:04:13 10:57:52
---- XMP-exif ----
DateTimeOriginal                : 2017:04:13 10:57:52
---- XMP-xmp ----
CreateDate                      : 2017:04:13 10:57:52
ModifyDate                      : 2017:04:13 10:57:52
======== X:/!temp/aa/03.30.2007 (07.59.42 PM).MOV
---- QuickTime ----
CreateDate                      : 2017:04:13 10:57:52
ModifyDate                      : 2017:04:13 10:57:52
---- XMP-exif ----
DateTimeOriginal                : 2017:04:13 10:57:52
---- XMP-xmp ----
CreateDate                      : 2017:04:13 10:57:52
ModifyDate                      : 2017:04:13 10:57:52
    2 image files read

C:\>exiftool -P -overwrite_original "-AllDates<${filename;s/(\d\d)\.(\d\d)\.(\d{4})/$3$1$2/;s/(?<=\()(\d\d)(?=.*PM)/${1} +12 /ei}" X:\!temp\aa\03*
    2 image files updated

C:\>exiftool -g1 -a -s -alldates X:\!temp\aa\03*
======== X:/!temp/aa/03.30.2007 (07.59.42 AM).MOV
---- QuickTime ----
CreateDate                      : 2007:03:30 07:59:42
ModifyDate                      : 2007:03:30 07:59:42
---- XMP-exif ----
DateTimeOriginal                : 2007:03:30 07:59:42
---- XMP-xmp ----
CreateDate                      : 2007:03:30 07:59:42
ModifyDate                      : 2007:03:30 07:59:42
======== X:/!temp/aa/03.30.2007 (07.59.42 PM).MOV
---- QuickTime ----
CreateDate                      : 2007:03:30 19:59:42
ModifyDate                      : 2007:03:30 19:59:42
---- XMP-exif ----
DateTimeOriginal                : 2007:03:30 19:59:42
---- XMP-xmp ----
CreateDate                      : 2007:03:30 19:59:42
ModifyDate                      : 2007:03:30 19:59:42
    2 image files read


This is using a .MOV file instead of a .M4V, but the results should be similar, I think.

One thing to take note of is that very few videos can have EXIF data, but exiftool can write to XMP and the Quicktime dates covered by AllDates.

Title: Re: Setting the EXIF Dates from Filename (with different formatting)
Post by: paradiddles on July 22, 2017, 07:09:06 PM
StarGeek,

Sorry for the delayed response but I am just getting back into town and was able to try your suggestion out.  It worked like a charm!  Thank you very much for your help in this.  I am now looking through manuals and forums to see what each of the parts mean and do, so I can learn how it all works.

Thanks  Again.
Title: Re: Setting the EXIF Dates from Filename (with different formatting)
Post by: StarGeek on July 24, 2017, 08:22:56 PM
There's a lot of Regular Expressions (RegEx) in there which is better covered by sites that focus on Regex, as it is very complicated on its own.
Title: Re: Setting the EXIF Dates from Filename (with different formatting)
Post by: StarGeek on January 26, 2019, 05:18:40 PM
Reviving this to correct an error.  The original command did not properly deal with 12 am (midnight) and 12 pm (noon).

A correct command would be more along these lines:
exiftool "-AllDates<${filename;m/(\d\d)\.(\d\d)\.(\d{4}) \((\d\d)(.+)([AP]M)/;$_=$3.$2.$1.' '.(($4%12)+(($6 eq 'AM') ? 0 : 12)).$5}" .