Unlike photos, videos do not contain any internal metadata describing how/when/where they were first taken (EXIF data). Therefore, when exporting any kind of video from Apple Photos the files do not contain any information about when that video was actually taken.
My Android device / Google Photos gets around this by setting the Modification Time of the file to the date the video was taken. This is finnicky because if you, well, modify it later that date will change. But it’s better than nothing.
First I exported my videos from Apple Photos by clicking File > Export > Unmodified Originals
. On the window that pops up, you can check a box that exports the .xmp
files alongside the videos. Do that.
From these .xmp
files we can gleam the original shoot date and write that to the video file itself. Unfortunately the XML parser yq
could not work with the weirdly tagged nodes.
Python to the rescue:
import datetime
import glob
import os
import re
files = glob.glob("*.xmp")
for file in files:
with open(file) as f:
txt = f.read()
# Parse time from sidecar .xmp
foundTime = re.findall("<photoshop:DateCreated>(.*)<\/photoshop:DateCreated>", txt)
print(txt)
print(foundTime[0])
# Create epoch timestamp
newTimestamp = datetime.datetime.fromisoformat(foundTime[0])
newTime = int(newTimestamp.timestamp())
print (newTime)
# Find sibling .mp4 file, change modified timestamp
videoFile = glob.glob("*{}".format(file.replace(".xmp", ".mp4")))[0]
print(videoFile)
os.utime(videoFile, (newTime, newTime))
Depending on where the video was taken, you may want to alter the timestamp to account for a different timezone.