Here is a Python script which converts an integer frame number to drop-frame SMPTE time code.
Suggestions for improvement, modifications and bug reports are welcome.
Code:# Code by David Heidelberger, adapted from Andrew Duncan # http://www.davidheidelberger.com/blog/?p=29 # Given an int called framenumber and a double called framerate # Framerate should be 29.97, 59.94, or 23.976, otherwise the calculations will be off. import time import math d = 0 m = 0 framerate = 30 / 1.001 #29.97 framenumber = 0 framePeriod = 1 / framerate while framenumber < 120: dropFrames = round(framerate * .066666) #Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate framesPerHour = round(framerate*60*60) #Number of frames in an hour framesPer24Hours = framesPerHour*24 #Number of frames in a day - timecode rolls over after 24 hours framesPer10Minutes = round(framerate * 60 * 10) #Number of frames per ten minutes framesPerMinute = (round(framerate)*60)- dropFrames #Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames if framenumber < 0: #Negative time. Add 24 hours. framenumber=framesPer24Hours+framenumber #If framenumber is greater than 24 hrs, next operation will rollover clock framenumber = framenumber % framesPer24Hours #% is the modulus operator, which returns a remainder. a % b = the remainder of a/b #d = framenumber\framesPer10Minutes # \ means integer division, which is a/b without a remainder. Some languages you could use floor(a/b) d = math.floor(framenumber/framesPer10Minutes) m = framenumber % framesPer10Minutes #In the original post, the next line read m>1, which only worked for 29.97. Jean-Baptiste Mardelle correctly pointed out that m should be compared to dropFrames. if m>dropFrames: framenumber=framenumber + (dropFrames*9*d) + math.floor(dropFrames*((m-dropFrames)/framesPerMinute)) else: framenumber = framenumber + dropFrames*9*d frRound = round(framerate) frames = framenumber % frRound seconds = math.floor(framenumber / frRound) % 60 minutes = math.floor(math.floor(framenumber / frRound) / 60) % 60 hours = math.floor(math.floor(math.floor(framenumber / frRound) / 60) / 60) print (round(hours),":",round(minutes),":",round(seconds),":",round(frames)) framenumber += 1 time.sleep(framePeriod)
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays!
+ Reply to Thread
Results 1 to 1 of 1
Thread
-
Last edited by chris319; 15th Jun 2019 at 15:25.
Similar Threads
-
Inlay Date and Time Code to AVI - Quality Loss?
By Genius in forum CapturingReplies: 1Last Post: 24th Feb 2019, 11:53 -
SMPTE 302m Audio
By criggs in forum EditingReplies: 0Last Post: 5th Jan 2018, 23:07 -
Php and Python help
By Gok in forum ProgrammingReplies: 0Last Post: 5th Nov 2015, 10:41 -
Set a file split based on duration or time code in MKVmerge
By loninappleton in forum EditingReplies: 3Last Post: 31st Oct 2015, 13:58 -
Python Photogrammetry Toolbox GUI
By Arch Lich in forum EditingReplies: 1Last Post: 2nd Mar 2015, 15:03