ExifTool Forum

ExifTool => Newbies => Topic started by: Dike on February 09, 2020, 03:58:51 PM

Title: Modify EXIF dates based on filename
Post by: Dike 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
Title: Re: Modify EXIF dates based on filename
Post by: StarGeek on February 09, 2020, 04:16:13 PM
Quote from: Dike on February 09, 2020, 03:58:51 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

QuoteFor 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 (https://exiftool.org/faq.html#Q5).  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 (https://exiftool.org/ExifTool.html#QuickTimeUTC) to the above command.
Title: Re: Modify EXIF dates based on filename
Post by: Phil Harvey 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
Title: Re: Modify EXIF dates based on filename
Post by: StarGeek on February 10, 2020, 10:55:24 AM
Ah, good catch.  I assumed that the full HourMinuteSecond was represented without actually making sure.
Title: Re: Modify EXIF dates based on filename
Post by: Dike on February 11, 2020, 12:49:28 PM
Hey, I have tried running following command, but nothing has changed: exiftool "-CreateDate<${Filename;s/\d+\.mp4/00/i}" Video.2011-23-07_11-10.00.mp4

Output:

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.
Title: Re: Modify EXIF dates based on filename
Post by: StarGeek on February 11, 2020, 01:24:08 PM
If you are using Powershell, switch to CMD.
Title: Re: Modify EXIF dates based on filename
Post by: Dike 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.
Title: Re: Modify EXIF dates based on filename
Post by: StarGeek 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