Dynamic time shift calculation

Started by fxstein, October 26, 2022, 01:46:27 AM

Previous topic - Next topic

fxstein

Hi,

Back with a somewhat complicated problem:

I need to calculate a dynamic time offset on the fly as the difference between CreateDate and the first GPSDateTime within the extended attributes of GoPro mp4 video files and then shift all Quicktime dates by that amount.

Based on a post by StarGeek https://exiftool.org/forum/index.php?msg=55052 I have been able to do the calculation like this:

exiftool -ee -d '%s' -p '${GPSDateTime;$_=int(($_-$self->GetValue("CreateDate"))/3600+0.5)}' P_20221004110648_GoPro_Hero10_2442_GX010328.mp4
It's the time difference rounded to the closest hour.

Issue: how do I use this calculation as input to the timeshift calculation?

If I run this:

exiftool -d '%s' '-quicktime:time:all+=${GPSDateTime;$_=int(($_-$self->GetValue("CreateDate"))/3600+0.5)}' -o PT_20221004110648_GoPro_Hero10_2442_GX010328.mp4 P_20221004110648_GoPro_Hero10_2442_GX010328.mp4
I am getting

Warning: Shift value for ItemList:ReleaseDate is not a number
Your help is very much appreciated!
If you want to help fix GoPro and related EXIF metadata please check out: https://github.com/fxstein/GoProX

StarGeek

This is Common Mistake #5c.  You're using an equal sign = instead of a copy tag (greater/less than) sign </>.

You'll also want to use the ShiftTime helper function

I'm heading to bed, so I can't work up an example, but here's a snippet from one of my commands. In some videos I capture, the system time stamps end up at the time the video ended instead of started, so I have to subtract the duration.  "SysTime" is one of my short cuts for both file system time stampss (definition in this post).  This example subtracts seconds, but since you'll want hours, you would remove the 0:0:  Hopefully that will give you a starting point.
"-systime<${FileModifyDate;ShiftTime('-0:0:'.$self->GetValue('Duration','ValueConv'))}"
"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

fxstein

Very much appreciate your answer. Unfortunately, I don't understand it.

Heading to bed as well. Will try to re-read all of this tomorrow.
If you want to help fix GoPro and related EXIF metadata please check out: https://github.com/fxstein/GoProX

StarGeek

Taking the time to read your post and I have a question.  Are the Quicktime:Time tags set to a different time than the CreateDate and GPSDateTime?  Because most of the Quicktime tags are supposed to be set to UTC and the GPSDateTime is also supposed to be set to UTC.  If you shift the CreateDate by the difference between CreateDate and GPSDateTime, you're going to end up with the GPSDateTime time stamp.  So it would be just easier to copy GPSDateTime to Quicktime:Time:All

exiftool '-Quicktime:Time:All<GPSDateTime' /path/to/files/
"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

fxstein

#4
That is a great question and here is the reason for this and why I am rounding the delta to basically the implied DST offset:

In many cases, I have synchronized multiple cameras through different means down to a single frame. So I really want to keep the create time for the files, even the original name with the local timestamp they happened, because I can link multiple cameras files together very easily. But since GoPro incorrectly sets the QuickTime tags to local time instead of UTC, most downstream processing gets tripped up.

The logic basically leaves the time as is and just fixes the time in QuickTime to be the standard UTC.

It's a workaround that has proven to be very reliable for the types of workflows I am working with and that I have performed manually with exiftool by simply applying the delta by hand.

exiftool -AllDates+=7 -quicktime:time:all+=7 -verbose -o PT_20221004110648_GoPro_Hero10_2442_GX010328.mp4 P_20221004110648_GoPro_Hero10_2442_GX010328.mp4
Now I am trying to automate it because others have asked me for a more universal solution to the problem.

