In previous article I wrote about fixing ‘created’ metadata for images but there is one topic I didn’t finish there - fixing metadata for movies (see problem number 3 there). I didn’t finish it, because it wasn’t as simple as two ther commands. Or it was, but I chose different way.

So my problem was: some movies recorded with my phone have incorrect ‘created’ metadata, even though its name (which contains time) is correct. For example, movie has metadata TrackCreateDate (note, this is another tag than for images) with date 2018:10:18 17:06:36 but file name is 20181018_180636.mp4 which indicates 18:06:36. So one hour difference. If you are serious about for photos/movies ordering, that one hour really makes a difference.

And now we cannot just copy metadata from one tag to another, as there is not one correct tag. CreatedTime/FileModifyDate is wrong (as always on MacOS) and TrackCreateDate is slightly shifted. It complicates things a bit, so I decided to come back to Ruby like in good ol’ times and write simple script for this.

Ruby script to the rescue

Here it is: Movies exif time fix

I decided to write my own thing, because if file name format changes (as it may with different phones), then it would be really easy to change regular expression and date/time parsing. Not that I’m good at regular expressions (who is?) but I’m pretty good at googling them.

So what this script does is:

  1. Look for mp4 files in current folder which has desired name format (e.g. 20181018_180636.mp4)
  2. Read correct date and time from file name, i.e. go from 20181018_180636.mp4 to 2018:10:18 18:06:36
  3. Suggest change in movie metadata - both FileModifyDate and TrackCreateDate. User input is required to make sure that overriding is correct.
  4. If user agrees to changing file, file is changed.
  5. Correct movie metadata!

I tried to make this script extensible and easy to modify, so feel free to take it and change it as you like. It uses ExifTool under the hood so it can be also easily adjusted to modify photos based on their names. Fortunately, photos are usually not that broken, so standard ExifTool commands should suffice.

On ending note: by no means I’m EXIF and Ruby expert (but it was fun!), so if you can find anything that can be improved, feel free to point it out!