Using the filename for Exif Media Created value?

Started by greddin, December 23, 2021, 10:39:01 AM

Previous topic - Next topic

greddin

I have a bunch videos where the filenames all begin with the date they were created.

Here's a sample of how they are named:

07-14-2011_14355.mp4
07-15-2011_15356.mp4
07-16-2011_15647.mp4
...

In Windows 10, the "Media Created" shows incorrectly as the date/time they were converted to mp4. Is there a way I can use Exiftool to update the Media Created date/time using each filename's beginning date in the names?

Also, is the "Media Created" field shown in Windows 10, the same thing as the Exif CreateDate field?

Thanks for your help!

greddin

Reading one of the other posts, I ran the following command on one of the video files.

exiftool -time:all -G1 -a FILE

This is the output:

P:\Videos\Handbrake Converted>exiftool -time:all -G1 -a "07-16-2011 143104.mp4"
[System]        File Modification Date/Time     : 2021:12:22 21:23:16-06:00
[System]        File Access Date/Time           : 2021:12:23 09:44:32-06:00
[System]        File Creation Date/Time         : 2021:12:22 19:59:08-06:00
[QuickTime]     Create Date                     : 2011:07:16 06:59:08
[QuickTime]     Modify Date                     : 2021:12:23 01:59:08
[Track1]        Track Create Date               : 2021:12:23 01:59:08
[Track1]        Track Modify Date               : 2021:12:23 01:59:08
[Track1]        Media Create Date               : 2021:12:23 01:59:08
[Track1]        Media Modify Date               : 2021:12:23 01:59:08
[Track2]        Track Create Date               : 2021:12:23 01:59:08
[Track2]        Track Modify Date               : 2021:12:23 01:59:08
[Track2]        Media Create Date               : 2021:12:23 01:59:08
[Track2]        Media Modify Date               : 2021:12:23 01:59:08
[XMP-exif]      Date/Time Digitized             : 2011:07:16 00:00:00
[XMP-exif]      Date/Time Original              : 2011:07:16 00:00:00


It appears the Ceate Date is still within the file's Exif information.  What would be the command to batch that (if possible)?

Thanks again.

StarGeek

Are the numbers after the underscore just random or are they supposed to relate to the time in some way?

Video metadata is part of the Quicktime group, not EXIF.  There is no standard for EXIF data in video files, but most camera manufacturers force it into the file anyway, which each manufacturer doing it a different way, sometimes even between different camera models.

Normally, the basic command to copy the time stamp from the filename into a video file would be this (see FAQ #5)
exiftool "-CreateDate<Filename" file.mp4
But the problem is that your date is not formatted from Year down to second so the date must be rearranged.  Also, it doesn't look like the numbers after the underscore indicate HoursMinutesSeconds, so a default time must be included.

Finally, the standard for video time stamps says that it must be in UTC (see the above Quicktime link), so it needs to be adjusted.

So for a starting command, I would try this
exiftool "-CreateDate<${Filename;m/(\d\d)-(\d\d)-(\d{4})/$3$2$1/} 00:00:00" -api QuickTimeUTC /path/to/files/

This sets a default time of midnight and assumes that the videos were taken in the same timezone as the computer running the command.  If the videos were taken in a different time zone, ignoring Standard/Daylight time differences, then you will need to manually adjust them while writing with something like this, where the -05:00 would be the timezone for the video.
exiftool "-CreateDate<${Filename;m/(\d\d)-(\d\d)-(\d{4})/$3$2$1/} 00:00:00-05:00" -api QuickTimeUTC /path/to/files/
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

greddin

Thank you for the help. I will give this a try. Do you know where the "Media Created" property comes from that Windows displays?

StarGeek

The CreateDate tag.

See this post for what tags Windows reads to fill various properties.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

greddin

I'm trying this command on one of the files as a test. But getting an error.  Here's the command and output.

P:\Videos\Handbrake Converted>exiftool "-CreateDate<${Filename;m/(\d\d)-(\d\d)-(\d{4})/$3$2$1/} 00:00:00" -api QuickTimeUTC "07-15-2011 173606-1.mp4"
Warning: syntax error for 'Filename' - 07-15-2011 173606-1.mp4
Warning: No writable tags set from 07-15-2011 173606-1.mp4
    0 image files updated
    1 image files unchanged

StarGeek

Oops, I wasn't paying attention.  I forgot part of the command.  And I mixed up substitute and match.  Most of the time a substitution is used, but because you want to drop everything but the date, a match would be better.

Try
exiftool "-CreateDate<${Filename;m/(\d\d)-(\d\d)-(\d{4})/;$_=$3.$1.$2} 00:00:00" -api QuickTimeUTC "07-15-2011 173606-1.mp4"

Example output.  I'm in a time zone which would be -07:00 at the time for this file, so the first output shows the raw data of 2011:07:15 07:00:00.  Adding the -api QuickTimeUTC option adjusts it to my correct local time of 2011:07:15 00:00:00-07:00.  This is the value that would be shown in the Windows "Media Created" property.
C:\>exiftool -P -overwrite_original "-CreateDate<${Filename;m/(\d\d)-(\d\d)-(\d{4})/;$_=$3.$1.$2} 00:00:00" -api QuickTimeUTC "Y:\!temp\bbbb\07-15-2011 173606-1.mp4"
    1 image files updated

C:\>exiftool -G -a -s -CreateDate "Y:\!temp\bbbb\07-15-2011 173606-1.mp4"
[QuickTime]     CreateDate                      : 2011:07:15 07:00:00
[XMP]           CreateDate                      : 2011:07:15 00:00:00

C:\>exiftool -G -a -s -CreateDate -api QuickTimeUTC "Y:\!temp\bbbb\07-15-2011 173606-1.mp4"
[QuickTime]     CreateDate                      : 2011:07:15 00:00:00-07:00
[XMP]           CreateDate                      : 2011:07:15 00:00:00


But if the 173606 part of the filename actually stands for a time of 17:36:06, then the command needs to be adjusted to include that.  Your first examples only included 5 digits, which wouldn't be a fully formed time, unless a leading 0 was dropped.  The later examples include 6 digits, which might be an HourMinuteSecond time stamp.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

greddin

Thank you StarGeek. That last command works great!  Honestly I'm not sure what the last six digits of my videos are.  They were originally created from a Panasonic camcorder as m2ts files. Is there anyway to test to see if this in fact a time signature?

Lastly, now that this works with a single file, what would be the command to point do a directory of videos?  Would it be the /path/to/files/ you had before?  Is it possible to do recursive folders?

Thanks again for your help today.

StarGeek

Quote from: greddin on December 23, 2021, 02:41:01 PMIs there anyway to test to see if this in fact a time signature?

Nothing beyond comparing the values to the results of the Time:All command you used, possibly adjusted for time zones.

Quotehat would be the command to point do a directory of videos?  Would it be the /path/to/files/ you had before?

Same command, just pass a directory instead of a file.  You can pass almost any number of combined directories and filenames, limited only by the command line length (something like 8,000 characters for Windows).

QuoteIs it possible to do recursive folders?

Add the -r (-recurse) option.  And follow up answer, add -overwrite_original option to suppress the creation of backup files.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

greddin

Hi StarGeek. I really appreciate your help yesterday.  I decided to rename my video files by yyyy-mm-dd now so they will sort better.

I realize I need to update the date matching now from what you gave me yesterday. I've tried rearranging the date but getting this error.  Could you assist me in getting the date matching rearranged correctly now?

exiftool -P -r -overwrite_original "-CreateDate<${Filename;m/(\d{4})-(\d\d)-(\d\d)-/;$_=$2.$3.$1} 00:00:00" -api QuickTimeUTC "2011-07-15 173606-1.mp4"
Warning: No writable tags set from 2011-07-15 173606-1.mp4
    0 image files updated
    1 image files unchanged


Thank you.

greddin

I played around with it some more, this command doesn't fail now but is putting in a Create Date of 2/26/1929.

exiftool -P -overwrite_original "-CreateDate<${Filename;m/(\d{4})-(\d\d)-(\d\d)/;$_=$3.$1.$2} 00:00:00" -api QuickTimeUTC "2011-07-15 173606-1.mp4"
    1 image files updated



greddin

After playing around with the command I got it working with this: 

exiftool -P -overwrite_original "-CreateDate<${Filename;m/(\d{4})-(\d\d)-(\d\d)/;$_=$1.$2.$3} 00:00:00" -api QuickTimeUTC "2011-07-15 173606-1.mp4"
    1 image files updated


I had the matching pattern wrong before and an extra dash.

Thanks again!

StarGeek

Quote from: greddin on December 24, 2021, 11:05:25 AMI decided to rename my video files by yyyy-mm-dd now so they will sort better.

Always a good move.

And doing so makes the command much simpler, as per the FAQ #5 link above
exiftool "-CreateDate<$Filename 00:00:00} -api QuickTimeUTC /path/to/files/
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

greddin

My files are named like this now:  2011-07-15 173606.mp4.  Assuming the last six digits is the 24 time would it be update my command to translate that into the Create Date as well? 

StarGeek

Oh yeah, forgot about the trailing digits.

But yes, exiftool will try to convert those last 6 digits into HoursMinutesSeconds.  If there are 5 trailing digits like in your first post, it will treat the first 2 as hours, second 2 as minutes, and last digit as seconds.

To strip off those trailing digits if needed, you could use the ${Filename;m/(\d{4})-(\d\d)-(\d\d)/;$_=$1.$2.$3} 00:00:00" you posted above.

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype