Author Topic: Modify EXIF dates based on filename  (Read 274 times)

Dike

  • Newbie
  • *
  • Posts: 3
Modify EXIF dates based on filename
« on: February 09, 2020, 03:58:51 PM »
Hello, I'd like to modify EXIF dates of video files based on filename. I have multiple videos in a folder which share the same date format in its filenames.
For example, if the video was shot as of writing this post, the filename would be: Video.2020-09-02_21-54.00.mp4. The last two digits separated by a dot is an unnecessary number which isnt connected to a date by any way. How could I acompilish that? Do I need to edit all filenames to just pure date like 2020-09-02_21-54.mp4? Thanks!

Edit: I'd like to add that I am running exiftool on Windows

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3785
Re: Modify EXIF dates based on filename
« Reply #1 on: February 09, 2020, 04:16:13 PM »
Hello, I'd like to modify EXIF dates of video files based on filename.

One point to clarify, EXIF data is non-standard in video files. EXIF is only one type of metadata.  What you actually want to do is modify the Quicktime timestamps, most likely the CreateDate

Quote
For example, if the video was shot as of writing this post, the filename would be: Video.2020-09-02_21-54.00.mp4.

This is FAQ #5.  Your command would basically be this, replacing <FileOrDir> with the actual files and/or directories:
exiftool "-CreateDate<Filename" <FileOrDir>

Exiftool will take the first 14 numbers in the filename and create the time stamp out of that.  The extra numbers will be ignored as long as there aren't any number before the date/time in the filename.  If there are, then a modified command will be needed, but renaming the files won't be necessary.

Now, there is one thing to take note of.  That is that according to the spec, the timestamps in video files are supposed to be in UTC.  The above command will write the time stamp exactly as listed and not adjust it to the UTC.  This may make the time show incorrectly in some programs.  Windows, for example, will correctly read the time stamp as UTC and adjust it to the current time zone. Adobe programs do not adjust the time last time I heard (I probably should double check with Adobe Bridge).  If you wish to have exiftool adjust the time to UTC automatically, you can add the -api QuickTimeUTC option to the above command.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16687
    • ExifTool Home Page
Re: Modify EXIF dates based on filename
« Reply #2 on: February 10, 2020, 07:10:41 AM »
In StarGeek's command, the last 2 digits will be used for the seconds.  To set the seconds to zero instead, you could do something like this:

exiftool "-CreateDate<${Filename;s/\d+\.mp4/00/i}" FILE

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3785
Re: Modify EXIF dates based on filename
« Reply #3 on: February 10, 2020, 10:55:24 AM »
Ah, good catch.  I assumed that the full HourMinuteSecond was represented without actually making sure.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Dike

  • Newbie
  • *
  • Posts: 3
Re: Modify EXIF dates based on filename
« Reply #4 on: February 11, 2020, 12:49:28 PM »
Hey, I have tried running following command, but nothing has changed:
Code: [Select]
exiftool "-CreateDate<${Filename;s/\d+\.mp4/00/i}" Video.2011-23-07_11-10.00.mp4
Output:
Code: [Select]
Warning: No writable tags set from Video.2011-23-07_11-10.00.mp4
    0 image files updated
    1 image files unchanged

What could have gone wrong? Thanks.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3785
Re: Modify EXIF dates based on filename
« Reply #5 on: February 11, 2020, 01:24:08 PM »
If you are using Powershell, switch to CMD.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Dike

  • Newbie
  • *
  • Posts: 3
Re: Modify EXIF dates based on filename
« Reply #6 on: February 11, 2020, 05:57:19 PM »
Actually I was using CMD. I have tried to switch it to Powershell, but both generate same output.

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3785
Re: Modify EXIF dates based on filename
« Reply #7 on: February 11, 2020, 07:47:13 PM »
Oh, is that formatted as year-day-month?  That would be the problem. 

Try this
exiftool "-CreateDate<${Filename;/(\d{4})-(\d\d)-(\d\d)_(\d\d)-(\d\d)/;$_=$1.$3.$2.$4.$5.'00'}" Video.2011-23-07_11-10.00.mp4
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.