OptrisOptrisDocumentation

Documentation/OTC SDK/optris_sdk — Rust API referencev12.0

FrameIndex

pub struct FrameIndex

Where every frame of a recording is, and which of them a decoder can start from.

Opened with FrameIndex::open and closed when dropped; there is no manual close.

Examples

Price a seek before issuing it:

# fn main() -> optris_sdk::Result<()> {
use optris_sdk::FrameIndex;

let index = FrameIndex::open("shift2.mkv")?;
println!("{} frames, {} anchors", index.count()?, index.anchor_count()?);

let target = index.frame_at(4_000_000)?;
let walk = target - index.anchor_for(target)?;
if walk > 60 {
    println!("that seek would decode {walk} frames; coalesce it");
}
# Ok(())
# }

FrameIndex — methods

pub fn open(path: &str) -> Result<Self>

Index a recording without decoding it.

One pass over the container reading packet headers. No frame is decoded, which is what makes this affordable on a long take.

path is a .mkv written by this SDK, or any container the linked FFmpeg can demux.

Errors

Returns Status::Io when the file cannot be opened or is not a container FFmpeg understands, and Status::InvalidArgument when it carries no video stream. A file with a video stream and no frames in it opens successfully and is FrameIndex::is_empty; that is a real state, a take stopped before its first frame, and not an error.

pub fn count(&self) -> Result<u64>

How many frames the recording holds.

Counted from the container, so this is exact. It is not duration times frame rate, which is an estimate over a declared rate and is wrong whenever the camera did not deliver at the rate the header claims.

Errors

Returns Status::InvalidHandle if the index is not valid.

pub fn anchor_count(&self) -> Result<u64>

How many of those frames a decoder can start from.

Equal to FrameIndex::count for an all-intra recording, and far below it for anything this SDK writes today, measured on a 240-frame take, 20 are anchors and 220 are not. count / anchor_count is the average spacing, which is the figure a scrub budget is built from; for one specific target, ask FrameIndex::anchor_for.

Errors

As FrameIndex::count.

pub fn is_empty(&self) -> Result<bool>

Whether the recording holds no frames at all.

A real state rather than an error: a take stopped before its first frame arrived indexes successfully and is empty. Ask this before reading frame 0, because "no frames" and "frame 0 is unreachable" want different messages.

Errors

As FrameIndex::count.

pub fn entry(&self, frame: u64) -> Result<Option<FrameIndexEntry>>

One frame's entry, or None past the end.

None rather than an error because walking off the end is how a caller paging through a file finds out it has finished. An empty index answers None for every frame.

Errors

As FrameIndex::count.

pub fn read_entries(&self, first_frame: u64, capacity: usize) -> Result<Vec<FrameIndexEntry>>

Read a run of entries in container order.

For drawing a whole timeline, where one call per frame is a call per frame. At most capacity entries, fewer at the end of the file; a first_frame past the end returns an empty Vec rather than failing, which is exactly the condition a caller walking a file in pages ends on.

Errors

As FrameIndex::count.

pub fn anchor_for(&self, frame: u64) -> Result<u64>

The nearest frame at or before frame that a decoder can start from.

This is the number to price a coalesce on. frame - anchor is exactly what a cold seek to that frame then costs. It was "to within one frame" in earlier releases: a seek by frame number computed its target from the stream's nominal frame rate instead of reading the frame's own presentation time, so it could land one frame past the target or before the target's anchor. Both sides now read this index.

It does not bound a scrub. The walk starts from wherever the player already is, which this index cannot know, so seeking 0, 1, 2 … on one handle can pay a whole anchor interval more than the quote. Price a drag off this, then read crate::Camera::last_seek_walked_frames to see what the drag actually cost.

Never greater than frame, so decoding forward from the answer always reaches it. Zero for an empty index and for a frame past the end; there is nothing to seek to in either case. The first frame of a recording counts as an anchor whether or not it is flagged as one, because a decoder starting at the beginning of the file has nothing before it to be missing.

Errors

As FrameIndex::count.

pub fn frame_at(&self, timestamp_us: u64) -> Result<u64>

The frame shown at timestamp_us.

The last frame whose presentation time is at or before the timestamp, which is the frame a viewer would be looking at. Clamped to the last frame for a timestamp past the end, and 0 for an empty index.

Errors

As FrameIndex::count.

pub fn duration_us(&self) -> Result<u64>

Presentation time of the last frame, in microseconds.

Zero for an empty index. This is the last frame's start, not the end of its interval, so it is one frame period shorter than crate::Camera::playback_duration_us; a timeline that maps a scrub position onto a frame wants this one.

Errors

As FrameIndex::count.