Correcting Time for MP4 Video Files

Started by kreg, April 22, 2020, 11:57:02 PM

Previous topic - Next topic

kreg

Tried to avoid posting, but after a few days of reading various posts, I seem to be needing more help.

This is just a typical question about correcting time on a set of MP4 video files.  I failed to set the clock on my camera before going to South America.

If just looking at 1 of the files...

Correct time was 2019:06:28 11:59:23 GMT-04:00
(All dates are off by 5 months 18 days and 2 hours)

I have tried several approaches, but I can't quite get it perfected.


D:\capture\fixthese\video>exiftool -time:all -a -s -G1 MVI_3117.MP4


[System]        FileModifyDate                  : 2019:01:10 08:59:22-07:00
[System]        FileAccessDate                  : 2020:04:22 20:54:16-06:00
[System]        FileCreateDate                  : 2020:04:12 10:26:57-06:00
[IFD0]          ModifyDate                      : 2019:01:10 09:59:23
[ExifIFD]       DateTimeOriginal                : 2019:01:10 09:59:23
[ExifIFD]       CreateDate                      : 2019:01:10 09:59:23
[Canon]         TimeZone                        : -06:00
[Canon]         TimeZoneCity                    : Denver
[Canon]         DaylightSavings                 : On
[ExifIFD]       SubSecTime                      : 64
[ExifIFD]       SubSecTimeOriginal              : 64
[ExifIFD]       SubSecTimeDigitized             : 64
[QuickTime]     CreateDate                      : 2019:01:10 16:59:23
[QuickTime]     ModifyDate                      : 2019:01:10 16:59:23
[Track1]        TrackCreateDate                 : 2019:01:10 16:59:23
[Track1]        TrackModifyDate                 : 2019:01:10 16:59:23
[Track1]        MediaCreateDate                 : 2019:01:10 16:59:23
[Track1]        MediaModifyDate                 : 2019:01:10 16:59:23
[Track2]        TrackCreateDate                 : 2019:01:10 16:59:23
[Track2]        TrackModifyDate                 : 2019:01:10 16:59:23
[Track2]        MediaCreateDate                 : 2019:01:10 16:59:23
[Track2]        MediaModifyDate                 : 2019:01:10 16:59:23
[Composite]     SubSecCreateDate                : 2019:01:10 09:59:23.64
[Composite]     SubSecDateTimeOriginal          : 2019:01:10 09:59:23.64
[Composite]     SubSecModifyDate                : 2019:01:10 09:59:23.64


If I understand, tags in the Track categories might be UTC.  I have tried a variety of things...

This works for many of the tags, but not all.  Also, this does not account that some need to be UTC (I think, right?).  I'm happy to target the others specifically, but I'm still unclear as to what a [label] is vs. the Tag, and how to target them.  (Also, it seems not everything is writable)

exiftool "-AllDates=2019:06:28 11:59:23" -wm w MVI_3117.MP4


It did not error, but it also did not write.

D:\capture\fixthese\video>exiftool -DateTimeOriginal="2019:06:28 11:59:23" -wm w MVI_3117.MP4
    0 image files updated
    1 image files unchanged


I tried to target CreateDate specifically, so that I could effect derived tags, such as SubSecCreateDate.  Also did not work.

D:\capture\fixthese\video>exiftool -EXIF:CreateDate="2019:06:28 11:59:23" -wm w MVI_3117.MP4
    0 image files updated
    1 image files unchanged


I gave this a shot, but I can't really say what I was trying to do.  I guess I wanted to see if I could effect tags next to the type G1 with [Composite]

D:\capture\fixthese\video>exiftool -Composite:*date="2019:06:28 11:59:23" -wm w MVI_3117.MP4
    0 image files updated
    1 image files unchanged


I did have some success using ffmpeg, but the output (-c copy) resulted in only 86 tags!  The original has 283, and they are much more meaningful to preserve. 

ffmpeg -i MVI_3117.MP4 -c copy -map 0 -metadata creation_time="2019:06:28 11:59:23" MVI_3117-new.MP4


I didn't even get around to trying to fix the TimeZone and TimeZoneCity.
In the end, it'd be nice to manipulate the File System level tags also.  Makes for organizing files much easier when using just a file browser.

And personally... I'd rather directly attack each file from the camera with Exiftool.  It's... far too awesome to use something else.
Any guidance would be appreciated.

StarGeek

Quote from: kreg on April 22, 2020, 11:57:02 PM

