ExifTool Forum

ExifTool => Newbies => Topic started by: metalhead on November 06, 2019, 09:14:38 PM

Title: Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration
Post by: metalhead on November 06, 2019, 09:14:38 PM
Ultimately, I'm trying to set the FileModifyDate (of an MP4 file) to be the value of the Quicktime:CreateDate tag plus the value of the Quicktime:MediaDuration tag.  However, before I attempt that, I'm having trouble working out how to evaluate that value!

exiftool -G1 -a -MediaDuration -MediaCreateDate -s -api QuickTimeUTC ".\x.mp4"
[Track1]        MediaDuration                   : 0:16:35
[Track2]        MediaDuration                   : 0:16:35
[Track1]        MediaCreateDate                 : 2014:11:02 14:23:02+00:00
[Track2]        MediaCreateDate                 : 2014:11:02 14:23:02+00:00


Now, I'm probably going the wrong way about getting the value I need, but this is what I've got so far:

I get the correct value with the duration hardcoded in this command:
exiftool -api QuickTimeUTC -p "${Quicktime:MediaCreateDate;ShiftTime('0:0:0 0:16:35')}" ".\x.mp4"
2014:11:02 14:39:37+00:00

This command programatically outputs the hardcoded value (above) that the ShiftTime helper requires:
exiftool -p "0:0:0 "${Quicktime:MediaDuration} ".\x.mp4"
0:0:0 0:16:35

But if I try combining those two commands, it doesn't output the correct value.  I'm obviously doing something wrong:
exiftool -api QuickTimeUTC -p "${Quicktime:MediaCreateDate;ShiftTime('0:0:0 ${Quicktime:MediaDuration}')}" ".\x.mp4"
2014:11:02 14:23:02+00:00

Any help appreciated!
Title: Re: Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration
Post by: StarGeek on November 06, 2019, 10:33:26 PM
You can't access another tag from inside a tag in that way.  I haven't tested this, but try:
exiftool -api QuickTimeUTC -p "${Quicktime:MediaCreateDate;ShiftTime('0:0:0 '.$self->GetValue('MediaDuration'))}" ".\x.mp4"
Title: Re: Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration
Post by: Phil Harvey on November 07, 2019, 07:29:10 AM
Quote from: StarGeek on November 06, 2019, 10:33:26 PM
You can't access another tag from inside a tag in that way.

Yes.  It would be nice if this could be allowed, but differentiating between Perl variables and tag-name variables in an arbitrary Perl expression would be difficult.

Calling $self->GetValue() is the way to do it as StarGeek mentioned, but you want the ValueConv value which is the numerical seconds: $self->GetValue('MediaDuration',ValueConv=>1)

- Phil
Title: Re: Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration
Post by: metalhead on November 07, 2019, 09:37:20 AM
Quote from: StarGeek on November 06, 2019, 10:33:26 PM
You can't access another tag from inside a tag in that way.  I haven't tested this, but try:
exiftool -api QuickTimeUTC -p "${Quicktime:MediaCreateDate;ShiftTime('0:0:0 '.$self->GetValue('MediaDuration'))}" ".\x.mp4"

Thanks StarGeek, that does work.

2014:11:02 14:39:37+00:00

So, I was hoping the following command would set FileModifyDate, but it doesn't.
exiftool -api QuickTimeUTC -FileModifyDate="${Quicktime:MediaCreateDate;ShiftTime('0:0:0 '.$self->GetValue('MediaDuration'))}" -P ".\x.mp4"
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in File:FileModifyDate (PrintConvInv)
Nothing to do.


I was wondering if I need to explicitly declare the formatting or something, similar to the following (obviously without the hardcoded timestamp):
exiftool -api QuickTimeUTC -FileModifyDate="${'2014:11:02 14:39:37+00:00';DateFmt('%Y:%m:%d %H:%M:%SZ')}" -P ".\x.mp4"
FWIW, the above does actually work, but I was getting errors when trying various syntax when trying to do it without hardcoding.
Title: Re: Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration
Post by: metalhead on November 07, 2019, 09:37:52 AM
Quote from: Phil Harvey on November 07, 2019, 07:29:10 AM
Quote from: StarGeek on November 06, 2019, 10:33:26 PM
You can't access another tag from inside a tag in that way.

Yes.  It would be nice if this could be allowed, but differentiating between Perl variables and tag-name variables in an arbitrary Perl expression would be difficult.

Calling $self->GetValue() is the way to do it as StarGeek mentioned, but you want the ValueConv value which is the numerical seconds: $self->GetValue('MediaDuration',ValueConv=>1)

- Phil

Thank Phil, although I'm not sure I understand... Swapping that out in StarGeek's command gives the wrong value:
exiftool -api QuickTimeUTC -p "${Quicktime:MediaCreateDate;ShiftTime('0:0:0 '.$self->GetValue('MediaDuration',ValueConv=>1))}" ".\x.mp4"
2014:12:14 01:19:40+00:00

Or do you mean that when it comes to my goal of using the value to set FileModifyDate I need to set it using numerial seconds, instead of the output/format from StarGeek's command?
Title: Re: Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration
Post by: Phil Harvey on November 07, 2019, 09:50:30 AM
Sorry, I meant this:

exiftool -api QuickTimeUTC -p "${Quicktime:MediaCreateDate;ShiftTime('0:0:0 0:0:'.$self->GetValue('MediaDuration',ValueConv=>1))}" ".\x.mp4"

(you need to add a leading '0:0:' before the seconds)

Due to the variable format of MediaDuration, your other command will only work if the duration is between 30 seconds and 24 hours, when the format is HH:MM:SS.

- Phil
Title: Re: Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration
Post by: Phil Harvey on November 07, 2019, 09:53:49 AM
Quote from: metalhead on November 07, 2019, 09:37:20 AM
So, I was hoping the following command would set FileModifyDate, but it doesn't.
exiftool -api QuickTimeUTC -FileModifyDate="${Quicktime:MediaCreateDate;ShiftTime('0:0:0 '.$self->GetValue('MediaDuration'))}" -P ".\x.mp4"

This is common mistake 5c (https://exiftool.org/mistakes.html#M5).

- Phil
Title: Re: Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration
Post by: StarGeek on November 07, 2019, 10:35:00 AM
Quote from: Phil Harvey on November 07, 2019, 09:50:30 AM
Due to the variable format of MediaDuration, your other command will only work if the duration is between 30 seconds and 24 hours, when the format is HH:MM:SS.

Ah, yes, I see exactly the problem with my command now that you brought it up.
Title: Re: Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration
Post by: metalhead on November 10, 2019, 09:06:48 AM
Quote from: Phil Harvey on November 07, 2019, 09:53:49 AM
Quote from: metalhead on November 07, 2019, 09:37:20 AM
So, I was hoping the following command would set FileModifyDate, but it doesn't.
exiftool -api QuickTimeUTC -FileModifyDate="${Quicktime:MediaCreateDate;ShiftTime('0:0:0 '.$self->GetValue('MediaDuration'))}" -P ".\x.mp4"

This is common mistake 5c (https://exiftool.org/mistakes.html#M5).

- Phil

Thanks again Phil.  So the following command does what I want  :):
exiftool -api QuickTimeUTC "-FileModifyDate<${MediaCreateDate;ShiftTime('0:0:0 0:0:'.$self->GetValue('MediaDuration',ValueConv=>1))}" -P ".\x.mp4"