[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28722] trunk/blender/release/scripts/ modules/bpy/utils.py: utility functions
Campbell Barton
ideasman42 at gmail.com
Mon May 10 22:41:01 CEST 2010
Revision: 28722
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28722
Author: campbellbarton
Date: 2010-05-10 22:41:01 +0200 (Mon, 10 May 2010)
Log Message:
-----------
utility functions
bpy.utils.smpte_from_seconds(time)
bpy.utils.smpte_from_frame(frame)
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy/utils.py
Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py 2010-05-10 19:39:43 UTC (rev 28721)
+++ trunk/blender/release/scripts/modules/bpy/utils.py 2010-05-10 20:41:01 UTC (rev 28722)
@@ -332,3 +332,52 @@
'''
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
More information about the Bf-blender-cvs
mailing list