[IFD0]          ModifyDate                      : 2019:01:10 09:59:23
[ExifIFD]       DateTimeOriginal                : 2019:01:10 09:59:23
[ExifIFD]       CreateDate                      : 2019:01:10 09:59:23
[Canon]         TimeZone                        : -06:00
[Canon]         TimeZoneCity                    : Denver
[Canon]         DaylightSavings                 : On
[ExifIFD]       SubSecTime                      : 64
[ExifIFD]       SubSecTimeOriginal              : 64
[ExifIFD]       SubSecTimeDigitized             : 64

These tags are part of the EXIF and MakerNotes (a subgroup of the EXIF) groups.  The problem is that there is no standard for embedding EXIF data in a video file.  Not that that has stopped a lot of camera makers from forcing it into the file.  Because of this, exiftool is currently unable to edit these time stamps.  I'm not even sure that any of the camera companies have made a way to edit these tags.

Quote[QuickTime]     CreateDate                      : 2019:01:10 16:59:23
[QuickTime]     ModifyDate                      : 2019:01:10 16:59:23
[Track1]        TrackCreateDate                 : 2019:01:10 16:59:23
[Track1]        TrackModifyDate                 : 2019:01:10 16:59:23
[Track1]        MediaCreateDate                 : 2019:01:10 16:59:23
[Track1]        MediaModifyDate                 : 2019:01:10 16:59:23
[Track2]        TrackCreateDate                 : 2019:01:10 16:59:23
[Track2]        TrackModifyDate                 : 2019:01:10 16:59:23
[Track2]        MediaCreateDate                 : 2019:01:10 16:59:23
[Track2]        MediaModifyDate                 : 2019:01:10 16:59:23

These are the standard video time stamps and part of the Quicktime group. According to the standard, these are supposed to be in UTC, but it's up to you whether you want to make sure they are that way, depending upon what software you use with your files.  Adobe programs read these tags as if they were local time, the same as a jpg or RAW file.  Windows and Google photos will read them as per the spec as UTC time.  So it's up to you as to what you want to do.

Quote[Composite]     SubSecCreateDate                : 2019:01:10 09:59:23.64
[Composite]     SubSecDateTimeOriginal          : 2019:01:10 09:59:23.64
[Composite]     SubSecModifyDate                : 2019:01:10 09:59:23.64

The Composite group tags are tags that exiftool creates based upon other tags in the file.  They're not embedded metadata and you don't really need to worry about them.

QuoteThis works for many of the tags, but not all.  Also, this does not account that some need to be UTC (I think, right?).  I'm happy to target the others specifically, but I'm still unclear as to what a [label] is vs. the Tag, and how to target them.  (Also, it seems not everything is writable)

exiftool "-AllDates=2019:06:28 11:59:23" -wm w MVI_3117.MP4

The AllDates tag is a Shortcut tag.  It combines three separate tags, DateTimeOriginal, CreateDate, and ModifyDate.  Normally, it's used to edit EXIF tags of these names, but the latter two also appear as part of the Quicktime group, so those should get edited.  There is also a Quicktime:DateTimeOriginal tag, but because you are using the -wm (writemode) option with only Write existing tags set, it does not get created.  It's not a common tag anyway.

QuoteI did have some success using ffmpeg, but the output (-c copy) resulted in only 86 tags!  The original has 283, and they are much more meaningful to preserve. 

I do not believe that ffmpeg can copy the EXIF and MakerNotes block, which is where the missing tags would be stored.

Currently, you're basically stuck with the data in the EXIF and MakerNotes, short of loading the file into a hex editor and editing it that way, which may have some unforeseen pitfalls.  The Quicktime tags can all be edited with exiftool with a command like
exiftool -CreateDate="2019:06:28 11:59:23-04:00" -ModifyDate="2019:06:28 11:59:23-04:00" -Track*Date="2019:06:28 11:59:23-04:00" -Media*Date="2019:06:28 11:59:23-04:00" MVI_3117.MP4

I used a wildcard here to set both the Track dates and Media dates at the same time.

This will set the time stamps as if the time was local time (the Adobe way, against spec).  If you want to set them to UTC time (as spec), you can add the -api QuickTimeUTC option and exiftool will adjust to UTC time.

Another option would be to use exiftool's time shift ability to bulk shift by the 5 months, 18 days and 2 hours.  For example (I think this works, haven't tested it)
exiftool -TagsFromFile @ -time:all -GlobalTimeShift "5:18 2:0:0" /path/to/videos

This should take all the time tags exiftool can edit, shift the time, and copy them back into the file in the exact same spots.
* 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).

kreg

