Setting FileModifyDate as Quicktime:CreateDate + Quicktime:MediaDuration

Started by metalhead, November 06, 2019, 09:14:38 PM

Previous topic - Next topic

metalhead

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!

StarGeek

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"
* 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).

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

metalhead

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.

metalhead

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?

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

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.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

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.
* 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).

metalhead

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.

- 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"