Fix T45644: bpy.utils.smpte_from_frame drops frame
D1444 by @lichtwerk, with minor fix & docstring updates
This commit is contained in:
@@ -377,46 +377,31 @@ def preset_paths(subdir):
|
|||||||
|
|
||||||
def smpte_from_seconds(time, fps=None):
|
def smpte_from_seconds(time, fps=None):
|
||||||
"""
|
"""
|
||||||
Returns an SMPTE formatted string from the time in seconds: "HH:MM:SS:FF".
|
Returns an SMPTE formatted string from the *time*:
|
||||||
|
``HH:MM:SS:FF``.
|
||||||
|
|
||||||
If the *fps* is not given the current scene is used.
|
If the *fps* is not given the current scene is used.
|
||||||
|
|
||||||
|
:arg time: time in seconds.
|
||||||
|
:type time: int, float or ``datetime.timedelta``.
|
||||||
|
:return: the frame string.
|
||||||
|
:rtype: string
|
||||||
"""
|
"""
|
||||||
import math
|
|
||||||
|
|
||||||
if fps is None:
|
return smpte_from_frame(time_to_frame(time, fps=fps), fps)
|
||||||
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: # minutes
|
|
||||||
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):
|
def smpte_from_frame(frame, fps=None, fps_base=None):
|
||||||
"""
|
"""
|
||||||
Returns an SMPTE formatted string from the frame: "HH:MM:SS:FF".
|
Returns an SMPTE formatted string from the *frame*:
|
||||||
|
``HH:MM:SS:FF``.
|
||||||
|
|
||||||
If *fps* and *fps_base* are not given the current scene is used.
|
If *fps* and *fps_base* are not given the current scene is used.
|
||||||
|
|
||||||
:arg time: time in seconds.
|
:arg frame: frame number.
|
||||||
:type time: number or timedelta object
|
:type frame: int or float.
|
||||||
:return: the frame.
|
:return: the frame string.
|
||||||
:rtype: float
|
:rtype: string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if fps is None:
|
if fps is None:
|
||||||
@@ -425,7 +410,17 @@ def smpte_from_frame(frame, fps=None, fps_base=None):
|
|||||||
if fps_base is None:
|
if fps_base is None:
|
||||||
fps_base = _bpy.context.scene.render.fps_base
|
fps_base = _bpy.context.scene.render.fps_base
|
||||||
|
|
||||||
return smpte_from_seconds((frame * fps_base) / fps, fps)
|
sign = "-" if frame < 0 else ""
|
||||||
|
frame = abs(frame * fps_base)
|
||||||
|
|
||||||
|
return (
|
||||||
|
"%s%02d:%02d:%02d:%02d" % (
|
||||||
|
sign,
|
||||||
|
int(frame / (3600 * fps)), # HH
|
||||||
|
int((frame / (60 * fps)) % 60), # MM
|
||||||
|
int((frame / fps) % 60), # SS
|
||||||
|
int(frame % fps), # FF
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
def time_from_frame(frame, fps=None, fps_base=None):
|
def time_from_frame(frame, fps=None, fps_base=None):
|
||||||
@@ -435,7 +430,7 @@ def time_from_frame(frame, fps=None, fps_base=None):
|
|||||||
If *fps* and *fps_base* are not given the current scene is used.
|
If *fps* and *fps_base* are not given the current scene is used.
|
||||||
|
|
||||||
:arg frame: number.
|
:arg frame: number.
|
||||||
:type frame: the frame number
|
:type frame: int or float.
|
||||||
:return: the time in seconds.
|
:return: the time in seconds.
|
||||||
:rtype: datetime.timedelta
|
:rtype: datetime.timedelta
|
||||||
"""
|
"""
|
||||||
@@ -459,7 +454,7 @@ def time_to_frame(time, fps=None, fps_base=None):
|
|||||||
If *fps* and *fps_base* are not given the current scene is used.
|
If *fps* and *fps_base* are not given the current scene is used.
|
||||||
|
|
||||||
:arg time: time in seconds.
|
:arg time: time in seconds.
|
||||||
:type time: number or a datetime.timedelta object
|
:type time: number or a ``datetime.timedelta`` object
|
||||||
:return: the frame.
|
:return: the frame.
|
||||||
:rtype: float
|
:rtype: float
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user