THANK YOU for such an awesome explanation.  Everything you went over really did clear up many ideas that I've accumulated over the past week.  Seeing what I can not edit (short of hex editing) does make me feel a lot better about my files.  I could try hex, but... I'd rather leave them alone at that depth.  Also thank you for pointing out that SubSec* is not a tag that's actually present in the file.  I've been trying to find where that comes from.  Other tools were showing it also.  Metadata++ for example.  Seriously, thank you for this.  I will review what you wrote and try your suggestions.  Awesome!

StarGeek

All the sub pages listed on the Tag Names page have all the tags exiftool knows and whether they are writable or not.  When I'm not sure of a tag or don't know what group it's part of,  I'll do a google search on the tag with Site:exiftool.org/TagNames as part of the search to limit it to just the tag pages.  For example, in the case of SubSecCreateDate, this would be the google search.
* 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).

kreg

I'm trying to compose a GlobalTimeShift option.   Here is what I've composed for tackling a single file.

This is an example I seem to like.  I've compared this to a file from the same camera, where the time and timezone were set correctly for South America and close to the same time as the incorrectly dated file of the same trip.  Viewing the resulting -G1 (considering only the modifiable timestamps, thanks to your teaching), results the same as what this example produces.  I did leave the timezone off of -FileModifyDate, because when I included it, the time differed from the camera test.  My desktop is also operating currently in -06:00.

exiftool -FileModifyDate="2019:06:28 11:50:06" -CreateDate="2019:06:28 11:50:06-04:00" -ModifyDate="2019:06:28 11:50:06-04:00" -Track*Date="2019:06:28 11:50:06-04:00" -Media*Date="2019:06:28 11:50:06-04:00" -api QuickTimeUTC -wm w MVI_3109.MP4



D:\capture\fixthese\shift-test>exiftool -time:all -a -s -G1 MVI_3109.MP4.bak
[System]        FileModifyDate                  : 2019:06:28 11:50:06-06:00
[System]        FileAccessDate                  : 2019:06:28 11:50:06-06:00
[System]        FileCreateDate                  : 2020:04:29 23:18:27-06:00
[IFD0]          ModifyDate                      : 2019:01:10 09:50:06
[ExifIFD]       DateTimeOriginal                : 2019:01:10 09:50:06
[ExifIFD]       CreateDate                      : 2019:01:10 09:50:06
[Canon]         TimeZone                        : -06:00
[Canon]         TimeZoneCity                    : Denver
[Canon]         DaylightSavings                 : On
[ExifIFD]       SubSecTime                      : 88
[ExifIFD]       SubSecTimeOriginal              : 88
[ExifIFD]       SubSecTimeDigitized             : 88
[QuickTime]     CreateDate                      : 2019:06:28 15:50:06
[QuickTime]     ModifyDate                      : 2019:06:28 15:50:06
[Track1]        TrackCreateDate                 : 2019:06:28 15:50:06
[Track1]        TrackModifyDate                 : 2019:06:28 15:50:06
[Track1]        MediaCreateDate                 : 2019:06:28 15:50:06
[Track1]        MediaModifyDate                 : 2019:06:28 15:50:06
[Track2]        TrackCreateDate                 : 2019:06:28 15:50:06
[Track2]        TrackModifyDate                 : 2019:06:28 15:50:06
[Track2]        MediaCreateDate                 : 2019:06:28 15:50:06
[Track2]        MediaModifyDate                 : 2019:06:28 15:50:06
[Composite]     SubSecCreateDate                : 2019:01:10 09:50:06.88
[Composite]     SubSecDateTimeOriginal          : 2019:01:10 09:50:06.88
[Composite]     SubSecModifyDate                : 2019:01:10 09:50:06.88

