Skip to main content

track_samples_from_reader

Function track_samples_from_reader 

Source
pub fn track_samples_from_reader<R: Read + Seek>(
    reader: R,
) -> Result<Vec<TrackSamples>>
Expand description

Extracts sample information from all tracks in an MP4 file using a generic reader.

This function reads an MP4 file from any source that implements Read + Seek (such as a file, buffer, or network stream) and extracts detailed sample information from all video and audio tracks found in the file.

§Parameters

  • reader - A mutable reference to any type implementing Read + Seek traits. The reader will be used to parse the MP4 box structure and extract sample data.

§Returns

Returns Ok(Vec<TrackSamples>) containing sample information for each track found, or an Err if the file cannot be parsed or is not a valid MP4 file.

Each TrackSamples contains:

  • Track metadata (ID, handler type, timescale, duration)
  • Individual sample information (timing, size, sync status, file offsets)

§Errors

This function may return an error in the following cases:

  • I/O errors when reading from the source
  • Invalid or corrupted MP4 file structure
  • Missing required MP4 boxes (moov, trak, etc.)
  • Memory allocation failures for large files

§Example

use std::fs::File;
use mp4box::track_samples_from_reader;

let file = File::open("video.mp4").unwrap();
let track_samples = track_samples_from_reader(file).unwrap();

for track in track_samples {
    println!("Track {}: {} samples", track.track_id, track.sample_count);
}