OptrisOptrisDocumentation

Documentation/OTC SDK/OTC SDK — C++ API referencev12.0

optris::sdk::rec::Player

Opens recordings created by Recorder and delivers decoded frames with original timing. Uses a background thread for decode and delivery.

Public static functions

Open

static std::unique_ptr< Player > Open(const std::string &path)

Open a recording file for playback.

Probes the MKV container, locates video and metadata streams, and initializes the FFV1 decoder.

Parameters

Name Description
path Path to the .mkv recording file.

Returns: The player, with the file open.

Exceptions

Name Description
IoException if the file cannot be opened or is not a container FFmpeg understands.
SdkException if it carries no stream this SDK can replay, or if the decoder cannot be built.

OpenSeries

static std::unique_ptr< Player > OpenSeries(const std::string &path)

Open a multipart recording, from any one of its parts, and replay all of its parts as one recording.

Added in 12.0.10.

A recording started with a segment limit is written as several files, run_part000.mkv, run_part001.mkv and so on. Open() replays the one file it is given. This replays the whole recording, whichever part it is given:

  • one timeline. GetDurationUs() is the whole recording's, GetPositionUs() runs on across each part boundary rather than restarting at zero, and a frame whose camera gave no timestamp is stamped on the same continuous timeline.
  • seeking anywhere. SeekToTimestamp() and SeekToFrame() take a position in the whole recording and go to the part that holds it. Frames are counted across parts.
  • from the start. The replay begins at the first frame of part 0, whichever part was named.
  • regions and alarms carry on. Each part's region records reach the callbacks in order, so the state at the end of one part is where the next one starts from.
  • one set of files. GetAttachments() lists every file the recording carries once, with part 0's copy of each, plus any file only a later part carries.

The parts are found beside the named file by their shared series id, never by their names alone; see rec::OpenSeries(). A whole recording, one with no series or a series that never rolled over, is opened exactly as Open() opens it.

Parameters

Name Description
path Any part of the recording, or a whole recording.

Returns: The player, with the first part open.

Exceptions

Name Description
IoException if path cannot be read, or if a part of the recording is missing. The message names the missing part and the file it should be. Replaying across a hole would join two stretches of the recording that were never next to each other, and every time after the hole would be wrong by its unknown length. The parts that are there still open with Open().
SdkException for the reasons Open() gives.

ReadAttachments

static auto ReadAttachments(const std::string &path) -> std::vector< Attachment >

Read the files carried inside a recording without opening it for playback.

Parses the container header and stops: no decoder is created and no frame is read, so this costs the same on a one-second take and on an hour-long one. Works on any Matroska file this SDK writes, including a segment of a segmented recording and a multi-camera session file.

Parameters

Name Description
path Path to the .mkv file.

Returns: Its attachments. An empty vector for a file that carries none, which is not an error.

Exceptions

Name Description
IoException when the file cannot be opened or is not a container FFmpeg understands.

Public functions

GetSeriesPart

auto GetSeriesPart() const -> uint32_t

Which part of a multipart recording is being replayed.

Added in 12.0.10.

Counts from 0, the same number as the file's _partNNN suffix. 0 for a player opened with Open(), which holds one file.

GetSeriesPartCount

auto GetSeriesPartCount() const -> uint32_t

How many parts this player replays.

Added in 12.0.10.

1 for a player opened with Open(), and for a whole recording opened with OpenSeries().

~Player

~Player()

Player

Player(const Player &)=delete

operator=

Player & operator=(const Player &)=delete

Play

void Play()

Start playback on a background thread.

Frames are delivered through the registered callbacks at the rate determined by SetSpeed(). No-op if already playing.

Pause

void Pause()

Pause playback. The background thread exits.

Resume by calling Play() again. The file position is preserved.

Stop

void Stop()

Stop playback and reset to the beginning.

SeekToTimestamp

void SeekToTimestamp(uint64_t timestamp_us)

Seek to a timestamp in microseconds.

Frame-accurate. A recording this SDK writes is not all-intra: the FFV1 encoder's default GOP is 12, measured as 7 keyframes in 81 frames on a 27 Hz take. So the demuxer can only start at the keyframe at or before the target. The frames between that keyframe and the target are therefore decoded and not delivered: nothing after the keyframe can be decoded without them, and nothing before the target should be handed to a consumer that asked for the target.

Were they delivered, the reported position would step backward by up to a whole GOP -- measured at 403 ms on a 27 Hz take and 343 ms at 32 Hz -- and a per-tile scrub would show frames from before the point the operator picked.

Cost: Cost The walk is unpaced (it never sleeps), so a seek costs decode time rather than the playback time of the frames it steps over. The worst case is the keyframe interval minus one frame of decode; GetLastSeekWalkedFrames() reports what the last seek actually paid, and optris::sdk::rec::FrameIndex answers what a given file's interval is without decoding anything.

A target past the end: A target past the end Lands on the last frame, which is what FrameIndex::FrameAt() documents for a timestamp past the end. GetPositionUs() still answers the target that was asked for until a frame arrives.

Parameters

Name Description
timestamp_us Target position in microseconds from the start of the recording.

SeekToFrame

void SeekToFrame(size_t frame_index)

Seek to a frame by index.

Computes the timestamp from the stream's average frame rate and seeks to that position.

Parameters

Name Description
frame_index Zero-based frame number.

SetSpeed

void SetSpeed(float speed)

Set the playback speed multiplier.

Parameters

Name Description
speed 1.0 = real-time, 0.5 = half speed, 2.0 = double speed.

SetLoop

void SetLoop(bool loop)

Enable or disable loop playback.

When enabled, playback restarts from the beginning after reaching the end of the file.

Parameters

Name Description
loop True to enable looping.

GetWidth

auto GetWidth() const -> uint32_t

Get the video width in pixels.

GetHeight

auto GetHeight() const -> uint32_t

Get the video height in pixels.

GetFrameRate

auto GetFrameRate() const -> float

Get the video frame rate in Hz.

GetDurationUs

auto GetDurationUs() const -> uint64_t

Get total recording duration in microseconds.

GetStartTimeUs

auto GetStartTimeUs() const -> uint64_t

When the recording started: the container's creation_time, in microseconds since the Unix epoch (UTC).

For a recording made from a camera this is when the recording began, on the host clock of the machine that made it, to the second. For one converted from an earlier recording (a PIX Connect .ravi through rec::ImportRavi()) it is when the original was recorded, not when it was converted (Recorder::SetStartTime()). For a multipart recording it is when the first part began.

Zero when the file does not say: a file written by something other than this SDK, or with the tag stripped.

Add GetPositionUs() to it for the wall-clock time of the frame on screen.

GetStartTimeZone

auto GetStartTimeZone() const -> RecordingTimeZone

The time zone the recording was made in, beside the UTC start GetStartTimeUs() gives: the recording computer's for a recording of a camera, the one given (or, marked assumed, the one taken) at conversion for one converted from a PIX Connect .ravi. For a multipart recording, the first part's.

known is false for a recording that does not say: one made by an SDK release before this existed, or by another program.

GetPositionUs

auto GetPositionUs() const -> int64_t

Get current playback position in microseconds.

IsAtEnd

auto IsAtEnd() const -> bool

Whether a non-looping replay has delivered its last frame.

The end of a replay, asked rather than inferred. Comparing GetPositionUs() against GetDurationUs() cannot answer it: the position is the last frame's start and the duration counts that frame's own length as well, so the two are one frame period apart on a correct file and never meet. A consumer waiting for them to meet waits forever.

False until the file runs out, and false again after Play(), Stop() or any seek -- each of those is somewhere to play from. A replay under SetLoop(true) never sets it, because it never ends.

Play() does not rewind: a replay still sitting at the end reads end of file at once and reports the end again, often before the caller next looks. Seek to zero to play it a second time. The playback thread has stopped by the time this turns true, so a seek and a Play() straight after it always replay.

Returns: True once every frame in the file has been handed over and no wrap is coming.

GetAttachment

auto GetAttachment(const std::string &name) const -> std::optional< std::string >

Read an MKV attachment by filename.

A convenience over GetAttachments() for the SDK's own files, whose names are known and unique. Attachment names in general are not required to be unique, and this returns the first match; enumerate instead when the writer is not this SDK.

Parameters

Name Description
name Attachment filename (e.g. "device.json").

Returns: File contents, or nullopt if not found.

GetAttachments

auto GetAttachments() const -> std::vector< Attachment >

Every file carried inside this recording.

Names, MIME types and bytes, in container order, which puts the SDK's own otc-meta.json first for any file this SDK wrote. The application's own files are whatever an AttachmentProvider supplied as each file opened.

Attachment::compress is false on everything this returns: an MKV attachment stream is stored verbatim, so nothing was deflated on the way in and nothing is inflated on the way out. The flag is a snapshot concept, where it decides whether the otCa chunk is deflated.

SetRegionStateCallback

void SetRegionStateCallback(std::function< void(const std::string &)> cb)

Register a callback for each frame's region record.

Parameters

Name Description
cb Called with each frame's region record, as written by the recorder. Empty for a recording made without regions.

SetRegionCatchUpCallback

void SetRegionCatchUpCallback(std::function< void(const std::string &)> cb)

Register a callback for the region records of frames a seek decodes without delivering.

A recording this SDK writes is not all-intra, so a seek lands on the keyframe at or before its target and the frames between are decoded and discarded, see SeekToTimestamp(). Their region records still matter, because the record is a delta: matrices only when they changed, a definition only on a region's first frame. The region state at the target is the state at the keyframe plus every one of those records in order, so a consumer that saw only the delivered frame's record would land with the keyframe's regions.

Why this is not SetRegionStateCallback(): Why this is not SetRegionStateCallback() The timing contract is different and a consumer has to be able to tell them apart. A record from that one arrives just before its frame, so a consumer may hold it and apply it alongside that frame. A record from this one belongs to a frame that will never arrive, so a consumer that held it would apply only the last of them and lose the rest of the sequence. Apply these as they come.

Parameters

Name Description
cb Called once per walked-over frame that carries a region record, in file order. Never called for a seek that lands on a keyframe, because then there is nothing between.

DeliverCurrentFrame

auto DeliverCurrentFrame() -> bool

Decode forward from the last seek and hand over the frame at its target, without starting playback.

A seek of a stopped replay used to deliver nothing at all: Play() starts the decode thread and a seek does not, so the position moved and the picture stayed where it was until the next Play(). Measured on a paused scrub: no frame in 800 ms while GetPositionUs() already answered the target.

This runs the decode on the calling thread, fires the frame callback exactly once, and leaves the replay stopped. The frames already decoded past the target stay queued, so a Play() after it carries on from here rather than re-reading them.

Cost: Cost One keyframe-to-target walk, unpaced: it never sleeps, so it costs decode time and not playback time. The worst case is the recording's own keyframe interval minus one frame; optris::sdk::rec::FrameIndex answers what that is for a given file without decoding anything, and GetLastSeekWalkedFrames() says what the last seek actually paid.

Returns: Whether a frame was delivered. False while playing (the playback thread owns the decoder then and will reach the target by itself) and false for a file with no frames left.

GetLastSeekWalkedFrames

auto GetLastSeekWalkedFrames() const -> uint64_t

How many frames the last seek decoded without delivering them.

The cost of the last seek, counted rather than estimated from the keyframe interval. Zero after a seek that landed on a keyframe, and zero before the first seek.

One of a seek's two costs; see GetLastSeekReplayedRecords() for the other, which is bounded differently and can be the larger.

