Subtract file video length from Date Modified

Started by Simmo1985, November 15, 2015, 05:22:57 PM

Previous topic - Next topic

Simmo1985

Hi,

I'm trying to find a way to subtract the video length value from the Date Modified tag. I want the result of that equation to then become the new Date Created tag.

The video files are. ASF, MP4, MOV.

Example - Original video file:
Date modified: 16/11/2015 12:32:45pm
Video length: 00:02:30
Date created is therefore made to be: 16/11/2015 12:30:15pm

Thanks

Phil Harvey

The trick here is getting the duration in the proper format to use as a time shift.  This should work:

exiftool "-xmp:datecreated-<0:0:${duration#}" FILE

The extra 0:0 are the hours and minutes, and ${duration#} formats the duration in seconds.

This should work for MP4 and MOV videos provided DateCreated and Duration exist, but ExifTool doesn't yet write ASF files.

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


tgji

Hi everyone. This doesn't seem to work for me now in 2022, on MacOS (M1 Pro MacBook).

For a specific file that I want to move back by it's duration of 4 min and 30 seconds, I can get the following to work:

exiftool '-AllDates-=0:0:270' FILE

However, when I try to replace the 270 with ${duration#}, nothing happens.

I've also tried a few variations, such as: $duration# and
${duration} and duration#... nothing seems to work. I'm novice with Terminal and new to exiftool, so I don't quite understand the role of the $ or the
{}, and a few google searches didn't help me much (I may be in over my head).

I would love to figure out the "duration" method though as I would like to batch this with 100's of videos from an old camera.

Any help would be greatly appreciated!

StarGeek

#4
Did you check for the existence of a Duration tag?

Are you using double quotes as in the example or single quotes.  Since you mention Terminal, I'm guess you're using a Mac (silly me, you said you're using a Mac).  If so, as it says at the bottom of Phil's post

    On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

When copying tags you need to use < instead of =.  (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 ($).

tgji

#6
To StarGeek:

When I try exiftool MOV_0002.mp4 (using a different file than my original post) I see several fields with the word "duration", and when I do this: exiftool -duration  MOV_0002.mp4 I get: Duration : 0:00:40 and when I add the # I get: Duration : 40.04 — which are the expected results.

And yes I am using single quotes as I did notice that in Phil's signature.

To Phil:

I changed the = to a < resulting in this command: exiftool 'AllDates-<0:0:${duration#}' MOV_0002.mp4

but it returns:

Error: File not found - AllDates-<0:0:${duration#}, then it shows the metadata for that file.

I feel like I am missing something really simple!

UPDATE:

oops — I forgot a singular - at the beginning of the command... changing it to: exiftool '-AllDates-<0:0:${duration#}' MOV_0002.mp4 worked!

Thank you!