pub struct MediaFrame {
pub pts: i64,
pub dts: i64,
pub duration: Option<u64>,
pub data: Bytes,
pub codec: CodecId,
pub frame_type: FrameType,
pub flags: FrameFlags,
pub track_id: u32,
}Expand description
A single decoded or encoded media sample.
data is always a bytes::Bytes slice — zero-copy cloning is safe and
cheap. The same frame can be fanned-out to many subscribers without
copying the underlying buffer.
Fields§
§pts: i64Presentation timestamp in the stream’s time base (milliseconds).
dts: i64Decode timestamp in the stream’s time base (milliseconds).
duration: Option<u64>Duration of this frame in milliseconds. None = unknown.
data: BytesEncoded / raw payload.
codec: CodecIdCodec that produced this frame.
frame_type: FrameTypeFrame type classification.
flags: FrameFlagsBit flags.
track_id: u32Track index (0 = first video, 1 = first audio, etc.).
Implementations§
Source§impl MediaFrame
impl MediaFrame
Sourcepub fn new_video(
pts: i64,
dts: i64,
data: Bytes,
codec: CodecId,
is_key: bool,
) -> Self
pub fn new_video( pts: i64, dts: i64, data: Bytes, codec: CodecId, is_key: bool, ) -> Self
Build a video frame; is_key selects FrameType::Key vs
FrameType::Delta. Track id defaults to 0.
Sourcepub fn new_audio(pts: i64, data: Bytes, codec: CodecId) -> Self
pub fn new_audio(pts: i64, data: Bytes, codec: CodecId) -> Self
Build an audio frame (dts == pts, FrameType::Audio, track id 1).
Sourcepub fn is_keyframe(&self) -> bool
pub fn is_keyframe(&self) -> bool
Whether this frame is a video keyframe (FrameType::Key).
Sourcepub fn pts_duration(&self) -> Duration
pub fn pts_duration(&self) -> Duration
The presentation timestamp as a Duration (from the absolute pts).
Sourcepub fn pts_in(&self, timescale: u32) -> i64
pub fn pts_in(&self, timescale: u32) -> i64
The presentation timestamp rescaled from the frame’s millisecond base into
timescale ticks per second.
Frame timestamps are stored in milliseconds (a 1 kHz time base), but media containers and wire formats run other clocks: RTP and MPEG-TS use 90 kHz for video, RTP audio uses the sample rate, and CMAF/fMP4 pick a per-track timescale. This converts without changing how frames are stored, so a muxer/packetizer can emit timestamps in its own base:
let f = MediaFrame::new_video(1000, 1000, Bytes::new(), CodecId::H264, true);
assert_eq!(f.pts_in(90_000), 90_000); // 1000 ms → 90 kHz ticksThe math is done in i128 so a large pts × timescale cannot overflow.
Trait Implementations§
Source§impl Clone for MediaFrame
impl Clone for MediaFrame
Source§fn clone(&self) -> MediaFrame
fn clone(&self) -> MediaFrame
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more