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
impl Track
Sourcepub fn presentation_sample(&self, index: usize) -> Option<&TrackSample>
pub fn presentation_sample(&self, index: usize) -> Option<&TrackSample>
Returns a sample by its zero-based presentation index.
Sourcepub async fn read_sample_into<S: ByteSource + ?Sized>(
&self,
source: &S,
decode_index: usize,
destination: &mut [u8],
) -> Result<()>
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.
Sourcepub async fn to_encoded_video_samples<S: ByteSource + ?Sized>(
&self,
source: &S,
limits: &Limits,
) -> Result<Vec<EncodedVideoSample>>
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.
Sourcepub fn aac_config(&self) -> Result<AacTrackConfig>
pub fn aac_config(&self) -> Result<AacTrackConfig>
Parses the AAC AudioSpecificConfig carried by this track’s esds box.
Sourcepub fn opus_config(&self) -> Result<OpusHead>
pub fn opus_config(&self) -> Result<OpusHead>
Parses the Opus identification header carried by this track’s dOps
box.
Sourcepub fn vorbis_config(&self) -> Result<VorbisConfig>
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.
Sourcepub fn audio_sample_rate(&self) -> Result<u32>
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.
Sourcepub async fn to_encoded_audio_samples<S: ByteSource + ?Sized>(
&self,
source: &S,
limits: &Limits,
) -> Result<Vec<EncodedAudioSample>>
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.
Sourcepub fn audio_timing(&self, movie_timescale: u32) -> Result<AudioTrackTiming>
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.