pub struct Timecode {
pub hours: u8,
pub minutes: u8,
pub seconds: u8,
pub frames: u8,
pub frame_rate: FrameRateInfo,
pub user_bits: u32,
/* private fields */
}Expand description
SMPTE timecode structure
The frame_count_cache field stores the pre-computed total frame count
from midnight, avoiding recomputation on repeated calls to to_frames().
It is excluded from equality comparison and serialization so it does not
affect timecode identity or wire format.
Fields§
§hours: u8Hours (0-23)
minutes: u8Minutes (0-59)
seconds: u8Seconds (0-59)
frames: u8Frames (0 to frame_rate - 1)
frame_rate: FrameRateInfoFrame rate
user_bits: u32User bits (32 bits)
Implementations§
Source§impl Timecode
impl Timecode
Sourcepub fn new(
hours: u8,
minutes: u8,
seconds: u8,
frames: u8,
frame_rate: FrameRate,
) -> Result<Self, TimecodeError>
pub fn new( hours: u8, minutes: u8, seconds: u8, frames: u8, frame_rate: FrameRate, ) -> Result<Self, TimecodeError>
Create a new timecode
Sourcepub fn from_string(
s: &str,
frame_rate: FrameRate,
) -> Result<Self, TimecodeError>
pub fn from_string( s: &str, frame_rate: FrameRate, ) -> Result<Self, TimecodeError>
Parse a SMPTE timecode string.
Accepts both “HH:MM:SS:FF” (non-drop frame, all colons) and “HH:MM:SS;FF” (drop frame, semicolon before frames).
The frame_rate parameter determines the frame rate; the separator
before the frame field determines whether drop-frame validation applies.
§Errors
Returns an error if the string format is invalid or component values are out of range.
Sourcepub fn from_raw_fields(
hours: u8,
minutes: u8,
seconds: u8,
frames: u8,
fps: u8,
drop_frame: bool,
user_bits: u32,
) -> Self
pub fn from_raw_fields( hours: u8, minutes: u8, seconds: u8, frames: u8, fps: u8, drop_frame: bool, user_bits: u32, ) -> Self
Create a Timecode directly from raw fields without constructor validation.
This is intended for internal use in parsers and codecs where the
component values have already been validated by the caller.
The frame_count_cache is computed automatically.
Sourcepub fn with_user_bits(self, user_bits: u32) -> Self
pub fn with_user_bits(self, user_bits: u32) -> Self
Create timecode with user bits
Sourcepub fn to_frames(&self) -> u64
pub fn to_frames(&self) -> u64
Convert to total frames since midnight.
Returns the cached value computed at construction time — O(1).
Sourcepub fn to_seconds_f64(&self) -> f64
pub fn to_seconds_f64(&self) -> f64
Convert this timecode to elapsed wall-clock seconds as f64.
For pull-down rates (23.976, 29.97, 47.952, 59.94) the exact rational frame rate is used so the result is frame-accurate.
Sourcepub fn from_frames(
frames: u64,
frame_rate: FrameRate,
) -> Result<Self, TimecodeError>
pub fn from_frames( frames: u64, frame_rate: FrameRate, ) -> Result<Self, TimecodeError>
Create from total frames since midnight
Sourcepub fn increment(&mut self) -> Result<(), TimecodeError>
pub fn increment(&mut self) -> Result<(), TimecodeError>
Increment by one frame
Sourcepub fn decrement(&mut self) -> Result<(), TimecodeError>
pub fn decrement(&mut self) -> Result<(), TimecodeError>
Decrement by one frame