Timestamp-synchronized subtitle rendering.
Supports SRT and WebVTT formats. Subtitles are rendered as GPU overlays synchronized with the media clock.
Architecture:
Subtitle File → Parser → Cue Timeline → Clock Sync → GPU OverlayExample
{:ok, sub} = Dala.Media.Subtitle.load("subtitles.srt")
# In your screen's handle_info:
def handle_info({:clock, :tick, %{timestamp_us: ts}}, socket) do
case Dala.Media.Subtitle.active_cue(sub, ts) do
nil -> {:noreply, socket}
cue -> {:noreply, render_subtitle(socket, cue)}
end
end
Summary
Functions
Find the active cue for a given timestamp (in microseconds).
Get all cues that fall within a time range.
Parse SRT content into a list of cues.
Parse WebVTT content into a list of cues.
Format a cue for GPU overlay rendering.
Types
@type cue() :: %{ id: non_neg_integer(), start_ms: non_neg_integer(), end_ms: non_neg_integer(), text: String.t(), style: map() }
Functions
@spec active_cue([cue()], non_neg_integer()) :: cue() | nil
Find the active cue for a given timestamp (in microseconds).
@spec cues_in_range([cue()], non_neg_integer(), non_neg_integer()) :: [cue()]
Get all cues that fall within a time range.
@spec parse_srt(String.t()) :: parse_result()
Parse SRT content into a list of cues.
@spec parse_vtt(String.t()) :: parse_result()
Parse WebVTT content into a list of cues.
Format a cue for GPU overlay rendering.