TrackSamples

Struct TrackSamples 

Source
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 equal samples.len() when all samples are successfully parsed.

  • samples - Detailed information for each individual sample in the track. Ordered chronologically by decode time (DTS). Each SampleInfo contains 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

Source§

fn clone(&self) -> TrackSamples

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TrackSamples

Source§

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

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

impl Serialize for TrackSamples

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.