I have a directory containing many .jpg and .mov files.
Every .jpg has a DateTimeOriginal exactly three hours more than FileModifyDate and a GPSDateTime exactly eight hours more than FileModifyDate.
But every .mov has neither DateTimeOriginal nor GPSDateTime.
To support future work with these files, I'd like to make them all consistent. After studying the man page for a while, I tried
exiftool '-DateTimeOriginal<FileModifyDate 03:00' \
'-GPSDateTime<FileModifyDate 08:00' *.MOV
but I got an error message saying I must use = instead of < So I tried
exiftool '-DateTimeOriginal=FileModifyDate 03:00' \
'-GPSDateTime=FileModifyDate 08:00' *.MOV
and got another message:
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][ /-HH:MM|Z]) in ExifIFD:DateTimeOriginal (PrintConvInv)
which implies I have to do each tag with a literal time instead of computing from another.
I see that I can copy one tag to another and afterward use = or -= to change it in another step. But is there a way to do it in one command?
CodePudding user response:
First the answer, but see below for some possible complications.
If the time shift was the same for both values, then you would use the GlobalTimeShift
option, but since that is not the case, you need to use the ShiftTime
helper function.
Additionally, the GPSDateTime
tag in a MOV file is going to be an XMP tag (specifically in the XMP-exif
group) which allows for the inclusion of a time zone and does not need to be set to UTC. Since the FileModifyDate
already includes a time zone and it looks like you want to shift it to UTC, you will have to strip away the time zone. You can do this by either using the -d
(-dateFormat
) option, which will set the date format globally, or the DateFmt
helper function, which will work on individual tags. A Perl regex substitution would also be an option, but for this example, I'll use the DateFmt
option.
Your command would be
exiftool '-DateTimeOriginal<${FileModifyDate;ShiftTime("3")}' '-GPSDateTime<${FileModifyDate;ShiftTime("8");DateFmt("%Y:%m:%d %H:%M:%S")}' *.MOV
For the ShiftTime
function, you only need to list the hours to be shifted as this is the default in a tag that includes both date and time. See the ExifTool Date/Time Shift Module for details.
Now, there are some problems with the way you are writing this data. In a MOV file, exiftool will include a time zone in the DateTimeOriginal
tag unless forced not to. If the time zone isn't included, then exiftool will default to the local time zone of the computer. So if the local time zone isn't the one that would apply to your shifted DateTimeOriginal
time, then you will need to include it. The change in the above command would be
'-DateTimeOriginal<${FileModifyDate;ShiftTime("3")}±##:00'
While the specs say that the DateTimeOriginal
tag in a video file does not need to include a time zone, if the time zone isn't included then Apple programs will display wildly inaccurate date/times (see this Exiftool forum thread).
Exiftool will also write to the XMP-exif:DateTimeOriginal
tag in addition to the Quicktime tag.
For the GPSDateTime
, there might be a better way to write that, if the file's other time stamps are accurate. In a video file, the CreateDate
is supposed to be set to UTC. If that tag is correctly set, it would be easier to set the GPSDateTime
like this
'-GPSDateTime<CreateDate'
It should be noted that Quicktime:DateTimeOriginal
is not commonly read by most programs, the Apple photo app being an exception. Also, XMP tags in video files, in this case XMP-exif:DateTimeOriginal
and XMP-exif:GPSDateTime
, are usually not used by most programs, with Adobe programs being the exception. The Quicktime:CreateDate
is the most widely used tag and since it is supposed to be in UTC, it also works for GPS date/time.
To break down why your original command didn't work, in the first case, you added a static string to the name of the tag. This caused exiftool to treat the whole thing as a string, which is why it told you to use an equal sign =
instead of the greater/less than signs <
/>
and the greater/less than signs are only used when copying tags. When you changed it to the equal sign, you were now writing a static string and since the DateTimeOriginal
tag requires a date/time format, you receive the Invalid date/time
error.
When combining a tag name with a static string, you need to prefix the tag name with the dollar sign. See the paragraph starting "A powerful redirection feature" under the -TagsFromFile
option for details.