pub struct MediaTime {
nanos: i64,
}Expand description
One point on the media timeline. Resolution is nanoseconds.
Fields§
§nanos: i64Implementations§
Source§impl MediaTime
impl MediaTime
Sourcepub const fn from_nanos(nanos: i64) -> Self
pub const fn from_nanos(nanos: i64) -> Self
Construct from raw nanoseconds since origin (can be negative).
Sourcepub fn from_seconds(s: f64) -> Self
pub fn from_seconds(s: f64) -> Self
Construct from seconds since origin (f64).
Sourcepub fn from_sample(index: u64, sample_rate: u32) -> Self
pub fn from_sample(index: u64, sample_rate: u32) -> Self
Construct from an audio sample index at a given sample rate.
MediaTime::from_sample(48_000, 48_000) == 1 s.
Sourcepub fn from_frame(index: u64, frame_rate: f64) -> Self
pub fn from_frame(index: u64, frame_rate: f64) -> Self
Construct from a video frame index at a given frame rate (fps).
MediaTime::from_frame(90, 30.0) == 3 s.
Sourcepub fn as_seconds(self) -> f64
pub fn as_seconds(self) -> f64
Seconds since origin (f64).
Sourcepub fn to_sample(self, sample_rate: u32) -> i64
pub fn to_sample(self, sample_rate: u32) -> i64
Audio sample index at a given rate, rounded to nearest.
Rounding (vs truncation) keeps from_sample ↔ to_sample
exact round-trip for any sample rate that doesn’t divide 10⁹
evenly (e.g. 44_100 Hz produces non-integer nanoseconds per
sample; truncating would drift -1 every sample).
MediaTime::from_seconds(1.0).to_sample(48_000) == 48_000.
Sourcepub fn to_frame(self, frame_rate: f64) -> i64
pub fn to_frame(self, frame_rate: f64) -> i64
Video frame index at a given fps, rounded to nearest.
Same round-trip rationale as Self::to_sample.
Trait Implementations§
Source§impl Add<MediaDuration> for MediaTime
impl Add<MediaDuration> for MediaTime
Source§impl Ord for MediaTime
impl Ord for MediaTime
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for MediaTime
impl PartialOrd for MediaTime
Source§impl Sub<MediaDuration> for MediaTime
impl Sub<MediaDuration> for MediaTime
Source§impl Sub for MediaTime
impl Sub for MediaTime
Source§fn sub(self, rhs: MediaTime) -> MediaDuration
fn sub(self, rhs: MediaTime) -> MediaDuration
b - a returns the MediaDuration between two times.
Source§type Output = MediaDuration
type Output = MediaDuration
- operator.