OptrisOptrisDocumentation

Documentation/OTC SDK/Optris.Sdk — C# API referencev12.0

FrameIndex

public sealed class FrameIndex : IDisposable

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

This is what answers "what will a seek cost" before paying for it. ThermalCamera.LastSeekWalkedFrames says what the last seek paid; this says what the next one will. An application that scrubs a timeline and wants to decide whether to coalesce seeks during a drag needs the second, and a documented worst case is not a measurement of the file in front of you: the bound depends on the recording's own anchor spacing and on where the drag started.

Nothing is decoded. Opening one is a single pass over the container reading packet headers, so the cost is proportional to the number of frames and not to the number of pixels. Measured on a 240-frame take written by the shipping recorder: 20 frames are anchors and 220 are not, so a seek lands on the frame that was asked for about 8% of the time and decodes forward to it the rest.

Immutable once open, so any number of threads may read one.

Example

using FrameIndex index = FrameIndex.Open("take.mkv");
ulong anchor = index.AnchorFor(target);
if (target - anchor > 10)
{
    // Far from an anchor: coalesce the drag instead of seeking now.
}

FrameIndex: properties

public ulong AnchorCount { get; }

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. Count / AnchorCount is the average spacing, which is the figure a scrub budget is built from; for one specific target, ask FrameIndex.AnchorFor(…).

public ulong Count { get; }

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.

public TimeSpan Duration { get; }

Presentation time of the last frame.

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 ThermalCamera.PlaybackDuration; a timeline that maps a scrub position onto a frame wants this one.

public bool IsEmpty { get; }

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.

FrameIndex: methods

public ulong AnchorFor(ulong frame)

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

This is the number to price a coalesce on. frame - AnchorFor(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 ThermalCamera.LastSeekWalkedFrames 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.

public void Dispose()

Release the index.

public ulong FrameAt(TimeSpan position)

The frame shown at position.

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

public static FrameIndex Open(string path)

Index a recording without decoding it.

  • path: A .mkv written by this SDK, or any container the linked FFmpeg can demux.

  • Throws ArgumentException: path is null or empty.

  • Throws OptrisSdkException: The file cannot be opened, is not a container FFmpeg understands, or carries no video stream. A file with a video stream and no frames in it opens successfully and is FrameIndex.IsEmpty: that is a real state, a take stopped before its first frame, and not an error.

public IReadOnlyList<FrameIndexEntry> ReadEntries(ulong firstFrame, int count)

Read a run of entries in container order.

  • firstFrame: Where to start.
  • count: How many to read at most.

Returns: The entries read, which is fewer than count at the end of the file and empty when firstFrame is past it. Past the end is not an error: a caller walking a file in pages ends on exactly that condition.

For drawing a whole timeline, where one call per frame is a call per frame. Equivalent to FrameIndex.TryGetEntry(…) in a loop.

public Nullable<FrameIndexEntry> TryGetEntry(ulong frame)

One frame's entry.

  • frame: Zero-based position in the file.

Returns: The entry, or null when frame is past the end, which is also the answer an empty index gives for every frame.