OptrisOptrisDocumentation

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

optris::sdk::rec

One attachment type, shared by snapshots and recordings.

An application can carry its own files inside the images and videos the SDK writes: a process context dump, a config file, a reading taken from another system. The same Attachment value is used everywhere:

  • in a snapshot it becomes an otCa chunk in the PNG, or the private tag 65200 in the TIFF;
  • in a recording it becomes an MKV attachment stream.

Attachments are collected through an AttachmentProvider rather than a setter. See the note on the pull shape below.

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

Why this exists: Why this exists A recording this SDK writes is not all-intra. Measured on a 240-frame take written by the shipping Recorder: 20 frames are seek anchors and 220 are not, so Player::SeekToFrame() lands on the frame that was asked for 8% of the time and on some earlier frame the rest of the time, by up to 11 frames. Worse, the player then reports the position that was requested rather than the one it reached, so the miss is invisible: the transport bar and the picture disagree and nothing says so.

That is survivable for Play(), which is walking forward anyway. It is not survivable for a scrubbing timeline or a frame export, which is what this is for. With an index in hand a caller can seek to the anchor at or before the frame it wants and decode forward to it, and can know before it starts how far that will be.

What it costs: What it costs One pass over the container reading packet headers. No frame is decoded, which is what makes this affordable on a long take: the work is proportional to the number of packets, not to the number of pixels.

This does not require recordings to become all-intra: This does not require recordings to become all-intra If they ever do, every entry reports anchor == true, AnchorFor() becomes the identity, and callers keep working unchanged; the decode-forward step simply never has anything to do.

Example: Example cpp #include "optris/sdk/rec/frame_index.h" // Throws IoException if the file will not open, and SdkException // if it carries no video stream this SDK can index. const auto index = optris::sdk::rec::FrameIndex::Build("rec.mkv"); // How far back a seek to frame 100 really starts. const uint64_t anchor = index.AnchorFor(100); std::println("{} frames of decode to reach 100", 100 - anchor);

See also: Player for playback, which this describes but does not drive.

One metadata schema, three carriers.

The same JSON document describes a still image and a recording, and lands in whichever slot the container provides:

Carrier Where it lives
PNG iTXt otc:meta, deflate-compressed
TIFF ImageDescription tag, uncompressed
MKV the otc-meta.json attachment stream

One serializer, one parser, one document to maintain, and a snapshot and a recording describe their device identically.

Absent versus zero: Absent versus zero Every optional field is written only when it is known. A reader can therefore tell "not recorded" from "recorded as zero", which matters when the value is a measurement.

How a recording and a still are written, as opposed to what goes into them.

Why these two structs are a header of their own: Why these two structs are a header of their own They used to live in rec/types.h and rec/snapshot.h, which is where a reader expects them -- and that made them unreachable from the one place that needed them most. An alarm's SnapshotAction and RecordingAction are declared in alarm.h, and alarm.h cannot include either of those headers: rec/types.h included alarm.h directly, and rec/snapshot.h reaches it through rec/attachment.h, which carries a std::optional<[AlarmEvent](/documentation/sdks/otc-sdk/v12.0/api/classes/optris.sdk.alarmevent)>. So an alarm action could name a format and a directory but not a compression level or a segment size, so the imager started every alarm recording and wrote every alarm still with the defaults.

This header depends on api.h and the standard library, nothing else, which is what makes it includable from both sides of that cycle. It is the natural shape anyway: these are plain value types describing a request, with no reference to a frame, a camera or an error.

rec/types.h and rec/snapshot.h both include it, so every existing #include keeps compiling and every name keeps its spelling.

The Player class decodes FFV1-compressed MKV recordings created by the Recorder and delivers reconstructed optris::sdk::ThermalFrame objects through callbacks. Playback runs on a background thread with timing that matches the original capture rate (adjustable via SetSpeed()). The player supports seeking by timestamp or frame index, looping, and pause/resume.

Thread safety: Thread safety Callbacks are invoked from the playback thread. The callback registration methods (SetFrameCallback, SetMeasurementCallback) are mutex-protected and may be called from any thread.

Example: Example This header is not part of the sdk.h single-include header: include it as well, beside sdk.h or without it (see extra_includes).

#include "optris/sdk/rec/player.h"

// Throws IoException if the file will not open, so a caller that
// cannot do anything about that lets it out.
auto player = optris::sdk::rec::Player::Open("rec.mkv");

player->SetFrameCallback(
    [](const optris::sdk::ThermalFrame &frame,
       const optris::sdk::rec::Telemetry &telemetry) {
      float center = frame.GetTemperature(
          frame.GetWidth() / 2, frame.GetHeight() / 2);
      std::println("frame {} center: {:.1f} C",
                   telemetry.sequence, center);
    });
player->SetSpeed(2.0f);  // 2x speed
player->Play();

Note: Playback delivers an optris::sdk::rec::Telemetry struct alongside the reconstructed ThermalFrame. The Telemetry mirrors the optris::sdk::FrameMetadata fields the recorder serializes.

See also: Recorder for creating recordings

The Recorder class provides lossless recording of 16-bit radiometric thermal data from the OTC.SDK using FFV1 codec in Matroska (MKV) containers. This preserves full temperature measurement capability for later analysis and playback. Each recording file contains, in this order:

  • Track one: the viewable video. What a player should show. Today that is the one-frame placard, a colorized still with a two-line notice along the bottom and a QR code for the software page in the corner, because this Recorder writes no false-colour track yet. First deliberately: most players take the first video track, and without this they show a near-black GRAY16LE rectangle.
  • Track two: the measurement (FFV1, GRAY16LE), the raw 16-bit pixel data, marked AV_DISPOSITION_DEFAULT
  • A subtitle stream with per-frame JSON metadata (timestamps, probe temperatures, flag state, measurement field statistics), immediately after the video track it belongs to
  • Optional attachment streams for calibration data, and the cover.jpg a file manager thumbnails The recorder accepts optris::sdk::ThermalFrame directly from the SDK's thermal frame callback.

