Skip to main content

CaptionTrack

Struct CaptionTrack 

Source
pub struct CaptionTrack { /* private fields */ }
Expand description

An immutable, bounded caption timeline with handwritten SRT interchange.

Build or parse outside frame callbacks. Sampling scans at most 16,384 cues, preserving input order and overlaps without sorting or previous-frame state. Layer construction and overlapping-label placement belong to the caller.

use motion_content::captions::*;
use motion_core::prelude::*;
let captions = CaptionTrack::from_srt("1\n00:00:01,000 --> 00:00:03,000\nLight takes time.\n")?;
let time = Time::from_frame(30, FrameRate::from(30));
assert_eq!(
    captions.active_at_time(time).next().unwrap().text(),
    "Light takes time."
);
assert!(captions.to_srt()?.starts_with("1\n00:00:01,000"));

Implementations§

Source§

impl CaptionTrack

Source

pub fn new( cues: impl IntoIterator<Item = CaptionCue>, ) -> Result<Self, ValidationError>

Keeps input order, including overlaps and unsorted times; empty input is valid. Rejects more than 16,384 cues or over 8 MiB of aggregate UTF-8 text. Cloning a track clones its text; it does not share mutable playback state.

Source

pub fn cues(&self) -> &[CaptionCue]

Returns immutable cues in their original input order.

Source

pub fn active_at(&self, time: Duration) -> impl Iterator<Item = &CaptionCue>

Samples an explicit time in the same half-open interval and input order.

Source

pub fn active_at_time(&self, time: Time) -> impl Iterator<Item = &CaptionCue>

Samples signed ticks exactly, without rounding through nanoseconds. Negative times contain no captions. Cue intervals remain half-open.

Source

pub fn from_srt(source: &str) -> Result<Self, ValidationError>

Parses at most 8 MiB of UTF-8 SRT, with optional leading BOM and LF/CRLF.

Requires unsigned u64 cue identifiers and HH:MM:SS,mmm --> HH:MM:SS,mmm; hours have at least two digits, minutes/seconds are below 60. Identifiers need not be consecutive or unique. Blank lines separate cues; surrounding blank lines and horizontal whitespace around identifiers/arrows are allowed. Multiline bodies and literal markup are preserved; timing/layout extensions are rejected. Syntax/limits return InvalidData with a one-based line number. Empty input is a valid empty track. No files are read during sampling.

Source

pub fn to_srt(&self) -> Result<String, ValidationError>

Serializes canonical SRT with sequential one-based identifiers and LF lines. Preserves cue order/text/times; does not sort or retain original identifiers. Rejects sub-millisecond times rather than rounding, and output over 8 MiB. No file writes, subtitle muxing or audio mixing are performed.

Trait Implementations§

Source§

impl Clone for CaptionTrack

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CaptionTrack

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CaptionTrack

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for CaptionTrack

Source§

impl PartialEq for CaptionTrack

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CaptionTrack

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.