Independent from that I am also planning a GPS time function, for the workflow in goprox that does what you describe for those cases where the camera time is much more unreliable and hence the GPS time is the one to count on, but it has other implications.
If you want to help fix GoPro and related EXIF metadata please check out: https://github.com/fxstein/GoProX

fxstein

I have now taken you prior recommendation and modified the logic to this:

exiftool -ee -d '%s' '-quicktime:time:all<${CreateDate}+${GPSDateTime;$_=int(($_-$self->GetValue("CreateDate"))/3600+0.5)}' -o PT_20221004110648_GoPro_Hero10_2442_GX010328.mp4 P_20221004110648_GoPro_Hero10_2442_GX010328.mp4
This will run without error, but the output file has some strange values in it after that:

exiftool -ee -quicktime:time:all -GPSDateTime PT_20221004110648_GoPro_Hero10_2442_GX010328.mp4
File Modification Date/Time     : 2022:10:26 10:38:37-07:00
File Access Date/Time           : 2022:10:26 10:38:37-07:00
File Inode Change Date/Time     : 2022:10:26 10:38:37-07:00
Create Date                     : 2022:10:04 11:06:48
Modify Date                     : 2022:10:04 11:06:48
Release Date                    : 1664906808+7
Track Create Date               : 2022:10:04 11:06:48
Track Modify Date               : 2022:10:04 11:06:48
Media Create Date               : 2022:10:04 11:06:48
Media Modify Date               : 2022:10:04 11:06:48
Track Create Date               : 2022:10:04 11:06:48
Track Modify Date               : 2022:10:04 11:06:48
Media Create Date               : 2022:10:04 11:06:48
Media Modify Date               : 2022:10:04 11:06:48
Track Create Date               : 2022:10:04 11:06:48
Track Modify Date               : 2022:10:04 11:06:48
Media Create Date               : 2022:10:04 11:06:48
Media Modify Date               : 2022:10:04 11:06:48
Track Create Date               : 2022:10:04 11:06:48
Track Modify Date               : 2022:10:04 11:06:48
Media Create Date               : 2022:10:04 11:06:48
Media Modify Date               : 2022:10:04 11:06:48
GPS Date Time                   : 2022:10:04 18:06:48.700
GPS Date Time                   : 2022:10:04 18:06:51.100
GPS Date Time                   : 2022:10:04 18:06:52.100
GPS Date Time                   : 2022:10:04 18:06:53.100
GPS Date Time                   : 2022:10:04 18:06:54.100
GPS Date Time                   : 2022:10:04 18:06:55.100
GPS Date Time                   : 2022:10:04 18:06:56.100
GPS Date Time                   : 2022:10:04 18:06:57.100
GPS Date Time                   : 2022:10:04 18:06:58.100
GPS Date Time                   : 2022:10:04 18:06:59.100
GPS Date Time                   : 2022:10:04 18:07:00.100
GPS Date Time                   : 2022:10:04 18:07:01.100
GPS Date Time                   : 2022:10:04 18:07:02.100
GPS Date Time                   : 2022:10:04 18:07:03.100
GPS Date Time                   : 2022:10:04 18:07:04.100
GPS Date Time                   : 2022:10:04 18:07:05.100
GPS Date Time                   : 2022:10:04 18:07:06.100
GPS Date Time                   : 2022:10:04 18:07:07.100
GPS Date Time                   : 2022:10:04 18:07:08.100
GPS Date Time                   : 2022:10:04 18:07:09.100
GPS Date Time                   : 2022:10:04 18:07:10.100
GPS Date Time                   : 2022:10:04 18:07:11.100
GPS Date Time                   : 2022:10:04 18:07:12.100
GPS Date Time                   : 2022:10:04 18:07:13.100
GPS Date Time                   : 2022:10:04 18:07:14.100
Year                            : 1664906808+7
GPS Date Time                   : 2022:10:04 18:06:48.700

and the Quicktime tags are still not shifted.
If you want to help fix GoPro and related EXIF metadata please check out: https://github.com/fxstein/GoProX

