Show DateTimeOriginal as local date with correct timezone mp4

Started by atiris, September 21, 2023, 10:45:44 AM

Previous topic - Next topic

atiris

Hi, can you please advise me how to show DateTimeOriginal metadata in local time + timezone for mp4 file? 
Exiftool: 16.65, OS: Synology linux, uname -r: 4.4.302+

Every other date works as I expected, except for DateTimeOriginal. Example:

Extract without any other parameters show correct file modification date time in local timezone and everything else in UTC. File name is date in UTC.
$exiftool -FileModifyDate -MediaCreateDate -TrackCreateDate -DateTimeOriginal IMG_20230903_144713.mp4
File Modification Date/Time     : 2023:09:03 16:47:13+02:00
Media Create Date               : 2023:09:03 14:47:13
Track Create Date               : 2023:09:03 14:47:13
Date/Time Original              : 2023:09:03 14:47:13

Next, if I want show everything in local timezone I am using -api QuickTimeUTC, but then result is:
$exiftool -FileModifyDate -MediaCreateDate -TrackCreateDate -DateTimeOriginal -api QuickTimeUTC IMG_20230903_144713.mp4
File Modification Date/Time     : 2023:09:03 16:47:13+02:00
Media Create Date               : 2023:09:03 16:47:13+02:00
Track Create Date               : 2023:09:03 16:47:13+02:00
Date/Time Original              : 2023:09:03 14:47:13

So, maybe it is ok and DateTimeOriginal is not "transfered" to local date time and stay in UTC, but if I use formatting, then original date time is displayed as in local timezone! (So, formatting changed date by 2 hours.) But it is not converted, only timezone is added to UTC time.

$exiftool -FileModifyDate -MediaCreateDate -TrackCreateDate -DateTimeOriginal -api QuickTimeUTC -dateFormat "%Y-%m-%d %H:%M:%S%z" IMG_20230903_144713.mp4
File Modification Date/Time     : 2023-09-03 16:47:13+0200
Media Create Date               : 2023-09-03 16:47:13+0200
Track Create Date               : 2023-09-03 16:47:13+0200
Date/Time Original              : 2023-09-03 14:47:13+0200

It is expected that formatting change date
I know that the timezone is not directly in the spec and the ExifTool uses OffsetTimeOriginal, however, if I know that the DateTimeOriginal is in UTC, can I use some switch to display it correctly with formatting?