D:\capture\fixthese\shift-test>exiftool -time:all -a -s -G1 timetest.MP4.bak
[System]        FileModifyDate                  : 2019:06:28 11:50:11-06:00
[System]        FileAccessDate                  : 2020:04:30 00:05:17-06:00
[System]        FileCreateDate                  : 2019:06:28 11:50:11-06:00
[IFD0]          ModifyDate                      : 2019:06:28 11:50:11
[ExifIFD]       DateTimeOriginal                : 2019:06:28 11:50:11
[ExifIFD]       CreateDate                      : 2019:06:28 11:50:11
[Canon]         TimeZone                        : -04:00
[Canon]         TimeZoneCity                    : Caracas
[Canon]         DaylightSavings                 : Off
[ExifIFD]       SubSecTime                      : 91
[ExifIFD]       SubSecTimeOriginal              : 91
[ExifIFD]       SubSecTimeDigitized             : 91
[QuickTime]     CreateDate                      : 2019:06:28 15:50:11
[QuickTime]     ModifyDate                      : 2019:06:28 15:50:11
[Track1]        TrackCreateDate                 : 2019:06:28 15:50:11
[Track1]        TrackModifyDate                 : 2019:06:28 15:50:11
[Track1]        MediaCreateDate                 : 2019:06:28 15:50:11
[Track1]        MediaModifyDate                 : 2019:06:28 15:50:11
[Track2]        TrackCreateDate                 : 2019:06:28 15:50:11
[Track2]        TrackModifyDate                 : 2019:06:28 15:50:11
[Track2]        MediaCreateDate                 : 2019:06:28 15:50:11
[Track2]        MediaModifyDate                 : 2019:06:28 15:50:11
[Composite]     SubSecCreateDate                : 2019:06:28 11:50:11.91
[Composite]     SubSecDateTimeOriginal          : 2019:06:28 11:50:11.91
[Composite]     SubSecModifyDate                : 2019:06:28 11:50:11.91


Is there a way to use GlobalTimeShift or similar for this?   I even thought about trying 2 passes.  First set -FileModifyDate with =+ maybe, but even if that works, I don't know how to exclude it with a -GlobalTimeShift command on the 2nd pass.   And -GlobalTimeShift doesn't seem to be timezone aware.  At least, not that I could find in the man page.

Quote from: StarGeek on April 23, 2020, 12:50:55 AM
Another option would be to use exiftool's time shift ability to bulk shift by the 5 months, 18 days and 2 hours.  For example (I think this works, haven't tested it)
exiftool -TagsFromFile @ -time:all -GlobalTimeShift "5:18 2:0:0" /path/to/videos

This "worked" but again, it didn't seem to be timezone aware.  So it didn't match (the metadata that I'm able to change) with the test file from the purposely -04:00 set camera.

Phil Harvey

Coming back to the topic of writing maker notes in MP4 files...  The maker notes in most Canon MP4 files are stored inside the ThumbnailImage, which is writable, so you can do something like this (painful though it is):

exiftool -thumbnailimage -b FILE | exiftool -time:all="2019:06:28 11:50:06" -timezone="-04:00" -wm w - | exiftool -thumbnailimage'<=-' 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 ($).

StarGeek

Quote from: kreg on April 30, 2020, 03:40:48 AM
Is there a way to use GlobalTimeShift or similar for this?

I'm not quite sure what the question is.  But I will point out that for a video shot at 2019:06:28 11:50:06-04:00, it would be incorrect for the FileModifyDate to also show 2019:06:28 11:50:06.  The file system tags are aware of time zones and will adjust the time according to local time zone of the computer it is shown on.
* 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).

kreg

Quote from: Phil Harvey on April 30, 2020, 07:45:31 AM
The maker notes in most Canon MP4 files are stored inside the ThumbnailImage, which is writable, so you can do something like this (painful though it is):

exiftool -thumbnailimage -b FILE | exiftool -time:all="2019:06:28 11:50:06" -timezone="-04:00" -wm w - | exiftool -thumbnailimage'<=-' FILE

Hello Phil Harvey!  Thank you for this advise.  I will certainly test and try to add this in, and any other advise you are willing to offer.  Any thoughts on automating a shift across all files? Love this tool.


Quote from: StarGeek on April 30, 2020, 12:33:37 PM
I'm not quite sure what the question is.  But I will point out that for a video shot at 2019:06:28 11:50:06-04:00, it would be incorrect for the FileModifyDate to also show 2019:06:28 11:50:06.

Are you responding to me or Phil about the "would be incorrect" FileModifyDate timezone?

If to me, then here is what I'm attempting. if you look at the code section in my previous post, I added 2 outputs.  Let's look at them in reverse.

The second output example, is a test file from the same camera.   I was just attempting to simulate "what if I did remember to set the time correctly to my destiation?  What would the file look like when I got home?  So while sitting here, I just put the camera's clock to Jun 28, 11:50am, -04:00 and no daylight savings check mark.   I then shot a few seconds of video.  I turned off the camera, and pulled the SD card out.  Then I copied the file as is, to my computer, which is sitting here in -06:00 Mountain Daylight Savings time

The first output example, is me trying to correct one of the actual .MP4 video files shot from that camera, when I really was there (with the completely wrong time set), and using Exiftool to try matching the test MP4 as best as I can.  -FileModifyDate in the simulated test example, does end up with -06:00 as a result, with no changes made to it.  So I made effort to match that for the real trip MP4.

This is why I did

-FileModifyDate="2019:06:28 11:50:06"


instead of

