Skip to main content

Track

Struct Track 

Source
pub struct Track {
Show 14 fields pub id: u32, pub kind: TrackKind, pub codec: Codec, pub timescale: u32, pub duration: u64, pub dimensions: Option<VideoDimensions>, pub channels: Option<u16>, pub sample_rate: Option<u32>, pub language: Option<String>, pub decoder_config: Vec<u8>, pub edits: Vec<EditMapping>, pub samples: Vec<TrackSample>, pub presentation_order: Vec<usize>, pub vorbis_packet_heads: Vec<u8>,
}
Expand description

Read-only metadata and indexes for one demuxed track, from any container.

Fields§

§id: u32§kind: TrackKind§codec: Codec§timescale: u32§duration: u64§dimensions: Option<VideoDimensions>§channels: Option<u16>§sample_rate: Option<u32>§language: Option<String>

The track’s ISO 639-2/T language code, such as "eng" or "fra", from an MP4 track’s mdhd box: "und" when the file marks the language undetermined, and None when the box holds no valid code. A WebM track’s is always None.

§decoder_config: Vec<u8>

Complete codec configuration box, including its header, in the form an MP4 sample entry carries it whichever container the track came from.

§edits: Vec<EditMapping>§samples: Vec<TrackSample>

Samples in decode order.

§presentation_order: Vec<usize>

Decode-order indexes of the presentation frames, sorted by PTS, then DTS, then decode index. A decode-only sample, such as a hidden VP8 frame stored as a WebM block of its own, is decoded on the way to the frames after it but is never presented, so it is not listed.

§vorbis_packet_heads: Vec<u8>

The first byte of every sample, in decode order, of a WebM Vorbis track, which crate::WebmDemuxer reads anyway while scanning block headers. A Vorbis packet’s mode number is in it, so every packet’s decoded interval is known without reading the packets again; empty for every other track.

Implementations§

Source§

impl Track

Source

pub fn presentation_sample(&self, index: usize) -> Option<&TrackSample>

Returns a sample by its zero-based presentation index.

Source

pub async fn read_sample_into<S: ByteSource + ?Sized>( &self, source: &S, decode_index: usize, destination: &mut [u8], ) -> Result<()>

Reads one decode-order sample without changing caller-visible source state.

Source

pub async fn to_encoded_video_samples<S: ByteSource + ?Sized>( &self, source: &S, limits: &Limits, ) -> Result<Vec<EncodedVideoSample>>

Reads every decode-order sample and returns owned EncodedVideoSample values keyed by presentation order, ready for a crate::codec::VideoDecoderFactory backend.

The zero-based position of each sample within Self::presentation_order becomes its presentation_index, and is_sync becomes random_access. A decode-only sample, which presentation_order does not list, takes an identity past the last presentation frame, in decode order, so it never collides with a frame a caller asks for. Total decoded sample bytes are bounded by limits.max_allocation_bytes.

Source

pub fn aac_config(&self) -> Result<AacTrackConfig>

Parses the AAC AudioSpecificConfig carried by this track’s esds box.

Source

pub fn opus_config(&self) -> Result<OpusHead>

Parses the Opus identification header carried by this track’s dOps box.

Source

pub fn vorbis_config(&self) -> Result<VorbisConfig>

Parses the three Vorbis header packets a WebM Vorbis track carries as its decoder_config (see crate::WebmDemuxer); Vorbis has no MP4 sample entry.

Source

pub fn audio_sample_rate(&self) -> Result<u32>

The sample rate this audio track decodes at: the AAC AudioSpecificConfig’s or the Vorbis identification header’s, or 48 kHz for Opus, which always decodes at that rate whatever its input was.

Source

pub async fn to_encoded_audio_samples<S: ByteSource + ?Sized>( &self, source: &S, limits: &Limits, ) -> Result<Vec<EncodedAudioSample>>

Reads every indexed audio packet - AAC access units, Opus or Vorbis packets - from its validated byte range.

Packet intervals use the decoded PCM sample clock and remain contiguous even when the track timescale differs from the decoded sample rate.

Source

pub fn audio_timing(&self, movie_timescale: u32) -> Result<AudioTrackTiming>

Converts the track’s MP4 edit-list timing to the presentation sample clock used by crate::AudioSampleReader, including decoder priming and end padding.

An Opus track without an edit list still has its dOps pre-skip trimmed as priming, and ends where its sample table does: the packets themselves can decode past that end, which is how a muxer that writes no edit list trims the stream.

Trait Implementations§

Source§

impl Clone for Track

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Track

Source§

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

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

impl Eq for Track

Source§

impl PartialEq for Track

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Track

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.