I get correct date only if I update it first to include timezone, but my phone not including timezone by default :(

exiftool "-Quicktime:DateTimeOriginal=2023:09:03 16:47:13+02:00" "-Quicktime:CreationDate=2023:09:03 16:47:13+02:00" IMG_20230903_144713.mp4
exiftool -FileModifyDate -MediaCreateDate -TrackCreateDate -DateTimeOriginal -api QuickTimeUTC -dateFormat "%Y-%m-%d %H:%M:%S%z" IMG_20230903_144713.mp4
File Modification Date/Time     : 2023-09-03 16:47:13+0200
Media Create Date               : 2023-09-03 16:47:13+0200
Track Create Date               : 2023-09-03 16:47:13+0200
Date/Time Original              : 2023-09-03 16:47:13+0200

With the same commands there is no problem for jpg files. So how to extract it from mp4 with correct timezone without update it first? 
Thanks

StarGeek

See this post which has my standard copy/paste regarding video time stamps.  The tl;dr is that the DateTimeOriginal in videos is not a UTC time stamp but is supposed to be the local time with optional time zone.

Quote from: atiris on September 21, 2023, 10:45:44 AMSo, maybe it is ok and DateTimeOriginal is not "transfered" to local date time and stay in UTC, but if I use formatting, then original date time is displayed as in local timezone! (So, formatting changed date by 2 hours.) But it is not converted, only timezone is added to UTC time.

It looks like your video wrote the same time to the DateTimeOriginal as it did to the other date/time tags.  Since the DateTimeOriginal is not saved as UTC, when you format the time using the -d (-dateFormat) option and the %z variable, the date/time is not altered and because it does not include a time zone, exiftool is returning the local time zone as set by the computer.  See note #3 under Common Date Format Codes.

QuoteIt is expected that formatting change date
I know that the timezone is not directly in the spec and the ExifTool uses OffsetTimeOriginal, however, if I know that the DateTimeOriginal is in UTC, can I use some switch to display it correctly with formatting?

As I said, DateTimeOriginal is not in UTC.  The only time exiftool will use the various OffsetTime* tags to change anything is when creating the Composite:SubSec* tags (SubSecCreateDate, SubSecDateTimeOriginal, and SubSecModifyDate).  Also note that these tags will only use the time stamp from the corresponding EXIF tag.  See the Composite tags page.

QuoteI get correct date only if I update it first to include timezone, but my phone not including timezone by default :(
...
So how to extract it from mp4 with correct timezone without update it first?

The only thing you can do is fix the video DateTimeOriginal tag.  As long as the computer is in the correct time zone, you can copy directly from one of the other correct tags.  For example, if the FileModifyDate is correct, you can directly copy it with
exiftool "-Quicktime:DateTimeOriginal<FileModifyDate" /path/to/files/

Note that you don't need the -api QuickTimeUTC option here as the FileModifyDate tag will always have the time zone local to the computer. The file system time stamps are basically saved as UTC and adjusted to the local time zone except on some older file systems such as FAT32.

You can also copy directly from one of the other video tags, but in that case you will need to use the -api QuickTimeUTC option
exiftool -api QuickTimeUTC "-Quicktime:DateTimeOriginal<Quicktime:CreateDate" /path/to/files/

QuoteWith the same commands there is no problem for jpg files.

Jpegs save the data to different tags.  Use the command in FAQ #3 to see all the tags, including ones with duplicate names, and the locations of those tags.
* 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).

wywh

Maybe the .mp4 does not have timezone in that tag. You can write it without or with timezone:

exiftool -n -overwrite_original -api QuickTimeUTC=1 '-UserData:DateTimeOriginal=2001:06:01 12:00:00' a.mp4

exiftool -a -G1 -s -api QuickTimeUTC=1 -Time:All a.mp4                                                   
[QuickTime]     CreateDate                      : 2001:06:01 12:00:00+03:00
[UserData]      DateTimeOriginal                : 2001:06:01 12:00:00
[Keys]          CreationDate                    : 2001:06:01 12:00:00+03:00
[XMP-exif]      DateTimeOriginal                : 2001:06:01 12:00:00

exiftool -overwrite_original -api QuickTimeUTC=1 '-UserData:DateTimeOriginal=2001:06:01 12:00:00' a.mp4

exiftool -a -G1 -s -api QuickTimeUTC=1 -Time:All a.mp4                                                 
[QuickTime]     CreateDate                      : 2001:06:01 12:00:00+03:00
[UserData]      DateTimeOriginal                : 2001:06:01 12:00:00+03:00
[Keys]          CreationDate                    : 2001:06:01 12:00:00+03:00
[XMP-exif]      DateTimeOriginal                : 2001:06:01 12:00:00

- Matti

atiris

Ah, so the problem is that I assumed that if a date has no timezone, it's automatically in UTC, but that's not true with DateTimeOriginal. Ok, in that case the expected value is in local time and if I see it without timezone and it is in UTC then this is a bug in the media metadata.

OK thanks a lot.

StarGeek

Pretty much, yes.

This was common with older DSLR cameras, as they are not necessarily aware of the current time zone, unlike phones which are aware of the 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).

Alan Clifford

Quote from: atiris on September 21, 2023, 10:45:44 AMI know that the timezone is not directly in the spec and the ExifTool uses OffsetTimeOriginal

That is correct for exif.  This datetimeoriginal is probably xmp or quicktime.