pub struct Timecode { /* private fields */ }Expand description
A position within one 24-hour timecode day at a FrameRate.
The position is a frame count from 00:00:00:00, so arithmetic is exact and drop-frame labels
only matter when parsing and formatting. Arithmetic wraps at midnight in both directions.
use smpte_timecode::{FrameRate, Timecode};
let start = Timecode::parse("00:00:59;29", FrameRate::FPS_29_97_DF)?;
assert_eq!(start.frames(), 1799);
assert_eq!(start.wrapping_add_frames(1).to_string(), "00:01:00;02");Implementations§
Source§impl Timecode
impl Timecode
Sourcepub const fn from_frames(
frames: u32,
rate: FrameRate,
) -> Result<Self, TimecodeError>
pub const fn from_frames( frames: u32, rate: FrameRate, ) -> Result<Self, TimecodeError>
The position frames frames after 00:00:00:00.
§Errors
TimecodeError::FrameOutOfRange when frames is not below
FrameRate::frames_per_day.
Sourcepub const fn from_fields(
fields: Fields,
rate: FrameRate,
) -> Result<Self, TimecodeError>
pub const fn from_fields( fields: Fields, rate: FrameRate, ) -> Result<Self, TimecodeError>
The position that fields label at rate.
§Errors
TimecodeError::FieldOutOfRange for a field outside its range and
TimecodeError::DroppedLabel for a label drop-frame counting skips.
Sourcepub const fn parse(text: &str, rate: FrameRate) -> Result<Self, TimecodeError>
pub const fn parse(text: &str, rate: FrameRate) -> Result<Self, TimecodeError>
Parses HH:MM:SS:FF. Drop-frame rates also accept HH:MM:SS;FF. The frame field has two
or three digits. Surrounding whitespace is not accepted.
§Errors
TimecodeError::InvalidSyntax for any other shape, TimecodeError::DropFrameSeparator
for ; at a non-drop-frame rate, and the errors of Timecode::from_fields.
Sourcepub const fn from_seconds(
seconds: Ratio,
rate: FrameRate,
rounding: Rounding,
) -> Result<Self, TimecodeError>
pub const fn from_seconds( seconds: Ratio, rate: FrameRate, rounding: Rounding, ) -> Result<Self, TimecodeError>
The position at seconds after midnight, rounded to a whole frame.
§Errors
TimecodeError::FrameOutOfRange when the rounded frame falls outside the day.
Sourcepub const fn from_samples(
samples: u64,
sample_rate: Ratio,
rate: FrameRate,
rounding: Rounding,
) -> Result<Self, TimecodeError>
pub const fn from_samples( samples: u64, sample_rate: Ratio, rate: FrameRate, rounding: Rounding, ) -> Result<Self, TimecodeError>
The position of sample samples at sample_rate samples per second, rounded to a whole
frame. Pass a pulled sample rate from Pull::apply for pulled audio.
§Errors
TimecodeError::ZeroSampleRate for a zero sample_rate, TimecodeError::Overflow
when the exact product does not fit in 128 bits, and TimecodeError::FrameOutOfRange
when the rounded frame falls outside the day.
Sourcepub const fn wrapping_add_frames(self, delta: i64) -> Self
pub const fn wrapping_add_frames(self, delta: i64) -> Self
The position delta frames later, or earlier for a negative delta, wrapping at midnight.
Sourcepub const fn to_seconds(self) -> Ratio
pub const fn to_seconds(self) -> Ratio
The exact time since midnight in seconds.
use smpte_timecode::{FrameRate, Ratio, Timecode};
let hour = Timecode::parse("01:00:00:00", FrameRate::FPS_23_976)?;
assert_eq!(hour.to_seconds(), Ratio::new(18_018, 5)?); // 3603.6 sSourcepub const fn to_samples(
self,
sample_rate: Ratio,
rounding: Rounding,
) -> Result<u64, TimecodeError>
pub const fn to_samples( self, sample_rate: Ratio, rounding: Rounding, ) -> Result<u64, TimecodeError>
The sample at this position for sample_rate samples per second, rounded to a whole
sample. NTSC rates rarely land on a whole sample, so the rounding is part of the call.
use smpte_timecode::{FrameRate, Ratio, Rounding, Timecode};
let hour = Timecode::parse("01:00:00;00", FrameRate::FPS_29_97_DF)?;
let rate = Ratio::from_integer(48_000);
// Exactly 172 799 827.2 samples.
assert_eq!(hour.to_samples(rate, Rounding::Down)?, 172_799_827);
assert_eq!(hour.to_samples(rate, Rounding::Up)?, 172_799_828);§Errors
TimecodeError::Overflow when the sample does not fit in u64.