Skip to content

timeconv

seconds2ts

seconds2ts(s: float) -> str

Convert seconds to timestamp in the format hh:mm:ss.xxx.

Source code in src/encode_utils_cli/util/timeconv.py
 4
 5
 6
 7
 8
 9
10
def seconds2ts(s: float) -> str:
    """Convert seconds to timestamp in the format `hh:mm:ss.xxx`."""
    m = s // 60
    s %= 60
    h = m // 60
    m %= 60
    return f"{h:02.0f}:{m:02.0f}:{s:06.3f}"

ts2seconds

ts2seconds(ts: str) -> float

Convert timestamp hh:mm:ss.xxxx to seconds.

Source code in src/encode_utils_cli/util/timeconv.py
13
14
15
16
def ts2seconds(ts: str) -> float:
    """Convert timestamp `hh:mm:ss.xxxx` to seconds."""
    h, m, s = map(float, ts.split(":"))
    return h * 3600 + m * 60 + s

seconds2f

seconds2f(s: float, fps: Fraction) -> int

Convert seconds to frames.

Source code in src/encode_utils_cli/util/timeconv.py
19
20
21
def seconds2f(s: float, fps: Fraction) -> int:
    """Convert seconds to frames."""
    return round(s * fps)

ts2f

ts2f(ts: str, fps: Fraction) -> int

Convert a timestamp hh:mm:ss.xxxx in number of frames.

Source code in src/encode_utils_cli/util/timeconv.py
24
25
26
def ts2f(ts: str, fps: Fraction) -> int:
    """Convert a timestamp `hh:mm:ss.xxxx` in number of frames."""
    return seconds2f(s=ts2seconds(ts), fps=fps)