Author Topic: Shift DateTimeOriginal by time extracted from filename  (Read 482 times)

jakwas

  • Newbie
  • *
  • Posts: 2
Shift DateTimeOriginal by time extracted from filename
« on: September 02, 2018, 09:01:11 PM »
Hello,
I have many photo files with names like this:
0000-00-00 00.00.33_2017-07-26 20.05.35 M2U00024.MPG.JPG
where:
1) first part: "0000-00-00 00.00.33" is the time (00:00:33) by which I want to shift datetimeoriginal. 
00.00.33 means 33 seconds and it means that this photo file is a screen capture from 33 second in movie called M2U00024.MPG.
When it could help something I could change file names (with ReNamer) to such names for example:
00.00.33_2017-07-26 20.05.35 M2U00024.MPG.JPG

2) second part is the date of the creation of the film (for example M2U00024.MPG) from which the picture originated.

According to this second part I was able to set DateTimeOriginal for each photo (for example 2017-07-26 20:05:35).

But I want additionally to shift this DateTimeOriginal by this value which is at the beginning of the file name (for example 00:00:33, so DateTimeOriginal would be 2017-07-26 20:06:08).

I tried for example something like this:
exiftool "-datetimeoriginal+=filename" -d "%Y:%M:%D %H:%M:%S" "0000-00-00 00.00.33_2017-07-26 20.05.35 M2U00024.MPG.JPG"
but it says "Warning: Invalid shift string (filename) for ExifIFD:DateTimeOriginal. Nothing to do."

How can I do that what I want with exiftool or with another tool (when it is imposiible or very difficult with exiftool)? And it would be the best when it would be batch command for all files in one directory.

Thank you very much in advance.
« Last Edit: September 02, 2018, 09:58:32 PM by jakwas »

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 1055
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: Shift DateTimeOriginal by time extracted from filename
« Reply #1 on: September 03, 2018, 03:02:55 AM »
Hmm, even after changing the shift into something that should work, I still either get the wrong results or still an error. Looks like something isn't working properly.

@Phil, any idea why e.g.
Quote
exiftool '-datetimeoriginal+=0000:00:00 00:00:33' 0000-00-00\ 00.00.33_2017-07-26\ 20.05.35\ M2U00024.MPG.JPG
works but
Quote
exiftool '-datetimeoriginal+=${filename;s/_.*//g;s/[.-]/:/g;}' 0000-00-00\ 00.00.33_2017-07-26\ 20.05.35\ M2U00024.MPG.JPG
doesn't, event though
Quote
exiftool -p '-datetimeoriginal+=${filename;s/_.*//g;s/[.-]/:/g;}' 0000-00-00\ 00.00.33_2017-07-26\ 20.05.35\ M2U00024.MPG.JPG
shows the exact same shift  string...
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14759
    • ExifTool Home Page
Re: Shift DateTimeOriginal by time extracted from filename
« Reply #2 on: September 04, 2018, 03:57:39 PM »
This works (change the "=" to "<"):

exiftool '-datetimeoriginal+<${filename;s/_.*//g;s/[.-]/:/g;}' 0000-00-00\ 00.00.33_2017-07-26\ 20.05.35\ M2U00024.MPG.JPG

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

jakwas

  • Newbie
  • *
  • Posts: 2
Re: Shift DateTimeOriginal by time extracted from filename
« Reply #3 on: September 08, 2018, 06:34:36 AM »
Thank you both very much :) That helped me a lot.

jason1365

  • Newbie
  • *
  • Posts: 1
Re: Shift DateTimeOriginal by time extracted from filename
« Reply #4 on: April 20, 2019, 12:40:35 AM »
Can I take this topic one step further? I'm trying to organize my pictures and videos by into folders and filenames using date and time.

I've read in some other threads that MP4 files should stick to UTC dates. So, rather than changing any meta-data dates, I'd like to name the filename with a date based on my local offset. I've followed the guidance here to get a time sift to be based off another field. Now, I need to help taking that new date and applying it to file naming.

Code: [Select]
$ exiftool -CreateDate -ModifyDate -FileModifyDate IMG_1562.MP4
Create Date                     : 2018:03:21 20:37:15
Modify Date                     : 2018:03:21 20:37:16
File Modification Date/Time     : 2019:04:20 00:33:11-04:00

Adjust by the timezone offset found in FileModifyDate

Code: [Select]
$ exiftool '-CreateDate-<${FileModifyDate;s/.+-(\d+):\d+/0000:00:00 $1:00:00/;}' IMG_1562.MP4
    1 image files updated
Success.

Now, since I shouldn't be changing any dates in the file, how do I only use this to rename the file? The below command doesn't work. The time shifting functionality isn't working on the rename.

Code: [Select]
$ exiftool '-testName<CreateDate-<${FileModifyDate;s/.+-(\d+):\d+/0000:00:00 $1:00:00/;}' IMG_1562.MP4
'IMG_1562.MP4' --> 'CreateDate-<0000:00:00 04:00:00'

Version: libimage-exiftool-perl/xenial,xenial,now 10.10-1

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2516
Re: Shift DateTimeOriginal by time extracted from filename
« Reply #5 on: April 20, 2019, 02:41:04 AM »
I've read in some other threads that MP4 files should stick to UTC dates.

The specs say that it should be in UTC time.  You should do what you want, just as long as it works correctly with the software you are using.  For example, if you're reading the timestamp through Windows, then it should be in UTC as Windows understands the spec and adjusts accordingly.  If you plan on using it with Google Photos, then you might want to think about changing it to the local time it was shot, so that way it appears correctly in Google Photos timeline (see here where I did some testing).

Quote
Now, since I shouldn't be changing any dates in the file, how do I only use this to rename the file?

Luckily for you, you don't need to try and correct the time yourself when it comes to the Quicktime UTC problem.  You just need to use the -api QuickTimeUTC option

If you run
exiftool -api QuickTimeUTC '-testname<CreateDate' IMG_1562.MP4
you should find the resulting time is adjusted to your local time zone.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.