pub struct PacketScanner { /* private fields */ }Expand description
A stateful packet-level scanner for media files.
PacketScanner opens a media file (or URL) and iterates over demuxed packets
without decoding. This is useful for inspecting packet metadata such as
timestamps, keyframe flags, sizes, and stream indices.
§Example
use ez_ffmpeg::packet_scanner::PacketScanner;
let mut scanner = PacketScanner::open("test.mp4")?;
for packet in scanner.packets() {
let packet = packet?;
println!(
"stream={} pts={:?} size={} keyframe={}",
packet.stream_index(),
packet.pts(),
packet.size(),
packet.is_keyframe(),
);
}Implementations§
Source§impl PacketScanner
impl PacketScanner
Sourcepub fn open(url: impl Into<String>) -> Result<Self>
pub fn open(url: impl Into<String>) -> Result<Self>
Open a media file or URL for packet scanning.
Stream information is extracted and cached at open time so that
streams, video_stream,
audio_stream, and
stream_for_packet are available
immediately without additional I/O.
Sourcepub fn seek(&mut self, timestamp_us: i64) -> Result<()>
pub fn seek(&mut self, timestamp_us: i64) -> Result<()>
Seek to a timestamp in microseconds.
Seeks to the nearest keyframe before the given timestamp. Can be called repeatedly for jump-reading patterns.
On failure you may continue reading or attempt another seek, though the exact read position is not guaranteed to be unchanged.
Sourcepub fn next_packet(&mut self) -> Result<Option<PacketInfo>>
pub fn next_packet(&mut self) -> Result<Option<PacketInfo>>
Read the next packet’s info. Returns None at EOF.
If the underlying demuxer returns EAGAIN (common with network streams),
this method retries with a 10 ms sleep up to 500 times (~5 seconds).
After exhausting retries it returns an error.
Sourcepub fn streams(&self) -> &[StreamInfo]
pub fn streams(&self) -> &[StreamInfo]
Returns all stream information cached at open time.
Sourcepub fn video_stream(&self) -> Option<&StreamInfo>
pub fn video_stream(&self) -> Option<&StreamInfo>
Returns the first video stream, if any.
Sourcepub fn audio_stream(&self) -> Option<&StreamInfo>
pub fn audio_stream(&self) -> Option<&StreamInfo>
Returns the first audio stream, if any.
Sourcepub fn stream_for_packet(&self, packet: &PacketInfo) -> Option<&StreamInfo>
pub fn stream_for_packet(&self, packet: &PacketInfo) -> Option<&StreamInfo>
Returns the stream information for the given packet, if the stream index is within bounds.
Sourcepub fn packets(&mut self) -> PacketIter<'_> ⓘ
pub fn packets(&mut self) -> PacketIter<'_> ⓘ
Returns an iterator for convenient for packet in scanner.packets() usage.
Each call creates a fresh iterator, so you can seek() and then call
packets() again to iterate from the new position.
The iterator is fused: once it yields None (EOF) or an Err, all
subsequent calls to next() return None.