Shift DateTimeOriginal by time extracted from filename

Started by jakwas, September 02, 2018, 09:01:11 PM

Previous topic - Next topic

jakwas

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.

Hayo Baan

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.
Quoteexiftool '-datetimeoriginal+=0000:00:00 00:00:33' 0000-00-00\ 00.00.33_2017-07-26\ 20.05.35\ M2U00024.MPG.JPG
works but
Quoteexiftool '-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
Quoteexiftool -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

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/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

jakwas


jason1365

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.

$ 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

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

$ 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

Quote from: jason1365 on April 20, 2019, 12:40:35 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).

QuoteNow, 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.
* 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).