StarGeek

Remove the -ee (-extractEmbedded) option so you don't see all the time stamps from the GPS track.

No idea what's happening with ReleaseDate and Year.  But you might try a more targeted approach rather than trying to write to All timestamps.  It's not really needed in most cases.  Instead, you can write using a wildcards (simple example here)
'-Quicktime:*ModifyDate<CreateDate' '-Quicktime:*CreateDate<CreateDate'

That will write to the Quicktime CreateDate, ModifyDate, and all the track time stamps.  The only stray tag that will write is ContentCreateDate.
"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

fxstein

The problem is for GoPro mp4 video files you need the -ee option to get any GPSDateTime - unless I am missing something.

As for the assignments: Is there any way to do the calculation once and apply the result to multiple instances?

All I am trying to do here is replicate this behavior dynamically:

exiftool -AllDates+=7 -quicktime:time:all+=7 ...
where 7 is a calculated difference (rounded) between CreateDate and GPSDateTime aka the actual DST offset.

Thank you!
If you want to help fix GoPro and related EXIF metadata please check out: https://github.com/fxstein/GoProX

StarGeek

Quote from: fxstein on October 27, 2022, 12:52:34 AMThe problem is for GoPro mp4 video files you need the -ee option to get any GPSDateTime - unless I am missing something.

Use the command in FAQ #3 to see if the data is elsewhere in the file.  That command will show you duplicate tags and the groups they belong to, as well as giving tag names instead of descriptions.

QuoteAs for the assignments: Is there any way to do the calculation once and apply the result to multiple instances?

You would have to create a shortcut.  If you have an .ExifTool_config file, you would add it to that.  The example shortcuts can be found at the top of the example.config file.  My own config file contains a shortcut called "VidTime".  Here's a self contained snippet that you could copy/paste into an .ExifTool_config file.
%Image::ExifTool::UserDefined::Shortcuts = (
    VidTime        => ['Quicktime:CreateDate','Quicktime:ModifyDate','Quicktime:TrackCreateDate','Quicktime:TrackModifyDate','Quicktime:MediaCreateDate','Quicktime:MediaModifyDate'],
);
"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

fxstein

Drumroll...

I finally got it working fully dynamic without any need for hard coded values or lists so it works on all GoPro video media:

exiftool -wm w -ee -d '%s' '-quicktime:time:all<${GPSDateTime;$_=$self->GetValue("CreateDate")+int(($_-$self->GetValue("CreateDate"))/3600+0.5)*3600}' -o PT_20221004110648_GoPro_Hero10_2442_GX010328.mp4 P_20221004110648_GoPro_Hero10_2442_GX010328.mp4 -api TimeZone=GMT
The magic happens in a few places here:
-ee is needed for GoPro mp4 video files to get the GPSDateTime
-wm w writes only existing tags to avoid creating new ones with -quicktime:time:all
${GPSDateTime;$_=$self->GetValue("CreateDate")+int(($_-$self->GetValue("CreateDate"))/3600+0.5)*3600} is the logic to calculate the DST offset we need to apply to the QuickTime Dates to shift them to UTC
-api TimeZone=GMT But that only works if you force exiftool to ignore the local timezone at execution time or everything gets shifted by that amount as well.

Now I just need to replace my dirty int() rounding logic with a version that works for negative offset as well.

Sometimes the path is not a straight one, but all your input has made me think more and differently and some google searches against the exiftool forum found me additional bits.

Very much appreciate what you all are doing!
If you want to help fix GoPro and related EXIF metadata please check out: https://github.com/fxstein/GoProX

fxstein

For future reference, this is now the fully implemented automatic time shift code for GoPro video media (both mp4 and 360):

https://github.com/fxstein/GoProX/commit/2ae114129ab18fb9cfa29f4f6a1fb3b08471f5a5
If you want to help fix GoPro and related EXIF metadata please check out: https://github.com/fxstein/GoProX