Change time in movie files by amount equal to duration of the video

Started by gheppell, May 01, 2020, 03:54:57 PM

Previous topic - Next topic

gheppell

Hello is there a way to move/change and given date (exif or quicktime) by an amount equal to the length of the video?  For context, most of my old video cameras date video at the end of the clip as opposed to the beginning, where I would like the file to be dated.  I can manually change each one by doing the math myself an entering the new time but this is cumbersome.  I would like to run a exiftool command, either on its own, or as part of a batch file to make this change. 

For example:  I start a video at 6 pm on Christmas day of last year that lasts 10 minutes.  Depending on the camera, it will be dated either as 2019:12:25 18:00:00 or 2019:12:25 18:10:00.  To the extent it is the latter, I would like to be able to change it to the former.

something like -createdate-={Duration}  where I don't have a clue what actually goes in the brackets.

Thank you.

StarGeek

I actually have to do that with some videos and live streams I download with Youtube-DL. 
exiftool "-createdate<${createdate;ShiftTime('-0:0:'.$self->GetValue('Duration','ValueConv'))}" /path/to/files/

You'll have to manually decide if it needs to be altered, though.  Or if you can find a tag to differentiate between the files that need to be changed vs. those that don't, you could use an -if option.
* 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).


krzysiu

Batch as Windows batch?
@echo off
setlocal

:fileloop
if "%~1"=="" goto :end
ffprobe -v error -select_streams v:0 -sexagesimal -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 %1 > %TEMP%\duration.tmp
set /p duration= < %TEMP%\duration.tmp
del %TEMP%\duration.tmp
set duration=0:0:0 %duration:~0,-7%
exiftool -filemodifydate-="%duration%" %1
shift
goto :fileloop

:end

endlocal
echo Done!
pause


This is how I'd do it (requires ffmpeg: https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20200501-39fb1e9-win64-static.zip). You just drop files (how many you want) on the batch file. Take note that:
1) Stream duration isn't always true
2) I'd recommend some errorlevel checking after ffprobe

Test for c:\test.avi (3s), c:\test2.avi (12s)
Before:

File Modification Date/Time     : 2020:04:17 10:40:27+02:00
File Modification Date/Time     : 2020:05:01 22:37:14+02:00


Command:

    1 image files updated
    1 image files updated
Done!


After:

File Modification Date/Time     : 2020:04:17 10:40:24+02:00
File Modification Date/Time     : 2020:05:01 22:37:02+02:00
"We would use teleporters and live on another planets, if only ExifTool would be present when I was researching cosmos and physics"
Albert Einstein

gheppell

Any idea how to write the quicktime:timezone tag to a file.  I have tried both through the command line and via imatch but no luck.  I do not get any errors, just a notification that file are 'unchanged'.

Thank you

StarGeek

If you check the QuickTime tag page, you'll see that the Quicktime:TimeZone tag is not writable.
* 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).

gheppell

Thank you.  just curious then, how does that tag get populated?

StarGeek

No idea.  Exiftool can read a large variety of data based upon public specs and what can be found/deciphered from various files, but the source and how the tags are created aren't always known.  Sometimes even the actual purpose of some tags isn't completely known.
* 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).

gheppell

New one for you.  I would like to take one date/time tag and apply it to another but make changes based on information already inherent in the tag.

In particular, and by way of example:

If my xmp:createdate is equal to    2020:04:19 22:19:33+01:00, I would like to copy this to the quicktime:creationdate tag BUT I would like to move the time by the sign opposite of the timezone implied and ALSO flip the sign.  In my example, the output would be:   2020:04:19 21:19:33-01:00.  I realize that I could 'manually' do this with two commands:  -quicktime:creationdate-=1   and -quicktime:creationdate<${quicktime:creationdate}-+01:00+-01:00, but I am doing this in bulk from imatch, so I would like exiftool to read the value of the time zone (ie. -1, or -2, or +3, etc) in the xmp:createdate tag and know to subtract or add to the time, and then also to flip the sign.  Sorry if this is confusing.  appreciate all the help and am happy to provide specific context on 'why' if you so desire.

regards

StarGeek

To clarify, the local time for the video is 2020:04:19 22:19:33+01:00 and you're trying to set it to UTC time, which would be 2020:04:19 21:19:33 (Quicktime:CreationDate does not hold a timezone value) as per the Quicktime spec?

If that's the case, all you need to do is add the -api QuickTimeUTC option.  Exiftool will do the adjustment automatically.
* 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).

gheppell

sort of

The quicktime:createdate does not hold a tz value but it turns out that creationdate does.  It doesn't necessarily do act as one might expect in the context I am using it, hence the reason I want to make the changes per my original post.  I won't bore you with the details, but it has to do with onedrive and how it holds videos and photos relative to each other, not to mention the system time adjustments that it makes. 

So, yes, I want the UTC time in absolute terms, but only in the quicktime:creationdate tag. Further, since I have learned that this tag holds the tz string, I need to flip the sign of the tz and maintain its absolute value.  Clear as mud??

Using my example, the video was taken at 10:19:33 pm on April 19th, in London (ie +01:00).  (It was actually 2019.  My understanding is that BST has been cancelled this year.) 
I don't want the xmp:createdate to change, I only reference it as the basis to write to the quicktime:creationdate tag in the absence of any other tag that has the info I need.

So, my reference, regardless of where it comes from is a date/time tag that has a tz component.  The output, using my example is, converts the date/time to UTC but then adds the tz string with the sign (ie. plus or minus) flipped from whatever it was in the referenced date/time tag.