framerate = 60
def _seconds(value):
if isinstance(value, str): # value seems to be a timestamp
_zip_ft = zip((3600, 60, 1, 1/framerate), value.split(':'))
return sum(f * float(t) for f,t in _zip_ft)
elif isinstance(value, (int, float)): # frames
return value / framerate
else:
return 0
def _timecode(seconds):
return '{h:02f}:{m:02f}:{s:02f}:{f:02f}'.format(h=int(seconds/3600),m=int(seconds/60%60),s=int(seconds%60),f=round((seconds-int(seconds))*framerate))
def _frames(seconds):
return seconds * framerate
def timecode_to_frames(timecode, start=None):
return _frames(_seconds(timecode) - _seconds(start))
def frames_to_timecode(frames, start=None):
return _timecode(_seconds(frames) + _seconds(start))
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme