Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mr. Mohon

macrumors newbie
Original poster
May 10, 2022
12
0
Hi.
Im trying to find or create an automator script to change MP4 files created date to match the date found in the EXIF/Metadata. When I download it from the cloud the date no longer matches the date the file was originally created. I get and understand why it doesn't but what I am looking for is a solution on how to change this easily using automator. Has anyone done this yet?
 
To save you a few keystrokes from the article in the link use :

Bash:
mdls -name kMDItemContentCreationDate /path/to/myfile.mp4

No need for grep and head.
 
kMDItemContentCreationDate might not always be a great value to use, but it's an option.

For example, if I look at a podcast I downloaded, I get this value:

Code:
kMDItemContentCreationDate             = 2022-05-09 18:19:27 +0000

Timestamp of when I downloaded it. But the release date of the podcast in Podcasts database is May 08, 2022 @ 21:00, which is more important for my podcasts use-case.

Other option: once one has a time value, can use the touch command to change the timestamps.

Code:
#
# set file timestamp to midnight
#
touch -t 202205110000 /path/to/the/file.mp3
 
Thank you. Since I do feel that it is important to share that I am doing this to videos, more specifically GoPro videos. The camera automatically uploads to the cloud but when I download from the cloud to my computer it has the download date as the created date (again I understand why this is happening). This makes organizing the videos almost impossible.

I did notice the above link to the video from macmost.com but I did not have success with it changing the creation date on a video like it did for a photo. I have tried but it does not change it to the correct date. It actually changed it to one hour later than when it was downloaded. So I adjusted the time zone adjustment form 6 to 7 and that gets the time zone right but it still only finds and uses the downloaded date.
 
It does work perfectly for the photos I took using the same camera but not for the videos.
 
At this point, I think we'll need to see what metadata is available for at least one of the MP4 files.

First, try this. It lists the metadata atttributes dealing with creation. Please copy and paste the output in a reply here.
Code:
mdls /path/to/myfile.mp4 | grep -i creat

Here's example output from a JPEG file of mine:
Code:
kMDItemContentCreationDate     = 2018-07-26 10:27:25 -0700
kMDItemFSCreationDate          = 2018-07-26 17:27:24 -0700
kMDItemFSCreatorCode           = ""
Note the 1-sec difference in the seconds field. A lot of other files I tried have both values the same. Only a few have the small difference like this one, and never differ by more than 1 sec.

If all you get for every MP4 file is the same timestamp in both values, then I suspect the metadata isn't being extracted from the file properly, or isn't even being identified properly, so it's only using the file-creation date. If that's the case, then a different strategy will be needed. I don't know what that might be off the top of my head, but it may involve utilities like ExifTool.
 
Here's the output:


kMDItemContentCreationDate = 2022-04-18 06:09:00 +0000


kMDItemContentCreationDate_Ranking = 2022-04-18 00:00:00 +0000


kMDItemFSCreationDate = 2022-04-18 06:09:00 +0000


kMDItemFSCreatorCode = ""
 
When I run that same line of code on a photo taken only minutes before a video I get this output:



kMDItemContentCreationDate = 2022-01-17 19:54:26 +0000


kMDItemContentCreationDate_Ranking = 2022-01-17 00:00:00 +0000


kMDItemCreator = "H21.01.01.20.00"


kMDItemFSCreationDate = 2022-04-18 06:11:50 +0000


kMDItemFSCreatorCode = ""
 
Here's the output:

kMDItemContentCreationDate = 2022-04-18 06:09:00 +0000
kMDItemContentCreationDate_Ranking = 2022-04-18 00:00:00 +0000
kMDItemFSCreationDate = 2022-04-18 06:09:00 +0000
kMDItemFSCreatorCode = ""
This definitely looks like it's using the FSCreationDate as the ContentCreationDate.

When I run that same line of code on a photo taken only minutes before a video I get this output:

kMDItemContentCreationDate = 2022-01-17 19:54:26 +0000
kMDItemContentCreationDate_Ranking = 2022-01-17 00:00:00 +0000
kMDItemCreator = "H21.01.01.20.00"
kMDItemFSCreationDate = 2022-04-18 06:11:50 +0000
kMDItemFSCreatorCode = ""
Here, however, we see very different values for ContentCreationDate and FSCreationDate.

To me, this looks like the metadata extraction doesn't see any valid ContentCreationDate metadata in the MP4 file, so it falls back to the FSCreationDate, which is going to be when the file was downloaded.


I think your next step is to use something like ExifTool to see if there's a usable ContentCreationDate embedded in the MP4 file. According to its Wikipedia page, it can extract things from MP4 files:
 
What @chown33 said re: exiftool, but that too might not be a complete picture, as per their matrix, video formats are hit/miss what might be accessible for metadata. So might need to dive deeper into what the MP4 container has buried deep in it (eg. Office documents are really zip files with stuff buried in it).
 
First off I would like to stop and say thanks everyone for the help so far. I have downloaded the ExifTool and started messing around with it. After watching a quick video and running the same file as earlier here is the output.
ExifTool Version Number : 12.41
File Name : GX010108.MP4
Directory : /Users/todd/Desktop/Test Folder (All files are duplicates)
File Size : 105 MiB
File Modification Date/Time : 2022:04:17 23:09:00-07:00
File Access Date/Time : 2022:05:11 18:02:26-07:00
File Inode Change Date/Time : 2022:05:11 16:45:10-07:00
File Permissions : -rwxr-xr-x
File Type : MP4
File Type Extension : mp4
MIME Type : video/mp4
Major Brand : MP4 Base Media v1 [IS0 14496-12:2003]
Minor Version : 0.2.0
Compatible Brands : isom, iso2, avc1, mp41
Movie Header Version : 0
Create Date : 2022:01:17 10:39:06
Modify Date : 2022:01:17 10:39:06
Time Scale : 60000
Duration : 0:01:01
Preferred Rate : 1
Preferred Volume : 100.00%
Preview Time : 0 s
Preview Duration : 0 s
Poster Time : 0 s
Selection Time : 0 s
Selection Duration : 0 s
Current Time : 0 s
Next Track ID : 5
Track Header Version : 0
Track Create Date : 2022:01:17 10:39:06
Track Modify Date : 2022:01:17 10:39:06
Track ID : 1
Track Duration : 0:01:01
Track Layer : 0
Track Volume : 0.00%
Image Width : 1920
Image Height : 1080
Graphics Mode : ditherCopy
Op Color : 32768 32768 32768
Compressor ID : avc1
Source Image Width : 1920
Source Image Height : 1080
X Resolution : 72
Y Resolution : 72
Bit Depth : 24
Color Representation : nclx 1 1 1
Buffer Size : 1875000
Max Bitrate : 15000000
Average Bitrate : 14148334
Video Frame Rate : 59.94
Time Code : 3
Balance : 0
Audio Format : mp4a
Audio Channels : 2
Audio Bits Per Sample : 24
Audio Sample Rate : 48000
Text Font : Unknown (21)
Text Face : Plain
Text Size : 10
Text Color : 0 0 0
Background Color : 65535 65535 65535
Font Name : Courier
Other Format : tmcd
Other Name :
Matrix Structure : 1 0 0 0 1 0 0 0 1
Media Header Version : 0
Media Create Date : 2022:01:17 10:39:06
Media Modify Date : 2022:01:17 10:39:06
Media Time Scale : 1000
Media Duration : 0:01:02
Handler Class : Media Handler
Handler Type : NRT Metadata
Handler Vendor ID : Apple
Handler Description : GoPro MET
Gen Media Version : 0
Gen Flags : 0 0 0
Gen Graphics Mode : ditherCopy
Gen Op Color : 32768 32768 32768
Gen Balance : 0
Meta Format : gpmd
Warning : [minor] The ExtractEmbedded option may find more tags in the media data
Metadata Version : 8.1.5
Firmware Version : H21.01.01.20.00
Camera Serial Number : C3461325091152
Camera Model Name : HERO10 Black
Media Unique ID : 765fa2491ca405f8e455ae52842f6e1f00000000000000000000000000000000
Auto Rotation : Up
Digital Zoom : No
Pro Tune : On
White Balance : AUTO
Sharpness : MED
Color Mode : NATURAL
Maximum Shutter Angle : AUTO
Auto ISO Max : 1600
Auto ISO Min : 100
Exposure Compensation : 0.0
Rate :
Field Of View : Super View
Sensor Readout Time : 16.0110015869141
Electronic Image Stabilization : HS EIS
Audio Setting : AUTO
Device Name : Highlights
Camera Serial Number Hash : 49a25f76f805a41c52ae55e41f6e2f84
Lens Serial Number : LKO1072802402800
Media Data Size : 110303933
Media Data Offset : 185058
Image Size : 1920x1080
Megapixels : 2.1
Avg Bitrate : 14.4 Mbps
Rotation : 0
 
As seen about 15 lines down is "Create Date : 2022:01:17 10:39:06", that is the date and time I am trying to change the files "Date Created" too.
 
Code:
touch -t `exiftool -CreateDate -d "%Y%m%d%H%M.%S" -s3 file.mp4` file.mp4
 
Code:
touch -t `exiftool -CreateDate -d "%Y%m%d%H%M.%S" -s3 file.mp4` file.mp4
Thank you for your help. I think we are getting close. I am struggling with where I input the file path into that line of code. I am still very new at this.
 
Substitute "file.mp4" with the file path. To be safe, put double quotes around the names:

Code:
touch -t `exiftool -CreateDate -d "%Y%m%d%H%M.%S" -s3 "/path/to/file.mp4"` "/path/to/file.mp4"
 
Substitute "file.mp4" with the file path. To be safe, put double quotes around the names:

Code:
touch -t `exiftool -CreateDate -d "%Y%m%d%H%M.%S" -s3 "/path/to/file.mp4"` "/path/to/file.mp4"
Thank you, this worked perfectly. Now how do I make this into an automator workflow?

Can I replace a part of the below code with something like the above code to make the automator workflow? Below is the one MacMost.com used for photos.
Code:
for f in "$@"
do
    touch -t $(date -j -f "%Y%m%d%H%M" -v-7H $(mdls $f | grep kMDItemContentCreationDate | head -n1 | awk '{gsub("[^[:digit:]]+"," ");print $1$2$3$4$5}') +%Y%m%d%H%M) $f
done
 
Not an Automator guy, but looks like everything between $() can be replaced with the exiftool command sequence.
 
I'm going to ask about this on apples forums to see if someone on there can help with creating the automator workflow. Thank you NoBoMac for all of the help getting me to where I am now.
 
Thank you. It came back with this error.
 

Attachments

  • Screen Shot 2022-05-13 at 7.00.27 AM.png
    Screen Shot 2022-05-13 at 7.00.27 AM.png
    62 KB · Views: 113
Put the full path in the script
Code:
for f in "$@"
do
   touch -t $(/usr/local/bin/exiftool -CreateDate -d "%Y%m%d%H%M.%S" -s3 "$f") "$f"
done
 
Hello everyone, @Mr. Mohon @NoBoMac @kryten2 @chown33 thank you so much, your discussion here helped me a lot!!!
Code:
for f in "$@"
do
   touch -t $(/usr/local/bin/exiftool -CreateDate -d "%Y%m%d%H%M.%S" -s3 "$f") "$f"
done

This Automator code from @bogdanw worked very well for me, but I need it to be able to do one more thing: To adjust the time!

On Garys code, for adjusting photos with Automator, I am able to add or subtract the time with "+" or "-" and time before H (v-6H):

Code:
for f in "$@"
do
    touch -t $(date -j -f "%Y%m%d%H%M" -v-6H $(mdls $f | grep kMDItemContentCreationDate | head -n1 | awk '{gsub("[^[:digit:]]+"," ");print $1$2$3$4$5}') +%Y%m%d%H%M) $f
done

How can I integrate ''-v-6H'' to the Automator code from @bogdanw to adjust the video time?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.