Skip to content

Instantly share code, notes, and snippets.

@khuangaf
Created August 26, 2018 12:48
Show Gist options
  • Save khuangaf/af7e9de7577959af84bda6bfe895a62c to your computer and use it in GitHub Desktop.
Save khuangaf/af7e9de7577959af84bda6bfe895a62c to your computer and use it in GitHub Desktop.
def second2timecode(time):
'''Convert second into time code for srt.'''
hours = time // 3600
time -= 3600 * hours
minutes = time // 60
time -= 60 * minutes
secs = np.floor(time % 60)
msecs = (time % 60 - secs) * 1000
timecode = "%02d:%02d:%02d,%03d" % (hours, minutes, secs, msecs)
return timecode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment