diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-05-11 00:41:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-05-11 00:41:01 +0400 |
commit | daba1d23ff512ef0db32bdde3a26f120d3d9f024 (patch) | |
tree | a52b40f02207478f8f84ab3fee98333fa94f8f05 /release | |
parent | a2166e5bc14ddd20bb7b85a48eefefe267ba5201 (diff) |
utility functions
bpy.utils.smpte_from_seconds(time)
bpy.utils.smpte_from_frame(frame)
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/bpy/utils.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py index a3fee82e566..d56d25546f7 100644 --- a/release/scripts/modules/bpy/utils.py +++ b/release/scripts/modules/bpy/utils.py @@ -332,3 +332,52 @@ def preset_paths(subdir): ''' return (_os.path.join(_presets, subdir), ) + + +def smpte_from_seconds(time, fps=None): + ''' + Returns an SMPTE formatted string from the time in seconds: "HH:MM:SS:FF". + + If the fps is not given the current scene is used. + ''' + import math + + if fps is None: + fps = _bpy.context.scene.render.fps + + hours = minutes = seconds = frames = 0 + + if time < 0: + time = -time + neg = "-" + else: + neg = "" + + if time >= 3600.0: # hours + hours = int(time / 3600.0) + time = time % 3600.0 + if time >= 60.0: # mins + minutes = int(time / 60.0) + time = time % 60.0 + + seconds = int(time) + frames= int(round(math.floor( ((time - seconds) * fps)))) + + return "%s%02d:%02d:%02d:%02d" % (neg, hours, minutes, seconds, frames) + + +def smpte_from_frame(frame, fps=None, fps_base=None): + ''' + Returns an SMPTE formatted string from the frame: "HH:MM:SS:FF". + + If the fps and fps_base are not given the current scene is used. + ''' + + if fps is None: + fps = _bpy.context.scene.render.fps + + if fps_base is None: + fps_base = _bpy.context.scene.render.fps_base + + return smpte_from_seconds((frame * fps_base) / fps, fps) +
\ No newline at end of file |