Is it possible to calculate with the duration tag?

Started by karlgustavv, June 12, 2016, 03:14:23 AM

Previous topic - Next topic

karlgustavv

Is there a way to use the time stored in the duration tag for calculation?

I want the creation date (or any other date) of movie files to be set at the beginning time of the recording. Some devices set all dates at the time the recording stops.

An easy solution would be to subtract the duration from the creation date:
exiftool "-FileModifyDate<${Createdate}Z - ${Duration}" *.mp4

This command sets FileModifyDate to CreateDate but it would be great if could do the calculation, too

Phil Harvey

In general, you should create a user-defined Composite tag to do this, but a quick-n-dirty and sneaky method would be this:

exiftool "-filemodifydate<${createdate;Image::ExifTool::ShiftTime($_,'0:0:'.$self->GetValue('Duration','ValueConv'),-1)}Z" -ext mp4 .

- 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 ($).

karlgustavv

Thank you for that fast answer.

Are there any restrictions on how short or long "duration" might be?

Phil Harvey

...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 ($).

Clindor

Hello,

I'm interesting in doing the exact same thing, except that in my case I would like to replace the date of the 'FileModifyDate' tag by the SUM of the value of the "Duration" tag to the 'CreationDate' tag. (So an addition instead of a substraction, but anyway...)

I copy the same command as the one Phil suggested, but it only replaces the 'FileModifyDate' tag by the 'CreationDate' with NO consideration to the 'Duration' (which is supposed to be larger than 2 minutes). What could probably go wrong?

Phil Harvey

What is the output of this command?:

exiftool -p "$createdate,$duration#,${createdate;Image::ExifTool::ShiftTime($_,'0:0:'.$self->GetValue('Duration','ValueConv'),-1)}Z" FILE

- 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 ($).

Clindor

Wow thanks for the quick answer  :)

Hum.. Unfortunately this time, no modification at all is made on the Modification Date, but I get an answer inside the Window cmd which looks a bit like this:

2019:08:23 16:59:47-07:00 (~CreationDate),120.663333333333 (I don't know what this might be),2019:08:23 16:57:46-07:00 (=CreationDate - Duration) Z

Phil Harvey

The command I gave printed out the unmodified CreateDate, Duration in seconds, and the shifted CreateDate.

So the shifted CreateDate is correct, and this should work for you:

exiftool "-filemodifydate<${createdate;Image::ExifTool::ShiftTime($_,'0:0:'.$self->GetValue('Duration','ValueConv'),-1)}Z" FILE

So, after running this command, what is the new FileModifyDate?:

exiftool -filemodifydate FILE

- 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 ($).

Clindor

I re-tried it several times this morning and after several inconclusive tests ... it finally WORKED!
So thanks a lot Phil!!  :D (I don't know what I did wrong the other times  :-\ but whatever..)

If I may ask an extra question: because it was a video made during a trip, there also is a time difference regarding the hours (the result displayed is 2 hours late compared to the "real" time the video was made on location) that can easily be rectified with the instruction:

"-FileModifyDate-=02:00"

So by putting the 2 instructions together I might get the correct result:

ExifTool "-FileModifyDate<${CreationDate;Image::ExifTool::ShiftTime($_,'0:0:'.$self->GetValue('Duration','ValueConv'),+1)}Z" "-FileModifyDate-=02:00" FILE

And it DOES work.. But is there a way to combine the 2 instructions into one? (or is it more safe to keep them separated?)

Phil Harvey

Your combined command won't work because the second assignment will override the first.  Instead, try this:

exiftool "-FileModifyDate<${CreationDate;Image::ExifTool::ShiftTime($_,'2:0:'.$self->GetValue('Duration','ValueConv'),+1)}Z" FILE

Also, if things are working intermittently for you, it is likely you are cutting and pasting commands and using fancy quotation marks (like "" in your combined command instead of "").

- 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 ($).

Clindor

#10
(Thank you for the tip with the "" instead of ""! I think there were other errors on my end, but I might as well put extra care on this specific matter)

Hum.. Unfortunately this arranged command doesn't work the way it is supposed to...  :-\ Instead of correct rectifying the 2 hours late, the execution of this command adds 2 extra hours late..

So I put "-2" instead of "2" in your command Phil, unfortunately this time neither the rectification of the time difference, or the calculation with the duration happens

So I don't know..

Phil Harvey

Ah.  The 2 hour shift is in the opposite direction to the duration.  OK, try this:

exiftool "-FileModifyDate<${CreationDate;ShiftTime('0:0:'.$self->GetValue('Duration','ValueConv'));ShiftTime('-2')}Z" FILE

There may be an easier way, but this was the obvious thing to try.  (Also, I have removed the unnecessary "Image::ExifTool::" since this is the default namespace anyway, and used the new simplified method of calling ShiftTime.)

- 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 ($).

Clindor

#12
You got it!! I'm not fully understanding the command or how it works.. but it WORKS!  ;D ;D ;D

So thank you, the result really is the one expected  :)

EDIT: Oh you simplified it! Now it's clear  :)