简体   繁体   English

exiftool——通过添加/减去另一个标签来编写一个标签

[英]exiftool—writing one tag by adding/subtracting from another

I have a directory containing many.jpg and.mov files.我有一个包含许多.jpg 和.mov 文件的目录。

Every.jpg has a DateTimeOriginal exactly three hours more than FileModifyDate and a GPSDateTime exactly eight hours more than FileModifyDate. Every.jpg 的 DateTimeOriginal 比FileModifyDate多三个小时,而 GPSDateTime 比FileModifyDate多八小时。

But every.mov has neither DateTimeOriginal nor GPSDateTime.但是 every.mov 既没有 DateTimeOriginal 也没有 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?但是有没有办法在一个命令中完成呢?

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 .如果两个值的时移相同,那么您将使用GlobalTimeShift选项,但由于情况并非如此,您需要使用ShiftTime助手 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.此外,MOV 文件中的GPSDateTime标签将是一个 XMP 标签(特别是在XMP-exif组中),它允许包含时区并且不需要设置为 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.由于FileModifyDate已经包含一个时区,而且您似乎想将其转换为 UTC,因此您必须去掉时区。 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.您可以使用-d ( -dateFormat ) 选项(它将全局设置日期格式)或DateFmt帮助程序 function来执行此操作,该选项将对单个标签起作用。 A Perl regex substitution would also be an option, but for this example, I'll use the DateFmt option. Perl 正则表达式替换也是一个选项,但对于此示例,我将使用DateFmt选项。

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.对于ShiftTime function,您只需列出要轮班的小时数,因为这是包含日期和时间的标签中的默认值。 See the ExifTool Date/Time Shift Module for details.有关详细信息,请参阅ExifTool 日期/时间偏移模块

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.在 MOV 文件中,exiftool 将在DateTimeOriginal标签中包含一个时区,除非强制不这样做。 If the time zone isn't included, then exiftool will default to the local time zone of the computer.如果不包括时区,则 exiftool 将默认为计算机的本地时区。 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.因此,如果本地时区不是适用于您的偏移DateTimeOriginal时间的时区,那么您将需要包括它。 You would now also have to strip away the time zone as above.您现在还必须像上面那样去掉时区。 The change in the above command would be上述命令的变化是

'-DateTimeOriginal<${FileModifyDate;ShiftTime("3");DateFmt("%Y:%m:%d %H:%M:%S")}}±##:00'

Also, if removing the time zone from both tag copy operations, you could switch to using the -d option.此外,如果从两个标签复制操作中删除时区,您可以切换到使用-d选项。

exiftool -d '%Y:%m:%d %H:%M:%S' '-DateTimeOriginal<${FileModifyDate;ShiftTime("3")}' '-GPSDateTime<${FileModifyDate;ShiftTime("8")}' *.MOV

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 ).虽然规范说视频文件中的DateTimeOriginal标签不需要包含时区,但如果不包含时区,Apple 程序将显示非常不准确的日期/时间(请参阅此 Exiftool 论坛主题)。

Exiftool will also write to the XMP-exif:DateTimeOriginal tag in addition to the Quicktime tag.除了 Quicktime 标签之外,Exiftool 还将写入XMP-exif:DateTimeOriginal标签。

For the GPSDateTime , there might be a better way to write that, if the file's other time stamps are accurate.对于GPSDateTime ,如果文件的其他时间戳是准确的,可能有更好的写法。 In a video file, the CreateDate is supposed to be set to UTC.在视频文件中, CreateDate应该设置为 UTC。 If that tag is correctly set, it would be easier to set the GPSDateTime like this如果该标签设置正确,那么像这样设置GPSDateTime会更容易

'-GPSDateTime<CreateDate'

It should be noted that Quicktime:DateTimeOriginal is not commonly read by most programs, the Apple photo app being an exception.应该注意的是, Quicktime:DateTimeOriginal并不被大多数程序读取,Apple 照片应用程序是一个例外。 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.此外,视频文件中的 XMP 标签(在本例中XMP-exif:DateTimeOriginalXMP-exif:GPSDateTime )通常不会被大多数程序使用,Adobe 程序除外。 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. Quicktime:CreateDate是使用最广泛的标签,因为它应该使用 UTC,所以它也适用于 GPS 日期/时间。

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.为了分析为什么您的原始命令不起作用,在第一种情况下,您在标签名称中添加了一个 static 字符串。 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.这导致 exiftool 将整个事物视为一个字符串,这就是为什么它告诉您使用等号=而不是大于/小于符号< / > ,并且大于/小于符号仅在复制标签时使用。 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.当您将其更改为等号时,您现在正在编写一个 static 字符串,并且由于DateTimeOriginal标记需要日期/时间格式,您会收到Invalid date/time错误。

When combining a tag name with a static string, you need to prefix the tag name with the dollar sign.将标签名称与 static 字符串组合时,您需要在标签名称前加上美元符号。 See the paragraph starting "A powerful redirection feature" under the -TagsFromFile option for details.有关详细信息,请参阅-TagsFromFile选项下以“强大的重定向功能”开头的段落。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ANSI DATETIME上的无效操作(在Teradata中将一个时间戳减去另一个时间戳) - Invalid Operation On An ANSI DATETIME (Subtracting one timestamp from another in Teradata) 从另一个JavaScript减去一次时的前导零 - Leading zero when subtracting one time from another javascript 是否可以保证从DATETIME添加或减去的天数是多少? - Is Adding or Subtracting From a DATETIME Guaranteed to be Number of Days? JavaScriptSerializer从日期减去一天 - JavaScriptSerializer is subtracting one day from date 通过在php中从当前时间添加或减去它来随机化时间 - Randomize timing by either adding or subtracting it from current time in php 从时间戳列中添加和减去秒列 pandas - Adding and subtracting seconds column from timestamp column pandas 在仅日期中添加天数,然后从c#中的日期中减去它 - Adding days to only date and then subtracting it from date in c# 从通用或本地DateTime添加/减去的最佳实践 - Best practice for adding/subtracting from universal or local DateTime 从 Java 日期添加/减去 5 秒 - 显示已弃用的警告 - Adding/Subtracting 5 seconds from Java Date - Showing deprected warning 从存储在另一个动态变量中的日期中减去动态值 - Subtracting dynamic value from date stored in another dynamic variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM