Skip to main content

Packet

Struct Packet 

Source
pub struct Packet {
    pub stream_index: u32,
    pub time_base: TimeBase,
    pub pts: Option<i64>,
    pub dts: Option<i64>,
    pub duration: Option<i64>,
    pub flags: PacketFlags,
    pub data: Vec<u8>,
}
Expand description

A chunk of compressed (encoded) data belonging to one stream.

Fields§

§stream_index: u32

Stream index this packet belongs to.

§time_base: TimeBase

Time base in which pts and dts are expressed.

§pts: Option<i64>

Presentation timestamp (display order). None if unknown.

§dts: Option<i64>

Decode timestamp (decode order). Often equal to pts for intra-only codecs.

§duration: Option<i64>

Packet duration in time_base units, or None if unknown.

§flags: PacketFlags

Flags describing this packet.

§data: Vec<u8>

Compressed payload.

Implementations§

Source§

impl Packet

Source

pub fn new(stream_index: u32, time_base: TimeBase, data: Vec<u8>) -> Self

Source

pub fn with_pts(self, pts: i64) -> Self

Source

pub fn with_dts(self, dts: i64) -> Self

Source

pub fn with_duration(self, d: i64) -> Self

Source

pub fn with_keyframe(self, kf: bool) -> Self

Source

pub fn with_header(self, header: bool) -> Self

Mark this packet as carrying codec-level headers rather than media data (extradata, parameter sets, codec-private blobs).

Source

pub fn with_corrupt(self, corrupt: bool) -> Self

Mark this packet’s payload as possibly corrupt. Decoders should still attempt to decode it but may produce best-effort output.

Source

pub fn with_discard(self, discard: bool) -> Self

Mark this packet for downstream discard (e.g. decoder delay padding, encoder priming samples, ASS dialogue tags shipped only for muxer round-trip).

Source

pub fn with_unit_boundary(self, boundary: bool) -> Self

Mark this packet as the last entry inside its source container’s natural framing unit (Ogg page, MP4 chunk, MKV cluster). Decoders ignore the flag; muxers may use it to recreate similar boundaries in their output.

Source

pub fn with_flags(self, flags: PacketFlags) -> Self

Replace this packet’s full flag set in one call. Useful for demuxers that compute flags up front and want a single setter rather than four chained builder calls.

Source

pub fn with_stream_index(self, stream_index: u32) -> Self

Override the packet’s stream index. Builder-style chainable counterpart to the public field, for cases where the demuxer builds packets with a placeholder stream index and remaps them to the final index downstream.

Source

pub fn with_time_base(self, time_base: TimeBase) -> Self

Override the packet’s time base. Builder-style chainable counterpart to the public field, for cases where the time base isn’t known at construction time (e.g. a remuxer rescaling all packets onto a unified output base).

Source

pub fn end_pts(&self) -> Option<i64>

Compute the packet’s end PTS (pts + duration) when both are known. Returns None if either is missing, or if the sum would overflow i64. Useful for muxers that need to derive a per- packet end timestamp without recomputing it at every call site.

Source

pub fn is_keyframe(&self) -> bool

Convenience accessor: true when PacketFlags::keyframe is set. Mirrors the builder pair with_keyframe(true).

Source

pub fn is_header(&self) -> bool

Convenience accessor: true when PacketFlags::header is set (the packet carries codec-level headers rather than media data).

Source

pub fn is_discard(&self) -> bool

Convenience accessor: true when PacketFlags::discard is set (downstream consumers should drop the packet).

Trait Implementations§

Source§

impl Clone for Packet

Source§

fn clone(&self) -> Packet

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 Packet

Source§

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

Formats the value using the given formatter. Read more

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 = Infallible

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

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

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.