v5: refactor into modular stream_tools desktop app
Same inaSpeechSegmenter engine split into reusable core/ (fftools, segmenter, exporters) + utils/ and a CustomTkinter multi-tab UI. Adds JSON and ffmpeg-script export. Extracted from the stream_tools app. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
42
utils/formats.py
Normal file
42
utils/formats.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
Timecode & duration formatting utilities.
|
||||
"""
|
||||
|
||||
|
||||
def fmt_dur(seconds: float) -> str:
|
||||
"""Format a duration as H:MM:SS or M:SS for display."""
|
||||
if seconds < 0:
|
||||
return "…"
|
||||
if seconds == 0:
|
||||
return "—"
|
||||
s = int(round(seconds))
|
||||
h, rem = divmod(s, 3600)
|
||||
m, sec = divmod(rem, 60)
|
||||
return f"{h}:{m:02d}:{sec:02d}" if h else f"{m}:{sec:02d}"
|
||||
|
||||
|
||||
def fmt_elapsed(s: float) -> str:
|
||||
if s < 60:
|
||||
return f"{int(s)}s"
|
||||
m, sec = divmod(int(s), 60)
|
||||
return f"{m}m {sec:02d}s"
|
||||
|
||||
|
||||
def format_timecode(seconds: float) -> str:
|
||||
"""Format seconds as HH:MM:SS."""
|
||||
h = int(seconds // 3600)
|
||||
m = int((seconds % 3600) // 60)
|
||||
s = int(seconds % 60)
|
||||
return f"{h:02d}:{m:02d}:{s:02d}"
|
||||
|
||||
|
||||
def seconds_to_smpte(seconds: float, fps: float = 29.97) -> str:
|
||||
"""Convert seconds to SMPTE timecode HH:MM:SS:FF."""
|
||||
total_frames = int(seconds * fps)
|
||||
ff = total_frames % int(round(fps))
|
||||
total_seconds = total_frames // int(round(fps))
|
||||
ss = total_seconds % 60
|
||||
total_minutes = total_seconds // 60
|
||||
mm = total_minutes % 60
|
||||
hh = total_minutes // 60
|
||||
return f"{hh:02d}:{mm:02d}:{ss:02d}:{ff:02d}"
|
||||
Reference in New Issue
Block a user