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: u32Stream index this packet belongs to.
time_base: TimeBaseTime 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: PacketFlagsFlags describing this packet.
data: Vec<u8>Compressed payload.
Implementations§
Source§impl Packet
impl Packet
pub fn new(stream_index: u32, time_base: TimeBase, data: Vec<u8>) -> Self
pub fn with_pts(self, pts: i64) -> Self
pub fn with_dts(self, dts: i64) -> Self
pub fn with_duration(self, d: i64) -> Self
pub fn with_keyframe(self, kf: bool) -> Self
Sourcepub fn with_header(self, header: bool) -> Self
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).
Sourcepub fn with_corrupt(self, corrupt: bool) -> Self
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.
Sourcepub fn with_discard(self, discard: bool) -> Self
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).
Sourcepub fn with_unit_boundary(self, boundary: bool) -> Self
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.
Sourcepub fn with_flags(self, flags: PacketFlags) -> Self
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.
Sourcepub fn with_stream_index(self, stream_index: u32) -> Self
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.
Sourcepub fn with_time_base(self, time_base: TimeBase) -> Self
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).
Sourcepub fn end_pts(&self) -> Option<i64>
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.
Sourcepub fn is_keyframe(&self) -> bool
pub fn is_keyframe(&self) -> bool
Convenience accessor: true when PacketFlags::keyframe is
set. Mirrors the builder pair with_keyframe(true).
Sourcepub fn is_header(&self) -> bool
pub fn is_header(&self) -> bool
Convenience accessor: true when PacketFlags::header is set
(the packet carries codec-level headers rather than media data).
Sourcepub fn is_discard(&self) -> bool
pub fn is_discard(&self) -> bool
Convenience accessor: true when PacketFlags::discard is
set (downstream consumers should drop the packet).