OptrisOptrisDocumentation

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

FrameIndex

class optris_sdk.playback.FrameIndex

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

Open one with open. It is a context manager; use it as one, or call close yourself. Immutable once open, so any number of threads may read one.

FrameIndex — properties

count

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.

anchor_count

How many of those frames a decoder can start from.

Equal to count for an all-intra recording, and far below it for anything this SDK writes today. count / anchor_count is the average spacing, which is the figure a scrub budget is built from; for one specific target, ask anchor_for.

duration_s

Presentation time of the last frame, in seconds.

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 optris_sdk.camera.Camera.playback_duration_s; a timeline that maps a scrub position onto a frame wants this one.

FrameIndex — methods

open(cls, path)

Index a recording without decoding it.

A file with a video stream and no frames in it opens successfully and is empty -- that is a real state, a take stopped before its first frame, and not an error.

  • Parameter path — an .mkv written by this SDK, or any container the linked FFmpeg can demux.
  • Raises ~optris_sdk.errors.IoError — the file cannot be opened or is not a container FFmpeg understands.
  • Raises ~optris_sdk.errors.InvalidArgumentError — the file carries no video stream.

close()

Release the index. Safe to call more than once.

__enter__()

__exit__(*_)

__len__()

empty()

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 entry 0, because "no frames" and "frame 0 is unreachable" want different messages.

entry(frame)

One frame's FrameIndexEntry, or None.

None when frame is past the end, which is also the answer an empty index gives for every frame. None rather than an exception because walking off the end of a file is an ordinary outcome of a loop, and a caller that has to catch to find its own terminating condition will instead guess one from count and race the next frame.

anchor_for(frame)

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

This is the number to price a coalesce on. frame - anchor_for(frame) 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 optris_sdk.camera.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.

frame_at(timestamp_s)

The frame shown at timestamp_s seconds.

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 zero for an empty index.

entries(first_frame = 0, count = None)

A run of FrameIndexEntry in container order.

For drawing a whole timeline, where one call per frame is a call per frame. count defaults to the rest of the file.

Fewer than count at the end, and empty when first_frame is past it -- past the end is not an error, because a caller walking a file in pages ends on exactly that condition.

__repr__()