Skip to content

Instantly share code, notes, and snippets.

@Lily418
Last active November 9, 2018 12:04
Show Gist options
  • Save Lily418/340c8752a275096a0ca80f2c8388eb3c to your computer and use it in GitHub Desktop.
Save Lily418/340c8752a275096a0ca80f2c8388eb3c to your computer and use it in GitHub Desktop.
Python 3 script for OSX and using mediainfo to get duration and assuming file creation time is the same as the video's end date calculates the time a video was recorded.
import os
import subprocess
import sys
import datetime
filePath = sys.argv[1]
print(filePath)
# Assume file creation date is video start time, this may not be true for all platforms
# and won't be true if file had been transfered in a way which loses this infomation
videoStartTime = datetime.datetime.fromtimestamp(os.stat(sys.argv[1]).st_birthtime)
fileDuration = int(subprocess.getoutput(f" mediainfo --Inform=\"General;%Duration%\" {filePath}"))
videoEndTime = videoStartTime + datetime.timedelta(milliseconds=fileDuration)
print("Duration: " + str(fileDuration) + " milliseconds")
print("Start Time: " + str(videoStartTime.isoformat()))
print("End Time: " + str(videoEndTime.isoformat()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment