ExifTool Forum

ExifTool => Newbies => Topic started by: somy on July 18, 2019, 07:58:35 AM

Title: Write a tag only when the tag doesn't exist?
Post by: somy on July 18, 2019, 07:58:35 AM
Hi all,

Can I instruct ExifTool to write to a timestamp tag when and only when the value of that tag doesn't exist?
I'd like to copy createdate to datetimeoriginal (and convert to local timestamp) only when the datetimeoriginal doesn't exist in MP4 container:
-datetimeoriginal<quicktime:createdate
In the same command I also need to copy some other values so I can't run this as a separate command. I saw some posts on string values, but not able to find anything for timestamp.
Any suggestion?


Title: Re: Write a tag only when the tag doesn't exist?
Post by: Phil Harvey on July 18, 2019, 08:20:50 AM
This is a bit tricky to do for a single tag in a command where you are doing other things, but it can be done with an advanced formatting expression, like this:

exiftool "-datetimeoriginal<${quicktime:createdate;$_ = undef if $self->GetValue('DateTimeOriginal')}" ...

- Phil
Title: Re: Write a tag only when the tag doesn't exist?
Post by: somy on July 18, 2019, 09:45:22 AM
Quote from: Phil Harvey on July 18, 2019, 08:20:50 AM
This is a bit tricky to do for a single tag in a command where you are doing other things, but it can be done with an advanced formatting expression, like this:

exiftool "-datetimeoriginal<${quicktime:createdate;$_ = undef if $self->GetValue('DateTimeOriginal')}" ...

- Phil
Wow - that magic works!!
Thanks a lot!
Title: Re: Write a tag only when the tag doesn't exist?
Post by: somy on July 19, 2019, 12:56:30 PM
Quote from: Phil Harvey on July 18, 2019, 08:20:50 AM
This is a bit tricky to do for a single tag in a command where you are doing other things, but it can be done with an advanced formatting expression, like this:

exiftool "-datetimeoriginal<${quicktime:createdate;$_ = undef if $self->GetValue('DateTimeOriginal')}" ...

- Phil
Hi Phil,

Hope you don't mind another question. How does the flag QuickTimeUTC work? It reads from CreateDate and adjust to local time with time zone from the mp4 file or from the computer where the command is run?  I'm asking because some of my videos were taken from different time zones, thanks in adavvance!
Title: Re: Write a tag only when the tag doesn't exist?
Post by: Phil Harvey on July 19, 2019, 02:23:12 PM
For the tags noted in the QuickTime tags documentation, the QuickTimeUTC option assumes that the time is stored as seconds since the epoch in UTC, and will convert to/from local time (or whatever time zone you specifiy) when writing and reading.

- Phil
Title: Re: Write a tag only when the tag doesn't exist?
Post by: somy on July 19, 2019, 02:29:20 PM
Quote from: Phil Harvey on July 19, 2019, 02:23:12 PM
For the tags noted in the QuickTime tags documentation, the QuickTimeUTC option assumes that the time is stored as seconds since the epoch in UTC, and will convert to/from local time (or whatever time zone you specifiy) when writing and reading.

- Phil
Thanks for your reply!
How can I specify time zone and what time zone will Exiftool use if I don't specify time zone (MP4 doesn't seem to have a tag for time zone). 
Title: Re: Write a tag only when the tag doesn't exist?
Post by: Hayo Baan on July 19, 2019, 04:09:38 PM
On Linux/Mac it's as simple as setting the TZ environment variable to the correct value. On Windows I'm not sure this works, but perhaps it does.
Title: Re: Write a tag only when the tag doesn't exist?
Post by: somy on July 20, 2019, 09:13:53 AM
Quote from: Hayo Baan on July 19, 2019, 04:09:38 PM
On Linux/Mac it's as simple as setting the TZ environment variable to the correct value. On Windows I'm not sure this works, but perhaps it does.
Thank you. I ask because I have some MP4 videos captured in another time zone, and I'd like to change timestamps to local. Currently it has the following values:

[QuickTime]     CreateDate                      : 2013:03:29 12:04:49
[XMP-exif]      DateTimeOriginal                : 2013:03:29 14:04:49+02:00

I'd like to change to DateTimeOriginal UTC+7:00:

[QuickTime]     CreateDate                      : 2013:03:29 12:04:49
[XMP-exif]      DateTimeOriginal                : 2013:03:29 19:04:49+07:00

There are many videos so would be nice to do it with on command. Any suggestion?
Title: Re: Write a tag only when the tag doesn't exist?
Post by: Hayo Baan on July 21, 2019, 05:41:26 AM
You are not using -api QuickTimeUTC=1 so exiftool is assuming that QuickTime:CreateDate is the local time when you shot the image, but it looks like you actually want exiftool to interpret the time as UTC, for that to happen append -api QuickTimeUTC=1 to the command. Then to get the XMP-exif DateTimeOriginal to be correct, temporarily set your timezone to the one you want e.g. "Asia/Jakarta" and then run the exiftool command to update the DateTimeOriginal.
TZ="Asia/Jakarta" exiftool -api QuickTimeUTC=1 "-XMP-exif:DateTimeOriginal<QuickTime:CreateDate" FILESorDIRs

Unexpectantly, you can not simply set TZ to "+07:00" since that makes the timezone "-07:00" :o (TZ="-07:00" sets it to "+07:00"), so better stick with the named timezones I think.

Above commands are for Mac/linux, on Windows setting TZ might work too (but would then certainly need to be on a separate line).
Title: Re: Write a tag only when the tag doesn't exist?
Post by: somy on July 22, 2019, 05:42:49 AM
Quote from: Hayo Baan on July 21, 2019, 05:41:26 AM
You are not using -api QuickTimeUTC=1 so exiftool is assuming that QuickTime:CreateDate is the local time when you shot the image, but it looks like you actually want exiftool to interpret the time as UTC, for that to happen append -api QuickTimeUTC=1 to the command. Then to get the XMP-exif DateTimeOriginal to be correct, temporarily set your timezone to the one you want e.g. "Asia/Jakarta" and then run the exiftool command to update the DateTimeOriginal.
TZ="Asia/Jakarta" exiftool -api QuickTimeUTC=1 "-XMP-exif:DateTimeOriginal<QuickTime:CreateDate" FILESorDIRs

Unexpectantly, you can not simply set TZ to "+07:00" since that makes the timezone "-07:00" :o (TZ="-07:00" sets it to "+07:00"), so better stick with the named timezones I think.

Above commands are for Mac/linux, on Windows setting TZ might work too (but would then certainly need to be on a separate line).
Thanks a lot for the help!