GetLastSeekReplayedRecords

auto GetLastSeekReplayedRecords() const -> uint64_t

How many region records the last seek replayed off the metadata track without decoding anything.

A seek has two things to catch up on and they are bounded by different distances, which is why there are two counters rather than one.

  • The picture reaches back to the video keyframe at or before the target, because nothing after a keyframe can be decoded without the frames between. That is GetLastSeekWalkedFrames(), and the bound is the recording's keyframe interval; optris::sdk::rec::FrameIndex answers it for a given file without decoding anything.
  • The region state reaches back as far as the records it has not applied yet, which can be before the keyframe: a region's definition is written on the frame it first appeared on, and walking forward from a keyframe never contains a definition that lies in an earlier interval. A seek forward replays only the records between where the state was last known and the target, which is what a scrub does and is cheap. A seek backward starts from the beginning of the file, because the record is a delta and nothing un-applies one.

Nothing is decoded for this: the records are on their own metadata stream and the video stream is handed to the demuxer to skip, so the cost is the record track's and not the file's.

Zero when the replay was already current to the target, zero before the first seek, and zero for a seek issued while playing; the decode thread owns the demuxer then, and a seek through optris::sdk::Player always pauses first.

SetRecordedAmbient

void SetRecordedAmbient(std::optional< float > ambient_c)

The ambient a frame was measured against when the frame itself does not say.

Every frame this player delivers carries an ambient in its metadata, as a live camera's does, so a replay answers Imager::GetEffectiveAmbientTemperature() and publishes the SignalField::kAmbientTemp device signal exactly as a camera does. Telemetry::ambient_temp_c is the first choice; this is what stands in when the frame has none.

Set it to the file-level otc-meta.json radiation.ambient_temp_c, or to nothing. Recordings written before the per-frame field existed carry only the file-level value, and it is the right answer for them: it was the ambient in force when the recording started and nothing in the file contradicts it. Leave it unset for a file that names no ambient at all, and then a replayed frame reports none -- which is what the file says, and a display can show nothing rather than a default no measurement used.

This player does not read otc-meta.json, which is why the value arrives from outside rather than being discovered here. optris::sdk::Player sets it once, at open.

In the SDK's temperature unit (Celsius unless SetTemperatureUnit() chose Fahrenheit). The file-level value is Celsius, as the file stores it, so in Fahrenheit pass Temperatures::FromCelsius(value, GetTemperatureUnit()).

SetFrameCallback

void SetFrameCallback(std::function< void(const optris::sdk::ThermalFrame &, const Telemetry &)> callback)

Register a callback for decoded frames.

Called from the playback thread for each decoded frame. The ThermalFrame is reconstructed from the stored 16-bit data; the Telemetry is deserialized from the JSON subtitle track.

Parameters

Name Description
callback Receives the thermal frame and telemetry.

SetPictureCallback

void SetPictureCallback(std::function< void(const optris::sdk::BgraFrame &, const Telemetry &)> callback)

Set the callback for a recording that is a picture.

A take written with VideoContent::kColorized carries the colorized 8-bit image, not 16-bit temperatures, so there is no ThermalFrame to reconstruct and SetFrameCallback() never fires. This one does instead, with the decoded picture.

Parameters

Name Description
callback Receives the picture and what telemetry the file carries.

IsPicture

bool IsPicture() const

Whether this file is a picture rather than radiometry.

Known once the stream is open, from its pixel format: 16-bit greyscale is a measurement, anything else is a picture. Callers have to ask, because everything downstream of a picture -- the readings, the alarms, the cursor temperature -- has no answer and must say so rather than show the last number it had.

It is read from the stream header at Open() rather than from the first frame to be decoded -- a picture file would otherwise answer "radiometry" for as long as nothing had been played, which is exactly when an application asks. The per-frame check still corrects it, so a file that changes format part way through is caught. A header that declares no pixel format at all still answers from the first frame, there being nothing else to answer from.