On my last vacation, I have shot a bunch of videos with two cameras. The problem was that camera #1 time was set to one hour later than camera #2. So in order for the videos to show up correctly in my video editing software, I needed to fix that.
I use OSX and could not find a quick way to do this. If you have XCode
installed, this will come with SetFile, a command line utility that can change file creation dates. Note that SetFile
can change either the file creation date, or the file modification date, but not both at the same time. Also note that SetFile
expects dates in American notation…
Anyways, here’s a small Python script that changes the file creation time of a bunch of video files (which names contain string “P14”):
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import datetime def modify_file_creation_date(path='.'): """ Alter the creation and modification time (set it one hour earlier) of all files named *P14* in path """ files = [] # r=root, d=directories, f = files for r, d, f in os.walk(path): for file in f: if "P14" in file: # get creation date and time date = (os.path.getctime(file)) # create a new date, just one hour earlier new_date = datetime.datetime.fromtimestamp(date) - datetime.timedelta(minutes=60) print("File %s - ORIGINAL DATETIME: %s - NEW DATETIME: %s\n" %(file, datetime.datetime.fromtimestamp(date), new_date )) # set the file creation date with the "-d" switch, which presumably stands for "dodification" os.system('SetFile -d "{}" {}'.format(new_date.strftime('%m/%d/%Y %H:%M:%S'), file)) # set the file modification date with the "-m" switch os.system('SetFile -m "{}" {}'.format(new_date.strftime('%m/%d/%Y %H:%M:%S'), file)) modify_file_creation_date()