News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Modify EXIF dates based on filename

Started by Dike, February 09, 2020, 03:58:51 PM

Previous topic - Next topic

Dike

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

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.  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.
* 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).

Phil Harvey

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/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Ah, good catch.  I assumed that the full HourMinuteSecond was represented without actually making sure.
* 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).

Dike

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.

StarGeek

If you are using Powershell, switch to CMD.
* 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).

Dike

Actually I was using CMD. I have tried to switch it to Powershell, but both generate same output.

StarGeek

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
* 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).