What a reader may rely on: the format contract: What a reader may rely on: the format contract A third party reading these files needs to know which properties are promises and which are incidental. Until this was written down there was no way to tell, and a shell extension shipped against markers reverse-engineered from this source. The full statement, with the legacy shapes it has to read, is What a third party may rely on. What this class guarantees is:

Guaranteed. Every segment of every file this Recorder writes with FileMetadata set carries all three of these, all of them in the header before the first Cluster, so a reader decides from the first few KiB without decoding anything:

  • an otc-meta.json attachment, holding at least otc_format, encoding, width, height and software ("OTC.SDK <version>");
  • a Tags element with OTC_FORMAT (the same integer as the document's otc_format) and OTC_SOFTWARE. These are what survives a remux; see below;
  • one text track per thermal track, its title ending in "Metadata". Not one per video stream: the cover and the placard are pictures and have none.

The video track is FFV1 GRAY16LE, and its samples are the SDK's internal int16: (celsius * 10) + 1000. The file now states that itself, in unit, scale and offset; do not infer a grid from encoding alone.

The viewable track is first and the measurement follows it. That much of the order is deliberate and is the one thing a player which takes "the first video track" can act on. Everything else about order is advisory.

Advisory. The metadata track's exact title, attachment order and indices, the presence and contents of cover.jpg, and every attachment beyond otc-meta.json. Match attachments by name, not by index. The number of video-ish streams is not fixed: a recording carries up to three, the thermal track plus the cover (attached_pic) and the placard (OTC_TRACK_ROLE=placard). So take the measurement as internal::IsContentVideoStream() does: by the role tag, never as "stream 0" or "the only video stream". Recordings written before this layout have the measurement first and carry no role tag, and the same rule reads both.

What a plain remux does now, and the one flag that saves it: What a plain remux does now, and the one flag that saves it ffmpeg -i rec.mkv -c copy out.mkv keeps one video stream and no attachments. With the placard in front of the measurement, and larger than it, that stream would be the placard: one JPEG and no temperatures, silently. AV_DISPOSITION_DEFAULT on the measurement wins av_find_best_stream() ahead of position and area, so the plain form still keeps the temperatures. It still loses otc-meta.json, the cover and the placard; -map 0 -c copy keeps everything.

Decidable from the header, which is small: Decidable from the header, which is small The markers are all before the first Cluster, in a finished file and in one still being written, so a reader answers without decoding anything. Measured on the test corpus: 1,101 bytes with no preview, 5,241 at 320x240, 10,545 at 640x480; the header is mostly the cover image, and a 64 KiB read covers every case. A finished file is cheaper still: its SeekHead names the byte offset of Tags. A foreign .mkv is rejected at its own first Cluster, 585 bytes in. scripts/check_recording_foreign_readers.py re-measures all of this every build and prints it.

A file being recorded is identifiable within about a second of its first frame: the writer flushes rather than buffering a quarter of a megabyte. It has no SeekHead yet (the muxer back-patches that at close), so only the fast path is unavailable. A probe must still answer "cannot tell yet" for an empty or truncated file rather than "not ours".

May change. MuxingApp, WritingApp and everything else libavformat writes by itself.

Why a tag as well as an attachment: Why a tag as well as an attachment A remux copies top-level tags; it copies attachments only when asked. ffmpeg -i in.mkv -c copy out.mkv -- the form a person types -- takes one track per media type and no attachments at all, so it leaves otc-meta.json behind, and a track rename can take the third marker with it. Before the tag, a remuxed recording carried nothing whatever that said what it was.

Thread safety: Thread safety The Recorder is not thread-safe. Call WriteFrame() from a single thread (typically the SDK callback thread). This header is not part of the sdk.h single-include header: include it as well, beside sdk.h or without it (see extra_includes).

Example: Example cpp #include "optris/sdk/rec/recorder.h" namespace rec = optris::sdk::rec; rec::GlobalConfig global; global.output_path = "recording.mkv"; // Every call here throws on failure, like the rest of the SDK's // C++ surface, and a full disk is not a rare case. Catch // optris::sdk::SdkException for any of them, or a derived type to // tell the refusals apart. try { auto recorder = rec::Recorder::Create(global); rec::StreamConfig stream; stream.width = imager->GetWidth(); stream.height = imager->GetHeight(); stream.frame_rate = 80.0f; recorder->AddVideoStream(stream); imager->SetThermalCallback([&](const optris::sdk::ThermalFrame &frame) { // A write can fail too: a disk fills up mid-recording. Decide // here whether one failed frame ends the take. recorder->WriteFrame(frame); }); } catch (const optris::sdk::InsufficientSpaceException &e) { std::println(stderr, "not enough room: {}", e.what()); } catch (const optris::sdk::SdkException &e) { std::println(stderr, "{}", e.what()); }

Call recorder->Stop() when the recording is finished -- from wherever your application decides that, not on the line after registering the callback.

See also: Player for playback of recorded files

See also: VideoExporter for re-encoding to standard formats

Thread-safe circular buffer that stores the most recent N thermal frames in memory. The SDK callback thread pushes frames; the recording controller flushes the buffer when a recording starts.

Several cameras into one file, on one clock, and back out again as one session.

An operator watching both sides of a furnace, or three points on a line, wants the dashboard recorded and replayed as it was seen: every camera in step, one file to archive and to send. Doing that with one recording per camera and a manifest beside them does not work, and the reason is worth stating because it is not obvious: each file's presentation times are measured from its own first frame. Two cameras are never started in the same microsecond, so the two files disagree from the start; and a camera that reports no capture stamp of its own -- which a PI over USB does, for every frame -- has its times synthesised from its nominal frame rate, so a camera running at 9.8 Hz and calling itself 10 Hz drifts by 2 % of elapsed time, without bound, for as long as the recording runs.

A session fixes that by taking the timing decision away from the cameras. One clock stamps every frame of every source, so the question "what did camera 1 see at the moment camera 0 saw this" has an answer in the file rather than in an application's guess.

What this is not: What this is not It is not a replacement for the per-camera recorder and does not change it. Imager::Recorder() and rec::Recorder behave exactly as they did, single-camera recordings open exactly as they did, and a session file is an ordinary Matroska file that any tool can probe.

This header is not part of the sdk.h single-include header: include it as well, beside sdk.h or without it (see extra_includes).

Example: Example cpp #include "optris/sdk/rec/session.h" namespace rec = optris::sdk::rec; rec::SessionConfig config; config.output_path = "dashboard.mkv"; // Every call on this surface throws on failure. Catch // optris::sdk::SdkException for any of them, or a derived type to // tell the refusals apart. try { auto session = rec::SessionRecorder::Create(config); // One AddSource() per camera, before Open(). The index it hands // back is how that camera is named for the rest of the session. rec::SessionSourceConfig north; north.stream.width = imager->GetWidth(); north.stream.height = imager->GetHeight(); north.stream.frame_rate = static_cast<float>(imager->GetDeviceInfo().frame_rate); north.name = "Furnace north"; north.device.model = imager->GetDeviceInfo().model; north.device.serial = imager->GetDeviceInfo().serial; const int index = session->AddSource(north); // Open before the first frame, so an unwritable path is an // answer you get while there is still somebody to give it to. session->Open(); // Hand every camera's frames in as they arrive. The session // stamps each one as this call is made, which is what puts all // of them on one timeline. imager->SetThermalCallback( [&session, index](const optris::sdk::ThermalFrame &f) { // A frame can be refused too: an unknown source, a full // hand-over queue. A callback must not let an exception // escape, so decide here what a dropped frame means. try { session->WriteFrame(index, f); } catch (const optris::sdk::SdkException &) { } }); } catch (const optris::sdk::SdkException &e) { std::println(stderr, "{}", e.what()); }

Unlike rec::Recorder, SessionRecorder::WriteFrame() is safe to call from several threads at once -- it has to be, because N cameras deliver on N callback threads. See the class for what it does with them.

Why the session takes frames and not cameras: Why the session takes frames and not cameras The obvious signature is SessionRecorder(std::vector<Imager *>), and it cannot work today: FrameSource::SetThermalCallback()` is a setter, not a subscription, so a session that registered itself would take the camera's frames away from the application that is drawing them. On a live dashboard -- which is the whole use case -- that is the one thing it must not do. Handing frames in costs the caller one line per camera and leaves its display alone. A camera-taking convenience becomes possible the day a FrameSource can have more than one frame subscriber.

See also: SessionPlayer for playing one back

See also: Recorder for the single-camera recorder, unchanged

Saving and loading single frames as self-describing image files.

PNG is the standard still format: 16-bit greyscale, lossless, and readable without any Optris-specific knowledge. The file states how to turn a pixel into a temperature, carries its metadata as JSON, and can hold arbitrary application files inside it. TIFF is the analysis export: one rigidly locked classic-TIFF profile, float32 by default, for ImageJ/Fiji, MATLAB, GDAL and tifffile. CSV is the plain table, spelled for a program by default or for a spreadsheet's locale on request (CsvOptions).

How a pixel becomes a temperature: How a pixel becomes a temperature Temperature pixels are anchored at absolute zero with a per-file scale, so a reader needs one number out of the file and one multiply: cpp T_kelvin = pixel * scale T_celsius = pixel * scale - 273.15 The scale is one of 0.01, 0.025 or 0.05 K, picked automatically from the camera's range. See temperature_grid.h.

The frame type decides what is in the file: The frame type decides what is in the file There is no encoding flag to get wrong. Passing a ThermalFrame writes temperature; passing a RawFrame writes uncalibrated detector counts, bit for bit. A file that claims one and contains the other is not expressible.

This header is in the single-include header, but Snapshot's companions (Recorder, Player, VideoExporter) are not -- see extra_includes.

Example: a radiometric PNG with a calibration blob: Example: a radiometric PNG with a calibration blob cpp // `frame` is whatever the thermal callback handed you. optris::sdk::rec::SnapshotInfo info; info.device_model = "Xi 400"; info.device_serial = "24120005"; info.emissivity = 0.95f; info.range_min_c = -20.0f; info.range_max_c = 100.0f; optris::sdk::rec::Attachment blob; blob.name = "calibration.bin"; // std::vector<std::byte>, not vector<uint8_t> -- it will not // convert. blob.data = LoadCalibration(); info.attachments.push_back(std::move(blob)); // Every call here throws on failure, like the rest of the SDK's // C++ surface. Catch optris::sdk::SdkException for any of them, or // a derived type to tell the refusals apart -- // InvalidArgumentException for a frame or a scale this format // cannot hold, IoException for a write that failed. try { optris::sdk::rec::Snapshot::SavePng(frame, "capture.png", info); // ... and getting it back, on another machine, later: auto back = optris::sdk::rec::Snapshot::ReadInfo("capture.png"); auto pixels = optris::sdk::rec::Snapshot::LoadThermal("capture.png"); } catch (const optris::sdk::SdkException &e) { std::println(stderr, "{}", e.what()); }

See also: Recorder for continuous recording

See also: temperature_grid.h for the pixel grid

See also: attachment.h for carrying application files

The pixel grid used by radiometric snapshots.

A temperature pixel is anchored at absolute zero and carries a per-file scale, so a reader needs one number out of the file and one multiply:

T_kelvin  = pixel * scale
T_celsius = pixel * scale - 273.15

There is no offset constant and no Optris magic number.

Why these three scales: Why these three scales A scale converts exactly from the SDK's internal int16 encoding (internal = celsius * 10 + 1000) and is exact in both Kelvin and Celsius when it divides both 0.1 and 273.15. That admits 0.01, 0.025 and 0.05, and rules out 0.1, which does not divide 273.15 and is the one step that would force rounding. Every rung here is therefore pure integer arithmetic in both directions, and internal -> pixel -> internal is bit-exact for every value the rung can represent.

Defines the error model, configuration structs, and lightweight data types used across the recording library.

Every fallible operation on this surface throws. Karl's direction, 2026-11-06: "the public api should emit exceptions". The types are in optris/sdk/exception.h, and RecordError below is what picks which one; see the table on ThrowRecording() in src/otc_sdk/recording_exception.h, and Result at the bottom of this file for what is left of the old shape and where it still lives.

The attachment seam lives in attachment.h, which this header pulls in so that everything that used to find Attachment and AttachmentProvider here still does.

The VideoExporter converts thermal frames to common video files for sharing and visualization. Two kinds of content (VideoContent): the thermal frames themselves, or the colorized picture. Thermal frames are written in one of two ways:

  • FFV1: the 16-bit samples themselves (GRAY16LE), losslessly. Every temperature comes back exactly.
  • A lossy codec (Motion JPEG, H.264, H.265, AV1, VP9): a "double height" picture, the high byte (MSB) of each sample in the top half and the low byte (LSB) in the bottom half of the luma plane. That picture does not keep the temperatures: a lossy codec moves the low bytes, and now and then a high byte, which is 25.6 C at once. So in a Matroska file (.mkv) the same frames also go to a second, lossless FFV1 track, and that track is what this SDK's player reads back, exactly. An MP4, MOV or WebM file cannot hold that track and keeps only the picture. VideoExporter::KeepsTemperatures() says which one you have. This header is not part of the sdk.h single-include header: include it as well, beside sdk.h or without it (see extra_includes).

Example: Example cpp #include "optris/sdk/rec/video_exporter.h" namespace rec = optris::sdk::rec; rec::VideoExportConfig config; config.output_path = "export.mkv"; config.width = imager->GetWidth(); config.height = imager->GetHeight(); config.frame_rate = 30.0f; config.codec = rec::VideoCodec::kFFV1; // Every call here throws on failure, like the rest of the SDK's // C++ surface. Catch optris::sdk::SdkException for any of them, or // a derived type to tell the refusals apart. try { auto exporter = rec::VideoExporter::Create(config); for (const optris::sdk::ThermalFrame &frame : frames) exporter->WriteFrame(frame); exporter->Finish(); } catch (const optris::sdk::FeatureNotSupportedException &e) { std::println(stderr, "no encoder for that codec: {}", e.what()); } catch (const optris::sdk::SdkException &e) { std::println(stderr, "{}", e.what()); }

See also: Recorder for lossless radiometric recording with metadata

Enumerations

AttachmentScope

enum AttachmentScope

Why the SDK is asking for attachments.

The same provider serves snapshots and recordings, and a segmented recording asks once per segment, so a provider that wants to distinguish those cases can.

Value Initialiser Description
kSnapshot A still image is being written (PNG or TIFF).
kRecording The first (or only) file of a recording is being written.
kRecordingSegment

AttachmentFormat

enum AttachmentFormat

Which container the SDK is about to write.

AttachmentScope says what kind of file it is; this says what the file is. The two are independent: a snapshot is one of four still formats, and every recording is a Matroska file.

A provider that has to answer differently per format reads this rather than the path. Reading AttachmentRequest::path and reconstructing the SDK's own format-to-extension mapping means owning a rule the SDK owns and can change.

kUnknown is zero so that a request nobody filled reads as "nobody said" rather than as a claim about the container, which is the convention this tree uses wherever a value could be mistaken for a statement (optris_sdk_image::has_frame_metadata, optris_sdk_frame_info::chip_temp_known, detector_settling). Nothing in the SDK leaves it unset today.

Value Initialiser Description
kUnknown = 0
kPng A PNG still. Carries attachments as otCa chunks.
kTiff A TIFF still. Carries attachments in private tag 65200.
kCsv
kJpeg
kMkv

PixelEncoding

enum PixelEncoding

What a pixel in the accompanying image means.

Value Initialiser Description
kTemperature
kRawAdu Uncalibrated detector counts, straight from the sensor.
kEnergy Linear radiometric energy, post-NUC and pre-PRN.
kColor

SegmentLimitAction

enum SegmentLimitAction

What a recording does when it reaches its segment limit, RecordingOptions::max_segment_bytes or RecordingOptions::max_segment_duration. Added in 12.0.10.

A separate setting rather than a field of RecordingOptions, so that the struct every existing caller builds keeps its size and layout. Set it on the camera with Imager::Recorder().SetSegmentLimitAction(), or pass it to Recorder::Create() when driving a Recorder directly. It has no effect on a recording with no segment limit.

No choice here knows or asks what the destination is. A limit is a number the application picked.

Value Initialiser Description
kContinueSeries = 0
kStartNewRecording = 1
kStopRecording = 2

RaviVerdict

enum RaviVerdict

What ImportRavi() would do with a file.

Value Initialiser Description
kConvertible = 0 Converts.
kShortWave = 1
kNoModel = 2
kUnreadable = 3 Not a .ravi, or unreadable.

SessionSourceKind

enum SessionSourceKind

What kind of camera one source of a session is.

Value Initialiser Description
kThermal = 0
kColor = 1

SessionTimestampSource

enum SessionTimestampSource

Which moment a frame's session time is taken from.

Value Initialiser Description
kHandover = 0
kFrameStamp = 1

SessionBacklogPolicy

enum SessionBacklogPolicy

What a session does with a frame it has no room for.

Value Initialiser Description
kDropNewest
kBlock

SessionSourceState

enum SessionSourceState

Whether a source is still producing.

Value Initialiser Description
kLive
kStalled
kEnded
kDisconnected

SessionSourcePresentation

enum SessionSourcePresentation

What a player should be putting on screen for one source right now.

This is a safety property, not a convenience: This is a safety property, not a convenience A viewer that holds a source's last frame across a hole shows a still picture of a scene nobody is watching, with nothing on it to say so. On a furnace, on a press, on anything that moves, a frozen picture read as a live one is the failure this enum exists to make impossible to reach by accident: a player asks what to show and is told, rather than defaulting to the last thing it had.

Value Initialiser Description
kPicture = 0 Frames are arriving for this source. Show them.
kDisconnected = 1
kEnded = 2

GridScale

enum GridScale

Step size of the absolute-zero-anchored pixel grid.

Value Initialiser Description
kScale10mK
kScale25mK 0.025 K per count. Covers up to 1365.2 C: the 150..900 range.
kScale50mK

RecordError

enum RecordError
Value Initialiser Description
kOk No error.
kInternal Internal FFmpeg or library error.
kInvalidParameter Bad argument (wrong dimensions, etc.).
kIoError File I/O failure.
kCodecNotFound
kInvalidState
kFileTooLarge
kPathExists
kInsufficientSpace

RecordingPhase

enum RecordingPhase

What happened to a recording.

Value Initialiser Description
kStarted = 0 A recording opened and is now taking frames.
kStopped = 1
kFailed = 2
kSegmentCompleted = 3
kSourceLost = 4
kSourceResumed = 5
kSourceEnded = 6
kDiscarded = 7
kSegmentPruned = 8
kRetentionShortened = 9

RecordingStopReason

enum RecordingStopReason

Who ended a recording.

On RecordingPhase::kStopped, and on nothing else. A program branches on this; RecordingEvent::message is the same answer in words, for a log a person reads.

Why this is a field and not a string to match on: Why this is a field and not a string to match on A Stopped with an empty message read exactly like the application's own stop, like a bounded recording reaching its duration, and like an alarm rule's stop. An earlier revision landed the message first and said in the header that a message is not the answer: an application that has to match text cannot be told apart from one that is guessing, and the text is free to be translated, reworded or lengthened without anybody thinking they have changed an interface.

The set is closed, and every value has a producer: The set is closed, and every value has a producer These five are what can end a recording in this SDK, and each one is written at exactly one place -- see the enumerator comments. scripts/check_recording_stop_producers.py fails the build if any value here has no producing line, on the precedent of check_alarm_signal_producers.py and for the same reason: a public enumerator that can never be delivered is a defect rather than a feature, because an application writes a branch for it and the branch is dead.

Value Initialiser Description
kUnknown = 0
kApplication = 1
kDuration = 2
kAlarmRule = 3
kReconnect = 4
kFailure = 5
kSegmentLimit = 6

StreamPixels

enum StreamPixels

What a video track of a recording holds.

Value Initialiser Description
kThermal16 = 0
kColor8 = 1

DiskFullAction

enum DiskFullAction

What to do when the volume is short of ContinuousPolicy:: min_free_bytes and pruning to the retention window has not fixed it.

There is no good answer here, only a choice between two bad ones, and an application that has not made the choice will discover which one it got at three in the morning. So it is a setting with no silent default behaviour behind it: both branches are observable through RecordingPhase::kRetentionShortened and both are counted.

Value Initialiser Description
kPruneBelowRetention = 0
kStopRecording = 1

PruneReason

enum PruneReason

Why the last prune happened.

Value Initialiser Description
kNone = 0 Nothing has been pruned.
kDuration = 1 RetentionPolicy::max_duration.
kBytes = 2 RetentionPolicy::max_bytes.
kFreeSpace = 3 RetentionPolicy::min_free_bytes.

VideoCodec

enum VideoCodec

Which encoder a video export asks for.

Which of these exist is a property of the FFmpeg that was linked and of the machine it runs on, not of this enum. Ask VideoExporter::IsCodecAvailable() before offering one.

Value Initialiser Description
kH264 H.264/AVC: widely compatible, good compression.
kH265
kAV1
kVP9 VP9: good compression, WebM compatible.
kFFV1 FFV1: lossless 16-bit preservation.
kMjpeg

VideoContent

enum VideoContent

What the frames handed to the exporter are.

Orthogonal to the codec, which until now was doing double duty as the content selector: "not FFV1" meant "pack 16 bits into two halves of a double-height luma plane". That packing makes a file no ordinary player can show, and through a lossy codec it does not keep the temperatures either; see kRadiometric.

Value Initialiser Description
kRadiometric
kColorized

VideoPreset

enum VideoPreset

Faster presets produce larger files but encode more quickly. Only applies to H.264 and H.265.

Value Initialiser Description
kUltrafast Fastest encoding, largest output.
kFast Fast encoding, good quality.
kMedium Balanced (default).
kSlow Slower encoding, best compression.

Typedefs

AttachmentProvider

std::function< std::vector< Attachment >(const AttachmentRequest &)> AttachmentProvider

Pulled once per file, as that file's header is written, and the only point at which attaching is possible.

Why a callback and not a setter: Why a callback and not a setter A recording started by an alarm is never started by the application, so there is no call it could hang a recorder->Attach(...) off. A manual start gives no usable window either: the provider is asked when the header is written, which is after StartRecording() has returned, and once the header is down MKV attachments can no longer be added. Asking the application, rather than waiting to be told, is what makes the manual and the triggered case the same case.

When: When The provider is asked before any frame is written to the file. That is the guarantee to rely on, and the reason the window exists at all: nothing reaches the file ahead of the attachments.

It is not asked while the file is being opened. Opening a recording is an avio_open() and nothing more; the header waits for the cover's look-ahead, which resolves on the first frame that makes a usable cover, at six frames, or at 400 ms of capture time, whichever comes first. So the provider is asked:

  • for a snapshot, inside the call that writes it;
  • for a recording, when that look-ahead resolves, after StartRecording() has returned;
  • for a recording that ended while the look-ahead was still unresolved, inside the call that stops it, which writes the frames still held.

A recording that received no frame at all asks nothing: Stop() removes its file rather than finishing it, so no header is written and no provider is called.

A consequence worth designing around: state the application sets up just after StartRecording() returns may or may not reach the file, depending on whether the look-ahead has resolved yet. Have what the provider needs ready before the recording starts.

Which thread, and what it holds: Which thread, and what it holds For a recording, never the thread that started it. It is: - the recording controller's own writer thread, which is where every frame a recording stores is encoded and written: a live frame, a flushed pre-roll and a segment rollover alike; - or the thread that stops a recording which ended while the look-ahead was unresolved: the application's own thread, or the SDK's timer thread for a bounded auto-stop.

The recording controller's mutex is not held while the provider runs. It is released before the write, and rec::Recorder has no mutex of its own at all.

For a snapshot it is the thread of the SaveSnapshot() call, the SDK's action thread for an alarm-fired one, or the SDK's timer thread for an interval capture.

Return promptly all the same. The writer thread is the one draining the queue, so a provider that blocks there lets the queue grow and, past its bound, costs frames. It does not stall frame delivery for the whole camera. And a provider that waits on a lock the application holds while calling StopRecording() still deadlocks: not against the mutex now, but because StopRecording() waits for the writer to finish the frame in flight. Do not block on I/O you cannot bound, and prepare the bytes in advance where possible.

Contract: Contract - Called synchronously, exactly once per file: once per snapshot, and once per segment for a segmented recording. - Returning an empty vector is normal and attaches nothing. - Throwing is caught, logged, and treated as returning nothing; the file is still written. An attachment is never a reason to lose a recording. - Do not call back into the imager's recording or snapshot methods from inside the provider: it re-enters the recorder the provider is supplying a header for. - AttachmentRequest::on_action_thread does not reliably tell you whether you are on an SDK thread; see the warning on that field.

Result

optris::sdk::Result< T, RecordError > Result

Wraps optris::sdk::Expected<T, Error<RecordError>>`. On success holds the value; on failure holds an Error with code and message.

Warning: No entry point in this namespace returns one any more. They throw; see the note at the top of this file. The alias is kept because Error<RecordError>andRecordError itself are still the vocabulary the refusals are built from, and because [optris::sdk::pif](/documentation/sdks/otc-sdk/v12.0/api/namespaces/optris.sdk.pif) still returns a Resultwhile that surface's own shape is decided. Using it on anything new is whaterror.h`'s warning forbids.

What a caller writes now (Recorder needs optris/sdk/rec/recorder.h, which is not in the single-include header; see extra_includes):

optris::sdk::rec::GlobalConfig config;
config.output_path = "recording.mkv";
try {
  auto recorder = optris::sdk::rec::Recorder::Create(config);
  // ... use it ...
} catch (const optris::sdk::SdkException &e) {
  std::println(stderr, "{}", e.what());
}

Functions

CanCarryAttachments

constexpr auto CanCarryAttachments(AttachmentFormat format) -> bool

Whether format has anywhere to put an attachment.

The SDK's own answer to its own container rule, which is why it is here rather than left for a provider to work out. Gate on this and use AttachmentFormat to decide what to attach rather than whether: a provider written against this keeps behaving when a fifth still format is added, and one that switches on the format itself has to be revisited.

kUnknown answers true, deliberately. It is not a format and so not a refusal; answering false would make a request built without a format quietly stop carrying anything.

AttachmentFormatName

constexpr auto AttachmentFormatName(AttachmentFormat format) -> const char *

The container's name, for a diagnostic. Never null.

AttachmentFormatOf

constexpr auto AttachmentFormatOf(::optris::sdk::SnapshotFormat format) -> AttachmentFormat

The container a still format writes.

ToString

OTC_SDK_API auto ToString(PixelEncoding encoding) -> std::string_view

Stable string form used in the JSON: "temperature", "raw_adu", "energy".

PixelEncodingFromString

OTC_SDK_API auto PixelEncodingFromString(std::string_view name) -> std::optional< PixelEncoding >

The inverse of ToString(). Returns nullopt for a name this build does not know, which is how a file from a newer writer is recognized rather than guessed at.

SerializeMetadata

OTC_SDK_API auto SerializeMetadata(const FileMetadata &meta) -> std::string

Serialize to the JSON of the shared schema.

Returns: The document.

Exceptions

Name Description
InvalidArgumentException when a required field (width, height) is unset.

ParseMetadata

OTC_SDK_API auto ParseMetadata(std::string_view json) -> FileMetadata

Parse the shared schema.

Returns: The document's fields.

Exceptions

Name Description
InvalidArgumentException on malformed JSON, on a missing required field, or on an otc_format this build does not understand.

SerializeFrameRecord

OTC_SDK_API auto SerializeFrameRecord(const FrameRecord &record) -> std::string

Serialize one per-frame record for the recording's metadata track.

ParseFrameRecord

OTC_SDK_API auto ParseFrameRecord(std::string_view json) -> FrameRecord

Read one per-frame record back.

Returns: The record.

Exceptions

Name Description
InvalidArgumentException for a payload that is not a record this build understands.

RaviVerdictName

OTC_SDK_API auto RaviVerdictName(RaviVerdict verdict) -> const char *

The verdict's name, as otc_ravi info prints it: "convertible", "short-wave", "no-model" or "unreadable".

InspectRavi

OTC_SDK_API auto InspectRavi(const std::string &path, const std::string &norm_directory={}) -> RaviInfo

Say what a .ravi holds and whether it converts.

Reads a few hundred kilobytes whatever the file's size. Never throws for a bad file: a missing, unreadable or foreign file is RaviVerdict::kUnreadable with the reason in RaviInfo::detail.

Parameters

Name Description
path The file, UTF-8.
norm_directory As RaviImportOptions::norm_directory. A file whose model is a normalization table needs the table to be judged convertible.

InspectRaviInZone

OTC_SDK_API auto InspectRaviInZone(const std::string &path, const std::string &norm_directory, const RaviTimeZone &zone) -> RaviInfo

InspectRavi(), with RaviInfo::recorded_at_utc placed in zone rather than in this computer's zone.

Exceptions

Name Description
InvalidArgumentException zone names a zone the platform does not know, gives both a name and an offset, or an offset past 18 hours. A bad file is still not an exception.

InspectRaviStartTime

OTC_SDK_API auto InspectRaviStartTime(const std::string &path, const RaviTimeZone &zone={}) -> RaviStartTime

Say when a .ravi started: the recording PC's clock reading as the file holds it, and that reading placed in zone.

Reads the first frame header only. Without a zone (the default), this computer's zone is used and RaviStartTime::time_zone_assumed says so; a conversion without a zone uses the same one.

Parameters

Name Description
path The file, UTF-8.
zone The recording PC's zone. Empty for this computer's.

Returns: The start; RaviStartTime::recorded_at_local is empty for a file that does not say, or that cannot be read.

Exceptions

Name Description
InvalidArgumentException zone cannot be used, as for InspectRavi().

InspectRaviFrameCounts

OTC_SDK_API auto InspectRaviFrameCounts(const std::string &path) -> RaviFrameCounts

Say how many frames a .ravi declares, and in which header.

Reads the headers and the RIFF part headers, a few hundred kilobytes whatever the file's size. Never throws for a bad file: RaviFrameCounts::readable is then false.

Parameters

Name Description
path The file, UTF-8.

ImportRavi

OTC_SDK_API auto ImportRavi(const std::string &source, const std::string &destination, const RaviImportOptions &options={}) -> RaviImportResult

Convert a .ravi into an SDK recording.

Temperatures are computed with PIX Connect's own model, frame by frame, from each frame's own header, so a recording whose emissivity or range changed while it ran converts correctly. The recording says when the original was recorded (Player::GetStartTimeUs()), which camera made it when the file says so, and carries PIX Connect's measuring areas as regions.

The recording is written beside destination under a temporary name and moved into place when it is complete. A failure or a cancel leaves nothing at destination, and a file already there is replaced only by a finished recording.

Parameters

Name Description
source The .ravi, UTF-8.
destination The .mkv to write, UTF-8.
options How to convert.

Returns: What was written, or RaviImportResult::cancelled.

Exceptions

Name Description
RaviDeclinedException The file has no radiometric model, or is short-wave without RaviImportOptions::allow_short_wave.
IoException The source cannot be read or is not a .ravi, or the destination cannot be written.
InvalidArgumentException A path is empty.

ImportRaviInZone

OTC_SDK_API auto ImportRaviInZone(const std::string &source, const std::string &destination, const RaviImportOptions &options, const RaviTimeZone &zone) -> RaviImportResult

ImportRavi(), reading the .ravi's start in the recording PC's time zone.

A .ravi stores its start as the recording PC's local clock, with no zone. The recording this writes always states a UTC start (Player::GetStartTimeUs()) and the zone it was read in (Player::GetStartTimeZone()). With zone, that zone. Without one (an empty RaviTimeZone, and ImportRavi()), this computer's zone, marked RecordingTimeZone::assumed, with a warning in the log and a note in the report: the start is then right only if this computer is in the zone the recording PC was in, and CorrectRaviStartTime() sets it right afterwards.

The report (RaviImportResult::report_json) gives recorded_at_local, recorded_at_utc, time_zone, utc_offset and time_zone_assumed.

Exceptions

Name Description
InvalidArgumentException zone cannot be used, as for InspectRavi(); also everything ImportRavi() throws.

CorrectRaviStartTime

OTC_SDK_API auto CorrectRaviStartTime(const std::string &recording, const RaviTimeZone &zone) -> RaviStartTime

Set the time zone of a recording converted from a .ravi, and with it the recording's UTC start.

For a recording converted without a zone, or with the wrong one. The start is read again from the recording PC's clock reading the conversion kept, in zone, and every place the recording states its start is rewritten to match: Player::GetStartTimeUs(), Player::GetStartTimeZone() (which then says corrected and no longer assumed), and the ravi block of otc-meta.json and ravi-origin.json. Works on recordings converted by any SDK release.

The recording is written again beside itself and renamed into place when it is whole, as Recorder::AttachToFile() does: it needs free space for a second copy while it runs, and a failure leaves it as it was.

Parameters

Name Description
recording The .mkv ImportRavi() wrote, UTF-8.
zone The recording PC's zone. Must name one.

Returns: The start as the recording now states it.

Exceptions

Name Description
InvalidArgumentException The recording was not converted from a .ravi: a recording of a camera states the zone and start of the computer that made it, which are known, so there is nothing to correct. Also for an empty or unusable zone, and for a recording in several parts.
IoException The recording cannot be read or rewritten.

CorrectRaviStartTimeUtc

OTC_SDK_API auto CorrectRaviStartTimeUtc(const std::string &recording, uint64_t utc_unix_us) -> RaviStartTime

Set the UTC start of a recording converted from a .ravi directly, when the instant is known some other way (a log, a second recording of the same event).

As CorrectRaviStartTime(), with the zone stated as the fixed offset between the recording PC's clock reading and utc_unix_us, rounded to the minute, and no zone name. The start itself is written exactly as given.

Parameters

Name Description
recording The .mkv ImportRavi() wrote, UTF-8.
utc_unix_us The real start, microseconds since the Unix epoch. Must be within 18 hours of the clock reading.

Exceptions

Name Description
As CorrectRaviStartTime().

OpenSeries

OTC_SDK_API auto OpenSeries(const std::string &path) -> SeriesView

Discover the series a recording belongs to, from any one of its parts.

Parameters

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

Returns: The view. A missing sibling is never an error.

Exceptions

Name Description
IoException only when path itself cannot be read.

GridScaleKelvin

OTC_SDK_API auto GridScaleKelvin(GridScale scale) -> double

Step size in Kelvin: 0.01, 0.025 or 0.05.

GridScaleFromKelvin

OTC_SDK_API auto GridScaleFromKelvin(double kelvin) -> std::optional< GridScale >

Map a step size read out of a file back onto a rung. Returns nullopt for any value that is not one of the three, so a foreign or corrupt scale is rejected rather than approximated.

GridScaleMinInternal

OTC_SDK_API auto GridScaleMinInternal(GridScale scale) -> int16_t

Lowest internal value the rung can represent. The same for all three rungs (-1731, or -273.1 C) because each is bounded below by pixel 0, which is absolute zero.

GridScaleMaxInternal

OTC_SDK_API auto GridScaleMaxInternal(GridScale scale) -> int16_t

Highest internal value the rung can represent, bounded above by pixel 65535.

GridScaleMaxCelsius

OTC_SDK_API auto GridScaleMaxCelsius(GridScale scale) -> float

Highest temperature the rung can represent, in Celsius: 382.2, 1365.2 or 3003.6.

GridScaleMinCelsius

OTC_SDK_API auto GridScaleMinCelsius() -> float

Lowest temperature any rung can represent, in Celsius: -273.1.

SelectGridScale

OTC_SDK_API auto SelectGridScale(float range_max_c) -> GridScale

The finest rung whose ceiling covers range_max_c: 0.01 K up to 382.2 C, 0.025 K up to 1365.2 C, 0.05 K above that.

InternalToPixel

OTC_SDK_API auto InternalToPixel(GridScale scale, int16_t internal, uint16_t *pixel) -> bool

Convert one internal value to its pixel.

Parameters

Name Description
scale Rung to convert on.
internal Value in the SDK's internal encoding.
pixel Receives the pixel; untouched when the value does not fit the rung.

Returns: False when internal falls outside [GridScaleMinInternal, GridScaleMaxInternal], that is, when it would land below absolute zero or above pixel 65535. Callers must not clip silently.

PixelToInternal

OTC_SDK_API auto PixelToInternal(GridScale scale, uint16_t pixel) -> int16_t

Convert one pixel back to its internal value.

Exact for every pixel this SDK writes. A pixel that is not on the rung's lattice (only possible in a file we did not write) is rounded to the nearest internal value rather than rejected, since a single stray pixel is not a reason to fail a whole image.

Variables

kOtcFormatVersion

constexpr int kOtcFormatVersion = 1

Schema version of the metadata document. Bumped only for a change a existing reader could not survive.

kSessionMetadataName

constexpr const char * kSessionMetadataName = "otc-session.json"

Name of the attachment a session writes into every file it produces, describing its sources. Readable with Player::GetAttachment() and with any tool that can list Matroska attachments, so a file can be identified as a session without decoding a single frame.

kOtcSessionFormatVersion

constexpr int kOtcSessionFormatVersion = 1

Schema version of that document. Raised only for a change an existing reader could not survive.

kSessionOutageOpen

constexpr uint64_t kSessionOutageOpen = UINT64_MAX

SessionOutage::until_us for an outage the file never closed.

kUnmeasuredPixel

constexpr std::uint16_t kUnmeasuredPixel = 0

The pixel that means "this pixel was not measured".

Zero, which is absolute zero on every rung and so a value no measurement can be: T_kelvin = 0 * scale is 0 K whichever rung the file declares, and no reader needs a table to see that is not a reading. It is also unreachable by construction: every rung is pixel = internal * mul + add with the pairs (10, 17315), (4, 6926) and (2, 3463), so pixel 0 would need an internal value of -1731.5 on all three. That is not an integer, and InternalToPixel() therefore never produces 0 for any input.

Radial distortion correction in Wide mode leaves output pixels with no source behind them, and a still of such a frame has to say so somewhere. The alternative was refusing to write the file at all: InternalToPixel() rejects optris::sdk::kInvalidPixel, because -3376.8 C is below absolute zero, and Snapshot's scale check refuses rather than clipping a measurement.