ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: mcorrente on April 16, 2021, 02:44:38 PM

Title: Setting media date/time to localized file date/time minus duration
Post by: mcorrente on April 16, 2021, 02:44:38 PM
Exif gurus:

I'm trying to figure out if there's a way I can use exiftool to set the "Media Create Date" of a video file to the local value of the "File Modification Date/Time" MINUS the "Duration".  All the data is in there, just not sure if exiftool can handle the localization or offsetting by the duration.

Short story long, here's why I'm trying to do this.  I have a GoPro and a known issue with GoPros is that they set the file date/times correctly (UTC with local offset), but the media date/times are set to UTC with no offset.  From my research, I understand that those tags shouldn't include an offset, but SHOULD be set to local time.  Notably, photos taken with GoPros have the values set correctly (which is why I can't just change the date and time on my camera to sort all this out).

In addition to that, GoPro breaks large recordings into ~9 min sections.  So, if I have a 30 minute video, I end up with 4 files.  Those files all share the same media date/time (the time I started the recording).  This is the date/time that's used on GoPro's website when uploading, so all the video pieces end up in an arbitrary order with no way to sort them correctly other than manually modifying each after uploading.  The file date/time of each piece IS different, and matches the date/time each section stopped recording.

I would like the media dates/times to match both the correct local time and the time at which each clip started recording.  If I take the file date/time (with the correct offset) and subtract the duration of the video, that's the value I get.

So, if I have a file with the following values:

ExifTool Version Number         : 12.24
File Modification Date/Time     : 2021:04:15 19:42:20-04:00
Duration                        : 0:01:38
Media Create Date               : 2021:04:15 19:42:18
Media Modify Date               : 2021:04:15 19:42:18


I would want the media dates to be set to 2021:04:15 15:40:42 (localized 2021:04:15 19:42:20-04:00 minus 1:38).

Is there any way to do this?  Thanks in advance.
Title: Re: Setting media date/time to localized file date/time minus duration
Post by: StarGeek on April 16, 2021, 04:32:38 PM
Quote from: mcorrente on April 16, 2021, 02:44:38 PM
Short story long, here's why I'm trying to do this.  I have a GoPro and a known issue with GoPros is that they set the file date/times correctly (UTC with local offset), but the media date/times are set to UTC with no offset.  From my research, I understand that those tags shouldn't include an offset, but SHOULD be set to local time.

Just pointing out that all integer based video timestamps, which includes MediaCreateDate (see here (https://exiftool.org/TagNames/QuickTime.html#MediaHeader)) are supposed to be set to UTC according to the specs. But since it's your file, you can and absolutely should set them how you like.

QuoteI would like the media dates/times to match both the correct local time and the time at which each clip started recording.
...
I would want the media dates to be set to 2021:04:15 15:40:42 (localized 2021:04:15 19:42:20-04:00 minus 1:38).

This is basically something I already have a command for which I use when downloading live streams with Youtube-DL.  Youtube-DL sets the FileModifyDate to the time the video ended so I have to shift it by the Duration to get the starting time.  So try this
exiftool -P "-MediaCreateDate<${FileModifyDate;ShiftTime('-0:0:'.$self->GetValue('Duration','ValueConv'))}" /path/to/files/

That will set the MediaCreateDate to the FileModifyDate minus the Duration using local time.  Add -api QuickTimeUTC option (https://exiftool.org/ExifTool.html#QuickTimeUTC) if you want to set it to UTC.  Swap single/double quotes if you're using Mac/Linux/PowerShell.
Title: Re: Setting media date/time to localized file date/time minus duration
Post by: mcorrente on April 16, 2021, 11:04:39 PM
Brilliant!  Thanks!  That worked like a charm.  Going to save me a ton of headache.