pub struct TrackSamples {
pub track_id: u32,
pub handler_type: String,
pub timescale: u32,
pub duration: u64,
pub sample_count: u32,
pub samples: Vec<SampleInfo>,
}Expand description
Complete sample information and metadata for a single track in an MP4 file.
This structure represents all the sample-level information extracted from an MP4 track, combining metadata from the track header and media information with detailed sample data parsed from the sample table boxes (stbl). It provides a complete view of a track’s temporal structure, timing information, and individual sample properties.
The struct is designed for media analysis, debugging, and applications that need detailed insight into MP4 file structure and sample organization.
§Fields
-
track_id- Unique identifier for this track within the MP4 file (from tkhd box). Track IDs are typically sequential starting from 1, but can have gaps. -
handler_type- Four-character code indicating the media type (from hdlr box):"vide"- Video track"soun"- Audio track"hint"- Hint track"meta"- Metadata track"subt"- Subtitle track- And other standardized or custom handler types
-
timescale- Time coordinate system for this track (from mdhd box). Defines the number of time units per second. For example:- Video tracks often use 90000 (90kHz) or frame rate multiples
- Audio tracks commonly use the sample rate (e.g., 48000 for 48kHz)
-
duration- Total track duration in track timescale units (from mdhd box). To get duration in seconds:duration as f64 / timescale as f64 -
sample_count- Total number of samples/frames in this track. Should equalsamples.len()when all samples are successfully parsed. -
samples- Detailed information for each individual sample in the track. Ordered chronologically by decode time (DTS). EachSampleInfocontains timing, size, sync status, and file offset information.
§Example
use mp4box::track_samples_from_path;
let track_samples = track_samples_from_path("video.mp4").unwrap();
for track in track_samples {
println!("Track {}: {} ({} samples)",
track.track_id,
track.handler_type,
track.sample_count);
let duration_sec = track.duration as f64 / track.timescale as f64;
println!("Duration: {:.2} seconds", duration_sec);
if track.handler_type == "vide" {
let keyframes = track.samples.iter()
.filter(|s| s.is_sync)
.count();
println!("Keyframes: {}", keyframes);
}
}Fields§
§track_id: u32§handler_type: String§timescale: u32§duration: u64§sample_count: u32§samples: Vec<SampleInfo>Trait Implementations§
Source§impl Clone for TrackSamples
impl Clone for TrackSamples
Source§fn clone(&self) -> TrackSamples
fn clone(&self) -> TrackSamples
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TrackSamples
impl Debug for TrackSamples
Auto Trait Implementations§
impl Freeze for TrackSamples
impl RefUnwindSafe for TrackSamples
impl Send for TrackSamples
impl Sync for TrackSamples
impl Unpin for TrackSamples
impl UnwindSafe for TrackSamples
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)