m2ts DateTimeOriginal editing

Started by ganymede55, December 30, 2015, 06:10:54 PM

Previous topic - Next topic

ganymede55

On a recent vacation, one of my Sony cameras was off by 11 hours and 38 min (+11:38:00 adjustment), resulting in pictures and videos grouped by the wrong date.  I can get the pictures cleaned up using ExifTool (and other front ends like GeoSetter) and I can use ExifTool or one of the others to adjust the FileCreateDate and FileModifyDate.  Unfortunately, some of my programs use only the DateTimeOriginal to group files in Windows folders or display them by date.  So it seems that my only choice is to update the DateTimeOriginal.  I read that ExifTool does not support this (and it reminds me when I try).  Are there any plans to support this soon or are there any tools that do allow this to be adjusted?  All I've found is tools that adjust the sidecar or similar files, but never the original.  Or is there some sort of workaround that I'm not thinking of?

I've spent way too much time on this and really have no other leads at this point, so this is it before throwing in the towel.  I think updating only the pictures would be worse than leaving everything alone.

Hayo Baan

DateTimeOriginal is supported, but not in all file formats (especially video). The problem to get this implemented is that video formats are quite a mess (eve more so than raw image files) so Phil has had no reliable way of updating the tag without potentially breaking the file.

A safe way of updating the tag would be to change its value in-place. Without touching any other bits in the file. This is not the way exiftool works though so it can not get implemented this way there :(
Hayo Baan – Photography
Web: www.hayobaan.nl

ganymede55

Hayo,
Thanks for the reply, but I'm not totally clear on what you're saying.  I know that DateTimeOriginal is supported as a read and that it exists in my file because I can see it in exiftool output.  I'm pretty sure that it's not supported (likely for the reasons you mentioned below).  I can also set FileCreateDate and FileModifyDate to match it.  I'm not clear if that was in question in your response above.

My main question is what do you mean by "change its value in-place"?  Do you mean with exiftool or some other application?  If so, what?  I can't even see the value in the basic windows properties for example.  Any clarifications are much appreciated.

Hayo Baan

With in-place, I meant editing the data at the exact spot they are in the file. Exiftool always fully rewrites the file (which cleans it up and optimises the structure optimised as well), but with video files this is too error prone so exiftool can't do it. Perhaps you can change the DateTimeOriginal with e.g., Photoshop, but I'm not sure about this.
Hayo Baan – Photography
Web: www.hayobaan.nl

Hayo Baan

#4
Ok, I took the time to write a little brute force script that changes the dateTime info in-place. I only had Nikon camera .mov files to test this on, so it might not fully work for you.

Anyway, first some info: there are many places where datetime info is stored in a .mov, for instance when I search for all datetime fields in a test file, here's what I get (-s to show tag names as used internally by exiftool, -a to show duplicate tags, -G0:1 to get group info):
$ exiftool -s -a -G0:1 -'*Date*' t.mov
[File:System]   FileModifyDate                  : 2016:01:01 15:43:24+01:00
[File:System]   FileAccessDate                  : 2016:01:01 15:35:23+01:00
[File:System]   FileInodeChangeDate             : 2016:01:01 15:43:24+01:00
[QuickTime]     CreateDate                      : 2015:01:16 13:57:39
[QuickTime]     ModifyDate                      : 2015:01:16 13:57:39
[QuickTime:Track1] TrackCreateDate              : 2015:01:16 13:57:39
[QuickTime:Track1] TrackModifyDate              : 2015:01:16 13:57:39
[QuickTime:Track1] MediaCreateDate              : 2015:01:16 13:57:39
[QuickTime:Track1] MediaModifyDate              : 2015:01:16 13:57:39
[QuickTime:Track2] TrackCreateDate              : 2015:01:16 13:57:39
[QuickTime:Track2] TrackModifyDate              : 2015:01:16 13:57:39
[QuickTime:Track2] MediaCreateDate              : 2015:01:16 13:57:39
[QuickTime:Track2] MediaModifyDate              : 2015:01:16 13:57:39
[MakerNotes:Nikon] CreateDate                   : 2015:01:16 13:57:39
[MakerNotes:Nikon] DateTimeOriginal             : 2015:01:16 13:57:39
[MakerNotes:Nikon] DateDisplayFormat            : D/M/Y


Now we want to adjust the dates by 11:38:00, so we'd use the following command to change them:
exiftool -s -CreateDate+="11:38:00" -ModifyDate+="11:38:00" -TrackCreateDate+="11:38:00" -TrackModifyDate+="11:38:00" -MediaCreateDate+="11:38:00" -MediaModifyDate+="11:38:00" -DateTimeOriginal+="11:38:00" t.mov
This results in:
$ exiftool -s -a -G0:1 -'*Date*' t.mov
[File:System]   FileModifyDate                  : 2016:01:01 15:44:58+01:00
[File:System]   FileAccessDate                  : 2016:01:01 15:45:23+01:00
[File:System]   FileInodeChangeDate             : 2016:01:01 15:44:58+01:00
[QuickTime]     CreateDate                      : 2015:01:17 01:35:39
[QuickTime]     ModifyDate                      : 2015:01:17 01:35:39
[QuickTime:Track1] TrackCreateDate              : 2015:01:17 01:35:39
[QuickTime:Track1] TrackModifyDate              : 2015:01:17 01:35:39
[QuickTime:Track1] MediaCreateDate              : 2015:01:17 01:35:39
[QuickTime:Track1] MediaModifyDate              : 2015:01:17 01:35:39
[QuickTime:Track2] TrackCreateDate              : 2015:01:17 01:35:39
[QuickTime:Track2] TrackModifyDate              : 2015:01:17 01:35:39
[QuickTime:Track2] MediaCreateDate              : 2015:01:17 01:35:39
[QuickTime:Track2] MediaModifyDate              : 2015:01:17 01:35:39
[MakerNotes:Nikon] CreateDate                   : 2015:01:16 13:57:39
[MakerNotes:Nikon] DateTimeOriginal             : 2015:01:16 13:57:39
[MakerNotes:Nikon] DateDisplayFormat            : D/M/Y

So it worked quite well indeed, apart from the dates in the makernotes...

For this I wrote a little script that matches the QuickTime CreateDate with the makernote DateTimeOriginal. It basically just changes all strings that match a byte indicating the length (20), followed by the DateTime string, followed by a zero byte. This has the side effect of changing the CreateDate in the makernote as well (which is what you'd want anyway).
$ ./mathDateTime  t.mov
OK: Changed date 2 times in t.mov

Which tells me it found and changed the date two times (which is what we expected).
Verifying with exifTool tells us this indeed worked:
$ exiftool -s -a -G0:1 -'*Date*' t.mov
[File:System]   FileModifyDate                  : 2016:01:01 15:49:17+01:00
[File:System]   FileAccessDate                  : 2016:01:01 15:51:23+01:00
[File:System]   FileInodeChangeDate             : 2016:01:01 15:49:17+01:00
[QuickTime]     CreateDate                      : 2015:01:17 01:35:39
[QuickTime]     ModifyDate                      : 2015:01:17 01:35:39
[QuickTime:Track1] TrackCreateDate              : 2015:01:17 01:35:39
[QuickTime:Track1] TrackModifyDate              : 2015:01:17 01:35:39
[QuickTime:Track1] MediaCreateDate              : 2015:01:17 01:35:39
[QuickTime:Track1] MediaModifyDate              : 2015:01:17 01:35:39
[QuickTime:Track2] TrackCreateDate              : 2015:01:17 01:35:39
[QuickTime:Track2] TrackModifyDate              : 2015:01:17 01:35:39
[QuickTime:Track2] MediaCreateDate              : 2015:01:17 01:35:39
[QuickTime:Track2] MediaModifyDate              : 2015:01:17 01:35:39
[MakerNotes:Nikon] CreateDate                   : 2015:01:17 01:35:39
[MakerNotes:Nikon] DateTimeOriginal             : 2015:01:17 01:35:39
[MakerNotes:Nikon] DateDisplayFormat            : D/M/Y


I've attached the script. Just provide it with a list of files to process on the command-line. The files need to have a correct QuickTime CreateDate (e.g., as done with the exiftool command I showed earlier).

WARNING: the script overwrites the original files so ALWAYS have a complete backup of the file you want to change the dates of!!!
Also, have a close look at the number of changes made, if this differs from the expected, chances are it inadvertently changed movie data instead of metadata (though unlikely, the movie data contained an exact match for the data string).

Anyway, try it out and let me know if it worked for you too :)

Please see later post for most current script!
Hayo Baan – Photography
Web: www.hayobaan.nl

ganymede55

Hayo,
Thanks again for taking the time to work on this!  Unfortunately, I can't get the basic update to work using the commands, so I haven't yet tried the script.  Here are the details:

I picked a copy of a small .m2ts video file to test on, but I also checked several others.  I modified all of the commands to only use it.  I suppose I should have used a copy of exiftool in a local directory to clean things up, so sorry for that.

Anyway, the first question I have is that these .m2ts file types don't seem to have nearly the Date fields that you have in your .MOV example, including the CreateDate field.  (Note that the command exiftool -s -a -G0:1 -time:all "G:\Public Videos\_Updated\8-8-2015\20150808213521.m2ts" returned exactly the same thing.) Is that going to be a show stopper?
C:\Windows\system32>exiftool -s -a -G0:1 -"*Date*" "G:\Public Videos\_Updated\8-8-2015\20150808213521.m2ts"
[File:System]   FileModifyDate                  : 2015:11:17 22:16:08-06:00
[File:System]   FileAccessDate                  : 2016:01:01 13:39:15-06:00
[File:System]   FileCreateDate                  : 2016:01:01 13:39:15-06:00
[H264]          DateTimeOriginal                : 2015:08:08 21:35:21-05:00


I tried writing to the CreateDate field for example just to see if that field was just hidden and could be updated, but no luck (not supported).
C:\Windows\system32>exiftool "-CreateDate<dateTimeOriginal" "G:\Public Videos\_Updated\8-8-2015\20150808213521.m2ts"
Error: Writing of M2TS files is not yet supported - G:/Public Videos/_Updated/8-8-2015/20150808213521.m2ts
    0 image files updated
    1 files weren't updated due to errors


I tried updating the DateTimeOriginal field with the same results
C:\Windows\system32>exiftool -s -DateTimeOriginal+="11:38:00" "G:\Public Videos\_Updated\8-8-2015\20150808213521.m2ts"
Error: Writing of M2TS files is not yet supported - G:/Public Videos/_Updated/8-8-2015/20150808213521.m2ts
    0 image files updated
    1 files weren't updated due to errors


However, I did have success updating the File System fields using the same commands (or copying from the DateTimeOriginal field).
C:\Windows\system32>exiftool -s -fileCreateDate+="11:38:00" -fileModifyDate+="11:38:00" "G:\Public Videos\_Updated\8-8-2015\20150808213521.m2ts"
    1 image files updated

C:\Windows\system32>exiftool -s -a -G0:1 -"*Date*" "G:\Public Videos\_Updated\8-8-2015\20150808213521.m2ts"
[File:System]   FileModifyDate                  : 2015:11:18 09:54:08-06:00
[File:System]   FileAccessDate                  : 2015:11:18 09:54:08-06:00
[File:System]   FileCreateDate                  : 2016:01:02 01:17:15-06:00
[H264]          DateTimeOriginal                : 2015:08:08 21:35:21-05:00


I didn't try running the batch script mainly because I'm not exactly sure how to do that, but also because I don't think it would work since the manual steps you showed didn't.  If you still think it's worth a try, please give me an example of how to run the script (with file names) and I'll try.  I'd also be happy to send you a video file.  Again, thanks for your help!  Please let me know if I'm missing something.


Hayo Baan

Ah, I see. These .m2ts files are quite a different beast. However, with your info I should be able to alter the script so it would also work for you, but then instead of using the QuickTime CreateDate, I would use the fileModifyDate. (I'd have thought fileCreateDate would be the better choice here, but that seems way off in your examples.)

Also, I notice the DateTimeOriginal has a timezone here, should the one from the fileCreateDate be used here too?
Note that me being able to tweak this does rely on the DateTimeOriginal being easily and uniquely identifiable, in the makernotes the DateTimeOriginal is recorded as a string which has a nice length and is therefore almost certain to be uniquely identifiable. If it is saved as some integer or something, I'm afraid it won't work (reliably).
If you could send me a sample file or point me to a location where I can download one, I could certainly have a go at this.

P.S. Seeing that you're running on Windows and not on UNIX/Mac, you'd need to install perl to be able to use my script too. Are you up to that?
Hayo Baan – Photography
Web: www.hayobaan.nl

ganymede55

Hayo,
Thanks again.  I uploaded a sample video.  It's a throwaway 5 sec clip that I'm glad I kept for this.  I don't want to add confusion, but the video I have referred to so far shot with a Sony that really only needed to be time-shifted-04:04:00 hours (basically time zone adjustment). I just happened to start editing that one and was planning to :deal with that later" if necessary.  Both cameras were shooting .m2ts videos this past summer in Hawaii (UTC-10 vs the UTC-6 time zone I'm in and computer is set to during downloads.  Hawaii doesn't use daylight savings, but I think it shows as -9 time zone since my camera was set to daylight savings).  Thus, I'd prefer to set to UTC-10, but if I get close (even UTC-5/6), I can deal with it.  For clarity, I'll just focus on the file I have attached which is representative of those from the camera to be adjusted +11:38:00.  All the captures below reference it.

Fresh after copying the file to my test folder, I get the (re)download date of November and today's date as the create date.  Hopefully that explains the "way off" dates you mentioned.
C:\Windows\system32>exiftool -s -a -G0:1 -"*Date*" "G:\Public Videos\_Updated\8-8-2015\20150809234216.m2ts"
[File:System]   FileModifyDate                  : 2015:11:15 15:48:10-06:00
[File:System]   FileAccessDate                  : 2016:01:01 22:26:09-06:00
[File:System]   FileCreateDate                  : 2016:01:01 22:26:09-06:00
[H264]          DateTimeOriginal                : 2015:08:09 23:42:15-09:00


I set the file create and modify dates to match DateTime original using exiftool and it succeeds but time shifts it for UTC-9 vs UTC-5 where I am now.  I think this eliminates the "way off" part you mentioned.
C:\Windows\system32>exiftool "-fileModifyDate<dateTimeOriginal" "-fileCreateDate<dateTimeOriginal" "G:\Public Videos\_Updated\8-8-2015\20150809234216.m2ts"
    1 image files updated

C:\Windows\system32>exiftool -s -a -G0:1 -"*Date*" "G:\Public Videos\_Updated\8-8-2015\20150809234216.m2ts"
[File:System]   FileModifyDate                  : 2015:08:10 03:42:15-05:00
[File:System]   FileAccessDate                  : 2015:08:10 03:42:15-05:00
[File:System]   FileCreateDate                  : 2015:08:10 03:42:15-05:00
[H264]          DateTimeOriginal                : 2015:08:09 23:42:15-09:00


I changed my computer to Hawaii time zone and did it again.  This time it gets adjusted to UTC-10 with -1 hr adjustment this time.  Alaska is UTC-9 so that's an option as well.
C:\Windows\system32>exiftool "-fileModifyDate<dateTimeOriginal" "-fileCreateDate<dateTimeOriginal" "G:\Public Videos\_Updated\8-8-2015\20150809234216.m2ts"
    1 image files updated

C:\Windows\system32>exiftool -s -a -G0:1 -"*Date*" "G:\Public Videos\_Updated\8-8-2015\20150809234216.m2ts"
[File:System]   FileModifyDate                  : 2015:08:09 22:42:15-10:00
[File:System]   FileAccessDate                  : 2015:08:09 22:42:15-10:00
[File:System]   FileCreateDate                  : 2015:08:09 22:42:15-10:00
[H264]          DateTimeOriginal                : 2015:08:09 23:42:15-09:00


If you think it will work after all of this, I'm up to installing perl, but it looks like there are a fair number of choices for Windows, so recommendations would be appreciated.  I confess I've never looked at perl, but I used to be decent at vbscript almost a decade ago if that helps. 

Thanks again. 

ganymede55

The attachment would not load so I sent you an email asking if I could email you directly with it.

Hayo Baan

Yes, please mail it to me directly.

Looking at what you need, I guess I have to enhance my script a little for you so the timezone info gets entered correctly too (for my own cameras the timezone info is not part of the DateTimeOriginal, but is placed in another tag). This isn't straightforward I'm afraid as you and the image are not in the same timezone and can use different daylight savings too... Anyway, I'll see what I can do, but first I have to get it to uniquely identify the DateTimeOriginal. That is the most important.

As for what perl to use, there are two distributions that are suggested on the perl website. Both are good and I have personally used ActiveState's version on Windows and remember how easy it was to install and use.
Hayo Baan – Photography
Web: www.hayobaan.nl

Hayo Baan

Hi Chris,

I was impatient and downloaded a sample .mts file from the internet  so I could have a look at the file structure already ;)

The bad news is that apart from dateTimeOriginal being stored in binary (I have already worked around that), about each half second of recording (?) there is a time recording, which is sequential... This means we can't just change it as it will likely break the video :( This probably also explains why Phil has such trouble supporting video (and then this is just one of the many formats)...

Sorry :(

(Perhaps the .m2ts is different in this respect, so please still send me one so I can investigate)

Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

The M2TS container format unfortunately has no metadata support, so the date/time information is extracted from the H264 video stream of these files.  As Hayo has said, editing this information is tricky, and not supported by ExifTool.

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

Hayo Baan

Hi Chris,

I got the .m2ts sample file and it has the same problem as the .mts I inspected earlier: there's a timestamp recorded twice every second :(

Quote from: Phil Harvey on January 02, 2016, 11:06:40 AM
The M2TS container format unfortunately has no metadata support, so the date/time information is extracted from the H264 video stream of these files.  As Hayo has said, editing this information is tricky, and not supported by ExifTool.

This actually got me thinking, if .m2ts is just a container perhaps you can use video editing software to wrap it in a different/another container that does support adding metadata?

Cheers,
Hayo
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Quote from: Hayo Baan on January 02, 2016, 11:12:08 AM
This actually got me thinking, if .m2ts is just a container perhaps you can use video editing software to wrap it in a different/another container that does support adding metadata?

Good idea.  The M2TS container is terrible.  I highly recommend converting to MP4 if you can find conversion software that will copy the video stream intact without recoding.

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

Hayo Baan

#14
Ok, I couldn't resist and spend some time at my matchDateTime script to be able to solve Chris' problem :D

I now have a version that will alter all timestamps in the sequence so should be safe to use. It also doesn't overwrite the original file (unless asked) and, for mts/m2ts files has the ability to alter the timezone and daylightsavings flag of the recording as well! (note though that exiftool currently doesn't show the daylightsavings flag, even though it is present).

Documentation:
NAME
       matchDateTime -- matches date/time info in movie files.

VERSION
       version 0.002

DESCRIPTION
       "matchDateTime" updates the date/time info in (movie) files.

       For "normal" movie files the maker note DateTimeOriginal dates (and any
       other matching dates) are updated with the date as set in the QuickTime
       CreateDate. It does this by simply replacing any string that exactly
       matches the DateTimeOriginal in the MakerNotes with the QuickTime
       CreateDate string. As extra precaution against false matches, the match
       is prefixed with the binary length marker and postfixed with the zero
       byte marker.

       MTS and M2TS files are handled specially, in that here we take the file
       modify date as the new target date and update all occurrences of the
       DateTimeOriginal with this. All sequential timestamps are updated as
       well. By default, the timezone information is left as was recorded by
       the camera, but you can change this by specifying a different timzezone
       (and optional daylight savings flag).

SYNOPSIS
         matchDateTime [-overwrite] [-tz TZ [-dst]] <Files>

OPTIONS
       -overwrite
           Overwrites the original (video) file instead of creating a new file
           with "_matchDateTime" added to the name.

       -tz TZ
           Use TZ as the new time zone. Specify the time zone in hours.

       -dst
           Indicates the daylight savings flag should be set when writing the
           new timezone information (only used when the "-tz" option is also
           specified).

AUTHOR
       Hayo Baan <info@hayobaan.com>

COPYRIGHT AND LICENSE
       This software is copyright (c) 2016 by Hayo Baan.

       This is free software; you can redistribute it and/or modify it under
       the same terms as the Perl 5 programming language system itself.


The perl script is attached to this post, please let me know if it works for you!

Please see later post for most current script!
Hayo Baan – Photography
Web: www.hayobaan.nl