ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: grasdk on August 13, 2024, 06:47:15 PM

Title: Setting Dates and Timezone offsets on files with varying sources
Post by: grasdk on August 13, 2024, 06:47:15 PM
Hi

I'm trying to set these two XMP timestamp tags on mp4 and mov files, from the available info in the files. If I am not mistaken, the principles apply to images as well, though the metadata on images are typically better and more complete than on videos.

Desired value is highlighted
[XMP:XMP-photoshop:Time] Date Created: UTC Timestamp with Z appended
[XMP:XMP-exif:Time] Date/Time Original: Local Timestamp + offset

I have the following sources with available info highlighted:


Filenames can have different formats, but all the kind that exiftool parses... For example PXL_YYYYMMDD_hhmmss, IMG_YYYYMMDDhhmmss or even just YYYY-MM-DD-hh-mm-ss).

For source 1-3 there is enough info present. I have GPS (in one case), UTC time and/or localtime and from that I can calculate an offset. For source 4 I would have to resort to some assumption about offset.

I have pieced together these commands per source (only an idea for the fourth for now):


Any comments and improvements on the above are welcome. But here comes the real questions:

The sources above will change over time, some new scenarios will show up. For example a pixel phone photo with gps disabled (oops, there is a problem already with the command). So I want to combine these commands and more into a robust single command that uses the best data available. Something in the lines of (just setting DateTimeOriginal for simplicity):

$ exiftool -config TimezoneLookUp.config -ee '-XMP:DateTimeOriginal<${Filename;s/.*(\d{4}).*(\d\d).*(\d\d).*(\d\d).*(\d\d).*(\d\d).*/$1:$2:$3 $4:$5:$6/;$_.=TimeZoneString(int((GetUnixTime($_)-GetUnixTime($self->GetValue("CreateDate")))/1800+0.5)*30)}' '-XMP:DateTimeOriginal<${QuickTime:CreationDate}' '-XMP:DateCreated<${QuickTime:Createdate;my $offset=$self->GetValue("GoogleLookUpTimeZone");ShiftTime($offset)}+$GoogleLookUpTimeZone' -@ videofiles.txt

I'm trying to leverage that the last assignment that is with a defined value is the highest priority, so I can set the timestamp from any of the sources (and add more, e.g. when only local timestamp is available) in a prioritized  manner.

With the few tests I've tried it seems to use the priority correctly, but when used on the different source files I get warnings:

Source 1:
Warning: Day '70' out of range 1..31 for 'Filename' - PXL3_20240812_170019137.mp4
Warning: [minor] Tag 'QuickTime:CreationDate' not defined - PXL3_20240812_170019137.mp4

Source 2:
Warning: Use of uninitialized value in subtraction (-) for 'Filename' - IMG_0105.MOV
Warning: Use of uninitialized value $shift in concatenation (.) or string for 'QuickTime:Createdate' - IMG_0105.MOV

Source 3
Warning: [minor] Tag 'QuickTime:CreationDate' not defined - oneplus_20240813_103754.mp4
Warning: Use of uninitialized value $shift in concatenation (.) or string for 'QuickTime:Createdate' - oneplus_20240813_103754.mp4

The first warning for source 1, is something about my matchers and the extended file-name timestamp with subsecs included. I could probably add group of 0-3 integers or something for that... but how do I get rid of the "initialized shift value" error on source 2 and 3 (because google timestamp is not defined in the absence of gps coords) and the file name error on source 2 (because filenames are not a date) and the 'the tag not defined 'error on source 1 and 3? (because spurce 3 has no tag). Or can I safely ignore them?

Thanks for reading and commenting. :)

PS: When you do things like exiftool -alldates<filename some internal parsing of filename goes on. Is there a way to use this instead of the huge regex in my command for source 3?