-FileModifyDate="2019:06:28 11:50:06-04:00"


Does it make sense to compare this way?

StarGeek

Quote from: kreg on April 30, 2020, 02:32:00 PM
Are you responding to me or Phil about the "would be incorrect" FileModifyDate timezone?

I quoted you in my post.  It was in response to what you were saying there.

QuoteSo I made effort to match that for the real trip MP4.

This is why I did

-FileModifyDate="2019:06:28 11:50:06"


instead of

-FileModifyDate="2019:06:28 11:50:06-04:00"


Does it make sense to compare this way?

The thing is, the video wasn't take at 2019:06:28 11:50:06-06:00, it was taken at 2019:06:28 11:50:06-04:00 which would be 2019:06:28 09:50:06-06:00.  The file system understand time zones and will adjust it properly.  You will never see a system time stamp of -04:00 on your computer unless you change the computer's system time to the -04:00 time zone.  And in that case, every single time stamp on every single file will be adjusted by two hours.

Here's an example. I changed my camera's time to -06:00 time zone, took a picture, changed it back to -08:00 time zone, and took another picture.  Results below
======== Y:/Pictures/Camera_Pictures/SDCC-2019/100D5100/DSC_0071.JPG
---- System ----
FileModifyDate                  : 2020:04:30 13:56:56-07:00
FileAccessDate                  : 2020:04:30 13:56:56-07:00
FileCreateDate                  : 2020:04:30 13:56:56-07:00
---- IFD0 ----
ModifyDate                      : 2020:04:30 13:56:57
---- ExifIFD ----
DateTimeOriginal                : 2020:04:30 13:56:57
CreateDate                      : 2020:04:30 13:56:57
SubSecTime                      : 10
SubSecTimeOriginal              : 10
SubSecTimeDigitized             : 10
---- Nikon ----
TimeZone                        : -06:00
DaylightSavings                 : Yes
DateDisplayFormat               : Y/M/D
PowerUpTime                     : 2019:09:12 15:49:36
---- Composite ----
SubSecCreateDate                : 2020:04:30 13:56:57.10
SubSecDateTimeOriginal          : 2020:04:30 13:56:57.10
SubSecModifyDate                : 2020:04:30 13:56:57.10
======== Y:/Pictures/Camera_Pictures/SDCC-2019/100D5100/DSC_0072.JPG
---- System ----
FileModifyDate                  : 2020:04:30 11:57:12-07:00
FileAccessDate                  : 2020:04:30 11:57:12-07:00
FileCreateDate                  : 2020:04:30 11:57:12-07:00
---- IFD0 ----
ModifyDate                      : 2020:04:30 11:57:11
---- ExifIFD ----
DateTimeOriginal                : 2020:04:30 11:57:11
CreateDate                      : 2020:04:30 11:57:11
SubSecTime                      : 60
SubSecTimeOriginal              : 60
SubSecTimeDigitized             : 60
---- Nikon ----
TimeZone                        : -08:00
DaylightSavings                 : Yes
DateDisplayFormat               : Y/M/D
PowerUpTime                     : 2019:09:12 13:49:36
---- Composite ----
SubSecCreateDate                : 2020:04:30 11:57:11.60
SubSecDateTimeOriginal          : 2020:04:30 11:57:11.60
SubSecModifyDate                : 2020:04:30 11:57:11.60
    2 image files read


Notice that on both images the FileModifyDate shows -07:00, while the embedded time zone, Nikon:TimeZone are different (with the DaylightSavings tag properly set so it adjusts the time).  But the first image shows 13:56:56 as the time while the second image shows 11:57:12.

You can consider the file system time stamps are similar to the Quicktime time stamps.  They're basically UTC, but the computer automatically shows you the time adjusted to the local time zone.

All that said, it's you file and data, it's always up to you how you want to set it.
* 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).

JohnJackson

Hi,
As an answer to the original poster/question: Correcting Time for MP4 Video Files.
You can also try to use MP4Workshop. It is a new software designed to edit the internal metadata of the MP4 file, and will also add timezone offset to make it align correctly with all other movies and pictures in for example GooglePhotos. It is free software, you can download from mp4workshop.com.
It can handle single files, but in essence it is aimed at batches of files (including JPG and MOV), which is usually the case when you camera setting is wrong..
It is free, GUI based, does NOT re-encode your video and has a preview window for the file you're working on. And it adds UTC and timezone offset: so no further weird effects in GooglePhotos or other programme used. It was first aimed solely at MP4/MOV, but now also handles JPG.

See mp4workshop.com
Greetings, John

JohnJackson