Playback
A recording opens as a frame source and measures like a camera. The regions travel inside the file, so a replayed frame is measured by the region that measured the live one. Writing the file is Recording.
In Fahrenheit: with the SDK switched to Fahrenheit (SetTemperatureUnit() and its counterparts, see Temperatures in Fahrenheit), every temperature on this page is read and written in Fahrenheit, and every difference in Fahrenheit degrees; the samples are unchanged.
The recording chapter is seven pages, each answering one question:
| Page | Question |
|---|---|
| Recording | How do I write a camera to a file? |
| A Running Recording | What is it telling me while it runs? |
| Recording File Format | What is the file, and what may a third party rely on? |
| Preview Pictures | Why does the file open on a picture, and which frame is it? |
| Snapshots and Interval Capture | How do I save one frame, or one every N seconds? |
| Recording Attachments | How do I put my own files inside the recording? |
| Playback | How do I read one back? |
Opening a Recording
Recorded MKV files are opened with Player::Open(). A Player fires the same callbacks as a live camera, measures its frames with the same region and alarm pass, and provides the same frame types.
#include <optrissdk.h> auto player = optris::sdk::Player::Open("/data/capture_001.mkv"); // Device info from the recording's embedded metadata. const auto& device = player->GetDeviceInfo(); auto serial = device.serial; auto model = device.model; auto w = player->GetWidth(); auto h = player->GetHeight();
optris_sdk_imager *playback = NULL; char serial[64]; char model[64]; uint32_t w = 0; uint32_t h = 0; optris_sdk_imager_create_from_file("/data/capture_001.mkv", &playback); /* Device info from the recording's embedded metadata. */ optris_sdk_imager_get_serial(playback, serial, sizeof(serial), NULL); optris_sdk_imager_get_model(playback, model, sizeof(model), NULL); optris_sdk_imager_get_width(playback, &w); optris_sdk_imager_get_height(playback, &h);
await using var playback = ThermalCamera.OpenRecording("capture_001.mkv"); // Device info from the recording's embedded metadata. string serial = playback.Serial; string model = playback.Model; int w = playback.Width; int h = playback.Height;
playback = optris_sdk.Camera.open_recording('capture_001.mkv') # Device info from the recording's embedded metadata. serial = playback.serial model = playback.model w, h = playback.width, playback.height
let playback = Camera::from_file("capture_001.mkv")?; // Device info from the recording's embedded metadata. let serial = playback.serial()?; let model = playback.model()?; let (w, h) = (playback.width()?, playback.height()?);
Player::Open() throws IoException if the file cannot be opened or is not a valid recording.
A recording in several files, played as one
A recording started with a segment limit is written as several files, run_part000.mkv, run_part001.mkv and so on (see Splitting a long recording). Player::Open() plays the one file it is given. Player::OpenSeries() plays the whole recording, from its first frame to its last, whichever of its files it is given, so the file a user double-clicks is enough.
#include <optrissdk.h> // Any file of the recording will do; this is its second. auto player = optris::sdk::Player::OpenSeries("/data/run_part001.mkv"); std::println("{} files, {:.1f} s", player->GetSeriesPartCount(), player->GetDurationUs() / 1e6); // A position in the whole recording: here, ten seconds before its end, // which is in its last file. player->SeekToTimestamp(player->GetDurationUs() - 10'000'000); std::println("playing file {}", player->GetSeriesPart()); player->Start();
optris_sdk_imager *playback = NULL; uint64_t duration_us = 0; uint32_t part = 0; uint32_t parts = 0; /* Any file of the recording will do; this is its second. */ if (optris_sdk_imager_create_from_series("/data/run_part001.mkv", &playback) != OPTRIS_SDK_OK) { /* A file of the recording is missing, or this one cannot be read: the message says which. */ fprintf(stderr, "%s\n", optris_sdk_last_error_message()); return; } optris_sdk_imager_get_playback_duration_us(playback, &duration_us); optris_sdk_imager_get_playback_part(playback, &part, &parts); printf("%u files, %.1f s\n", (unsigned)parts, duration_us / 1e6); /* A position in the whole recording, ten seconds before its end. */ optris_sdk_imager_seek_to_timestamp_us(playback, duration_us - 10000000); optris_sdk_imager_get_playback_part(playback, &part, &parts); printf("playing file %u\n", (unsigned)part); optris_sdk_imager_start(playback); optris_sdk_imager_destroy(playback);
// Any file of the recording will do; this is its second. await using var playback = ThermalCamera.OpenRecordingSeries("/data/run_part001.mkv"); Console.WriteLine($"{playback.PlaybackPartCount} files, " + $"{playback.PlaybackDuration}"); // A position in the whole recording, ten seconds before its end. playback.SeekTo(playback.PlaybackDuration - TimeSpan.FromSeconds(10)); Console.WriteLine($"playing file {playback.PlaybackPart}"); playback.Start();
import os import tempfile # Make a recording of three one-second files to play back. folder = tempfile.mkdtemp() camera.start_recording(os.path.join(folder, 'run.mkv'), options=optris_sdk.RecordingOptions( max_segment_duration_s=1.0)) time.sleep(2.6) camera.stop_recording() # Any file of the recording will do; this is its second. with optris_sdk.Camera.open_recording_series( os.path.join(folder, 'run_part001.mkv')) as playback: print(f'{playback.playback_part_count} files, ' f'{playback.playback_duration_s:.1f} s') playback.start() playback.pause_playback() # A position in the whole recording, half a second before its end. playback.seek_to(playback.playback_duration_s - 0.5) print(f'playing file {playback.playback_part}') playback.stop()
// Any file of the recording will do; this is its second. let mut playback = Camera::from_series("/data/run_part001.mkv")?; let (_, parts) = playback.playback_part()?; let duration_us = playback.playback_duration_us()?; println!("{parts} files, {:.1} s", duration_us as f64 / 1e6); // A position in the whole recording, ten seconds before its end. playback.seek_to_timestamp_us(duration_us.saturating_sub(10_000_000))?; let (part, _) = playback.playback_part()?; println!("playing file {part}"); playback.start()?;
A whole recording, one with no segment limit, opens with OpenSeries() exactly as with Open(), and so does every recording written by an earlier version: an application can open every recording the same way.
What "as one" means
- One length and one clock.
GetDurationUs()is the length of all the files together.GetPositionUs()runs on from one file into the next, so the first frame of the second file comes one frame after the last frame of the first, which is when it was recorded. A frame whose camera gave no timestamp of its own is stamped on that same clock instead of starting again at zero in each file. - Seeking anywhere.
SeekToTimestamp()takes a position in the whole recording and goes to the file that holds it.SeekToFrame()counts frames across the files. - From the start. Playback begins at the first frame of the first file, whichever file was opened.
GetSeriesPart()says which file is playing, counting from 0, the number in the file's_partNNNsuffix. - Measuring areas and alarms carry on. Each file's measuring areas reach the player in order, so a measuring area keeps its id from one file into the next and an alarm rule on it keeps its state. Each file of a recording made with this version starts with every measuring area complete, so a jump straight into its fifth file finds them there.
- One set of files carried.
GetAttachments()lists each file the recording carries once, not once per file: the first file's copy, and any file that only a later one carries, such as one an application attached to that file after it was finished. - One file open at a time. A recording that runs for days does not hold a decoder open for each of its files.
The files of a recording are found beside the one you open by the recording id that each of them carries, not by their names alone. Another recording in the same folder whose names happen to match is not taken for part of this one. rec::OpenSeries() lists the files without playing anything; see Recording File Format.
A missing file
If a file in the middle of the recording is missing, OpenSeries() refuses to open it and throws IoException, OPTRIS_SDK_ERROR_IO from C, whose message names the missing file. Playing across the gap would join two stretches of the recording that were never next to each other, and every time after the gap would be wrong by its length, which nothing in the other files records. Each file that is there still opens on its own with Open().
The last file of a recording cannot be told missing from the files before it: no file can know, when it is written, whether another will follow.
Exporting to an ordinary video
A recording can be turned into a video for people with no thermal tooling: rec::VideoExporter (optris/sdk/rec/video_exporter.h) converts thermal frames to common video files. MJPEG is present in every build; H.264, H.265, AV1 and VP9 are used where the machine carries an encoder, and VideoExporter::Create() throws, naming the codec, where it does not. Lossless FFV1 keeps the raw 16-bit data, and so does any radiometric export into a Matroska file; see Keeping the temperatures.
Keeping the temperatures
A radiometric export (VideoContent::kRadiometric, the default) is handed the thermal frames. Whether their temperatures survive depends on the codec and on the kind of file:
- FFV1 keeps every temperature, in any file that takes FFV1.
- Motion JPEG (the default), H.264, H.265, VP9 and AV1 write the frames as a double-height picture, the high byte of each value above and the low byte below. No ordinary player shows that picture usefully, and it does not keep the temperatures: the codec changes them by up to tens of degrees. So in a Matroska file (
.mkv) the export also writes the same frames to a second, lossless track, and that is the track the SDK reads back when the file is opened: every temperature comes back exactly. - An MP4, MOV or WebM file cannot hold the lossless track. A radiometric export into one keeps only the picture and logs a warning when it is created, and the SDK opens it as a picture, with no temperatures.
The exact copy makes a .mkv export larger and slower. Through Motion JPEG the file is roughly 2 to 5 times its size without the copy (up to about 20 times on a very noisy scene at quality 4). Through H.264 or H.265 it is many times larger (5 to 30 times on an ordinary scene, several hundred times on a noisy one), because those codecs make very small files by throwing detail away, and the exact copy keeps all of it. Writing it also takes longer. Measured on one Linux computer, 300 frames each:
| 300 frames | picture only | .mkv with the exact copy |
export time, picture only | export time, with the copy |
|---|---|---|---|---|
| 640 x 480, smooth scene, Motion JPEG (default) | 19.3 MB | 63.6 MB | 0.6 s | 3.3 s |
| 640 x 480, smooth scene, H.264 | 2.0 MB | 46.3 MB | 0.6 s | 3.2 s |
| 640 x 480, hot spot, Motion JPEG | 4.7 MB | 8.0 MB | 0.3 s | 0.8 s |
| 640 x 480, sensor noise, Motion JPEG | 11.2 MB | 56.9 MB | 0.6 s | 3.4 s |
| 160 x 120, smooth scene, Motion JPEG | 2.3 MB | 5.3 MB | 0.06 s | 0.24 s |
Even with the copy, the export writes about 90 frames a second at 640 x 480, about three times what a camera delivers, so a live export keeps up. The exact copy alone costs about what an FFV1 export of the same frames costs.
If you only want a picture to look at, you do not need the copy: an export into .mp4 gives the picture only, at its earlier size and speed, and a colour export (VideoContent::kColorized) gives an ordinary video in the palette you chose, which any player shows. Neither keeps the temperatures.
VideoExporter::KeepsTemperatures() says which of these an export is. Before 12.0.28 only FFV1 kept the temperatures, although the documentation said every radiometric export did. Measured on one Linux computer on a smooth 160 by 120 scene, reading the export back through the SDK and comparing every pixel:
| export | up to 12.0.27 | from 12.0.28, .mkv |
|---|---|---|
| Motion JPEG, best quality (2) | no temperatures (a picture); unpacked by hand: mean 2.35 C, 95th percentile 25.5 C, worst 51.4 C | exact (worst 0.0 C) |
| Motion JPEG, quality 31 | no temperatures; by hand: mean 2.76 C, worst 30.8 C | exact |
| H.264 | no temperatures; by hand: mean 6.25 C, worst 409.6 C | exact |
| VP9 | no temperatures; by hand: mean 5.85 C, worst 461.4 C | exact |
| AV1 | no temperatures; by hand: mean 8.40 C, worst 409.4 C | exact |
| FFV1 | exact | exact |
#include <optrissdk.h> optris::sdk::rec::VideoExportConfig config; config.output_path = "/data/archive.mkv"; config.width = w; config.height = h; config.frame_rate = 30.0F; auto exporter = optris::sdk::rec::VideoExporter::Create(config); const bool keeps = exporter->KeepsTemperatures(); // false for .mp4
optris_sdk_video_export_config config; optris_sdk_video_export *exporter = NULL; int keeps = 0; optris_sdk_video_export_config_init(&config, sizeof(config)); snprintf(config.output_path, sizeof(config.output_path), "/data/archive.mkv"); config.width = w; config.height = h; config.frame_rate = 30.0f; optris_sdk_video_export_create(&config, &exporter); optris_sdk_video_export_keeps_temperatures(exporter, &keeps); /* 0 for .mp4 */
using var export = VideoExport.Create(new VideoExportOptions { OutputPath = "archive.mkv", Width = w, Height = h, FrameRate = 30.0f, }); bool keeps = export.KeepsTemperatures; // false for .mp4
export = optris_sdk.VideoExport.create('archive.mkv', w, h, 30.0) keeps = export.keeps_temperatures # False for .mp4
let config = VideoExportConfig::new("archive.mkv", w, h, 30.0)?; let export = VideoExport::create(&config)?; let keeps = export.keeps_temperatures()?; // false for .mp4
Quality and file size
VideoExportConfig::bitrate_kbps chooses between two ways of encoding H.264, H.265, VP9 and AV1. Above 0, the encoder aims at that bitrate: the file has a predictable size and the quality is whatever fits. At 0, the default, the export aims at a quality instead, and the file is as large as the pictures need. Every encoder the SDK can use runs in its own constant-quality mode, at a setting measured to give the same quality on all of them, so the same export looks the same and has a comparable size on any computer. MJPEG has its own mjpeg_quality, and FFV1 is lossless.
The common quality is that of x264's default setting (CRF 23 at its medium preset). x264 itself is never used by the SDK; it only serves as the yardstick. On a two-second false-colour clip (60 pictures of 640 by 480, a figure walking through a room with a slow pan and camera noise, Iron palette) it gives a PSNR of 46.3 dB and an SSIM of 0.985 against the original pictures, measured with FFmpeg's psnr and ssim filters.
The preset (kUltrafast to kSlow) does not change that quality. It decides how hard an H.264 or H.265 encoder works to reach it: a slower preset gives a smaller file of about the same quality.
The same clip at kMedium, with no bitrate, before and after 12.0.23 (the earlier figures were measured with 12.0.21; 12.0.22 sets the encoders the same way):
| encoder | measured on | up to 12.0.22: size, PSNR | 12.0.23: size, PSNR, SSIM |
|---|---|---|---|
Windows' own H.264 encoder (h264_mf) |
Windows 11 | 70 KB, 44.3 dB | 131 KB, 46.2 dB, 0.984 |
NVIDIA H.264 (h264_nvenc) |
RTX A1000 | 473 KB, 49.1 dB | 41 KB, 46.5 dB, 0.985 |
NVIDIA H.264 (h264_nvenc) |
Quadro P2000 | 560 KB, 48.9 dB | 44 KB, 46.6 dB, 0.985 |
Intel QuickSync H.264 (h264_qsv) |
Intel graphics, Windows | 30 KB, 46.5 dB | 28 KB, 46.3 dB, 0.985 |
VA-API H.264 (h264_vaapi) |
Intel UHD 770, Linux | 132 KB, 47.9 dB | 58 KB, 46.2 dB, 0.984 |
NVIDIA H.265 (hevc_nvenc) |
RTX A1000 | 443 KB, 49.2 dB | 26 KB, 46.4 dB, 0.984 |
NVIDIA H.265 (hevc_nvenc) |
Quadro P2000 | 608 KB, 49.3 dB | 35 KB, 46.1 dB, 0.982 |
Intel QuickSync H.265 (hevc_qsv) |
Intel graphics, Windows | 18 KB, 47.1 dB | 15 KB, 46.2 dB, 0.984 |
Windows' own H.265 encoder (hevc_mf) |
Intel graphics, Windows 11 | not used: refused every picture | 24 KB, 46.5 dB, 0.984 |
VA-API H.265 (hevc_vaapi) |
Intel UHD 770, Linux | 29 KB, 47.3 dB | 21 KB, 46.3 dB, 0.984 |
VP9 in software (libvpx-vp9) |
Linux and Windows | 24 KB, 47.8 dB | 15 KB, 46.3 dB, 0.985 |
Intel QuickSync VP9 (vp9_qsv) |
Intel graphics, Windows | 401 KB, 48.6 dB | 88 KB, 47.9 dB, 0.986 |
VA-API VP9 (vp9_vaapi) |
Intel UHD 770, Linux | 81 KB, 45.0 dB | 45 KB, 46.4 dB, 0.983 |
Intel QuickSync AV1 (av1_qsv) |
Intel graphics, Windows | 13 KB, 45.0 dB | 18 KB, 46.4 dB, 0.985 |
AV1 in software (libaom-av1) |
Linux and Windows | 12 KB, 48.3 dB | 7 KB, 46.2 dB, 0.985 |
The sizes that remain are the encoders' own efficiency: at one quality, H.265, VP9 and AV1 need fewer bytes than H.264, and Windows' own H.264 encoder more than the graphics cards'. Intel's VP9 encoder cannot go down to the common quality and stays slightly above it. Which encoder an export uses is reported by VideoExporter::EncoderName().
Whether a file got larger or smaller from 12.0.22 to 12.0.23 depends on what is in the pictures, so the table does not tell you which way your own files moved. Windows' own H.264 encoder went both ways with the same setting. On the clip above its file grew from 70 KB to 131 KB. On ten seconds of a still scene (300 false-colour pictures of 640 by 480 from the simulated camera, a hot spot that does not move), it wrote 57,644 bytes with 12.0.22 and 32,240 bytes with 12.0.23, on a Windows 11 computer. What the setting fixes is the quality an export aims at; the size follows from the pictures.
On Windows, H.265 comes from the graphics card first (NVIDIA, Intel QuickSync, AMD), and Windows' own H.265 encoder is tried last. That one also runs on the graphics card, and it writes MP4 files but not Matroska (.mkv) files: it hands over the video's header information only inside the pictures, and Matroska needs it before the first one. So on a computer where only Windows' own encoder can make H.265, an MP4 export works, an .mkv export is refused by VideoExporter::Create() with a message that says so, and VideoExporter::IsCodecAvailable() answers no for H.265, because its yes holds for both kinds of file.
To get a file of a known size rather than a known quality, set a bitrate. Nothing else changes:
#include <optrissdk.h> optris::sdk::rec::VideoExportConfig config; config.output_path = "/data/share.mp4"; config.width = w; config.height = h; config.frame_rate = 30.0F; config.codec = optris::sdk::rec::VideoCodec::kH264; config.content = optris::sdk::rec::VideoContent::kColorized; config.bitrate_kbps = 2000; // 2 Mbit/s; 0 (the default) aims at quality auto exporter = optris::sdk::rec::VideoExporter::Create(config);
optris_sdk_video_export_config config; optris_sdk_video_export *exporter = NULL; optris_sdk_video_export_config_init(&config, sizeof(config)); snprintf(config.output_path, sizeof(config.output_path), "/data/share.mp4"); config.width = w; config.height = h; config.frame_rate = 30.0f; config.codec = OPTRIS_SDK_VIDEO_CODEC_H264; config.content = OPTRIS_SDK_VIDEO_CONTENT_COLORIZED; config.bitrate_kbps = 2000; /* 2 Mbit/s; 0 (the default) aims at quality */ optris_sdk_video_export_create(&config, &exporter);
var options = new VideoExportOptions { OutputPath = "share.mp4", Width = w, Height = h, FrameRate = 30.0f, Codec = VideoCodec.H264, Content = VideoContent.Colorized, BitrateKbps = 2000, // 2 Mbit/s; 0 (the default) aims at quality }; using var export = VideoExport.Create(options);
export = optris_sdk.VideoExport.create( 'share.mp4', w, h, 30.0, codec=optris_sdk.VIDEO_CODEC_H264, content=optris_sdk.VIDEO_CONTENT_COLORIZED, bitrate_kbps=2000) # 2 Mbit/s; 0 (the default) aims at quality
let mut config = VideoExportConfig::new("share.mp4", w, h, 30.0)?; config.codec = VideoCodec::H264; config.content = VideoContent::Colorized; config.bitrate_kbps = 2000; // 2 Mbit/s; 0 (the default) aims at quality let mut export = VideoExport::create(&config)?;
Playback Controls
| Method | Description |
|---|---|
SeekToFrame(uint64_t index) |
Jump to a frame by zero-based index. |
SeekToTimestamp(uint64_t us) |
Jump to the frame nearest an offset into the recording, in microseconds from its first frame. The same quantity GetPositionUs() reports, so 0 <= us <= GetDurationUs() covers every target this call accepts. It is not a frame's capture stamp; ThermalFrame::GetMetadata().timestamp_us is that, and it counts from an epoch of the transport's own. |
SetSpeed(float speed) |
Speed multiplier. 1.0 = real-time, 2.0 = double speed, 0.5 = half speed. |
GetSpeed() |
Current speed multiplier. |
SetLoop(bool loop) |
Enable or disable looping. When enabled, playback restarts from the first frame after the last one. |
IsLooping() |
Whether looping is enabled. |
GetDurationUs(), GetPositionUs() |
Length of the recording and the current position, in microseconds. |
GetDroppedFrameCount() |
How many decoded frames were discarded because the consumer could not keep up. See below. On FrameSource, so the same call works on a live camera and on a still. |
GetTelemetry(), GetRadiation() |
The telemetry and radiation parameters recorded with the current frame. On FrameSource, so the same call works on a live camera. |
Seeking is frame-accurate, and a recording is not all-intra
Those two facts together are the whole of why a seek costs anything.
A recording this SDK writes is not all-intra: a 299-frame take carries 25 keyframes, not 299, roughly one in twelve, which ffprobe -show_entries packet=flags will confirm on any file it produces. A 240-frame take has 20 anchors to 220 predicted frames. So the demuxer can only ever restart at the keyframe at or before the frame you asked for.
The frames in between are decoded and not delivered. The first frame out of a seek is the frame you asked for, and GetPositionUs() never steps backward after one.
What a seek costs
The undershoot is paid as decode time rather than as wrong pictures. The walk never sleeps, so a seek costs decode, not the playback time of the span it crosses. Two counters say what the last one paid:
| reaches back to | counter | worst case | |
|---|---|---|---|
| the picture | the keyframe at or before the target | GetLastSeekWalkedFrames() |
one keyframe interval of decode |
| the measuring areas | wherever their records were last applied | GetLastSeekReplayedRecords() |
the record track from the start of the file, nothing decoded |
Measured at the target furthest from a keyframe, 11 frames on a 12-frame grid, on a loaded shared workstation, so these are pessimistic rather than best-case:
| recording | frames walked | seek cost | per frame | playing the same span |
|---|---|---|---|---|
| 64×48 at 27 Hz | 11 | 0.47–0.74 ms | 42–67 µs | 407 ms |
| 64×48 at 32 Hz | 11 | 0.67–1.8 ms | 61–160 µs | 344 ms |
| 640×480 at 32 Hz | 11 | 23–25 ms | 2.1–2.3 ms | 344 ms |
Three runs, one-minute load average between 32 and 41 on a 24-core machine shared with other work, so the upper end of each range is a loaded figure and the real cost on an idle machine is lower. The ranges are what three runs produced: the one outlier (1.8 ms at 64×48) is a single run under rising load, and the 640×480 figure that matters varied by under 10 per cent across all three.
Planning a scrub around the seek cost
Plan against the 640×480 figure: about 25 ms at worst, half a frame period at 20 Hz. A scrub that issues a seek per mouse-move will feel it at the far end of each keyframe interval. The cost is proportional to how far past the keyframe you land, so the average is about half of it, and nothing but the decode thread waits. Coalescing seeks during a drag and honouring only the last removes it entirely.
The measuring areas pay differently
The measuring areas have a worst case of a different shape. A seek forward replays only the records between where the replay was and where it is going; a seek backward replays them from the start of the file. Nothing is decoded for it, so it is demux of a text track (on a 77-frame take, 59 records against 11 decoded frames), but on a long recording a backward seek is proportional to where it lands. See Recording what the measuring areas do.
rec::FrameIndex: ask the file rather than hardcoding a bound
Neither bound is a constant. A fixed "catch up fifteen frames" is wrong on the first file whose keyframe interval differs. rec::FrameIndex answers what a given file's interval is before you seek, reading packet headers and decoding nothing:
#include <optrissdk.h> // Throws IoException if the file will not open, so a caller that // cannot do anything about that lets it out. const auto index = optris::sdk::rec::FrameIndex::Build("/data/run.mkv"); // What a seek to frame 100 will have to decode and throw away. const uint64_t anchor = index.AnchorFor(100); const uint64_t walk = 100 - anchor; player->SeekToFrame(100); // lands exactly on frame 100 // player->GetLastSeekWalkedFrames() == walk
optris_sdk_frame_index *index = NULL; uint64_t anchor = 0; optris_sdk_frame_index_open("/data/run.mkv", &index); /* What a seek to frame 100 will have to decode and throw away. */ optris_sdk_frame_index_anchor_for(index, 100, &anchor); optris_sdk_imager_seek_to_frame(playback, 100); /* lands on frame 100 */ optris_sdk_frame_index_close(index);
using FrameIndex index = FrameIndex.Open("run.mkv"); // What a seek to frame 100 will have to decode and throw away. ulong anchor = index.AnchorFor(100); ulong walk = 100 - anchor; playback.SeekToFrame(100); // lands exactly on frame 100
index = optris_sdk.FrameIndex.open('run.mkv') # What a seek to frame 100 will have to decode and throw away. anchor = index.anchor_for(100) walk = 100 - anchor playback.seek_to_frame(100) # lands exactly on frame 100
let index = FrameIndex::open("run.mkv")?; // What a seek to frame 100 will have to decode and throw away. let anchor = index.anchor_for(100)?; let walk = 100 - anchor; playback.seek_to_frame(100)?; // lands exactly on frame 100
| Call | Answers |
|---|---|
Build() |
makes one pass over the container reading packet headers and decodes nothing, so it costs the same per frame on an hour-long take as on a one-second one |
Count() |
the exact frame count from the container, rather than GetDurationUs() * fps, which is an estimate over a declared rate and is wrong whenever the camera did not deliver at it |
AnchorFor() |
the keyframe at or before a given frame |
AnchorCount() |
how sparse the anchors are in the file in front of you, read from the container's own keyframe flags rather than guessed |
At(), FrameAt(us), DurationUs() |
map between frames and timestamps for a timeline |
If recordings ever become all-intra, every entry reports anchor == true, AnchorFor() becomes the identity, and code written against it keeps working with nothing to decode forward. Whether the recorder should write all-intra is still open.
GetDroppedFrameCount on a replay
A slow consumer loses frames, and says so. The pull queue between the decoder and your callback is four deep and discards on overflow. GetDroppedFrameCount() is the number discarded; delivered plus dropped adds up to the recording exactly.
Reachable from C, C#, Python and Rust as optris_sdk_imager_get_dropped_frame_count() and ThermalCamera.DroppedFrameCount, on a replay as well as on a camera. Which frame is lost differs from a camera's, and only a camera lets you choose: Imager::SetFrameQueuePolicy() defaults to dropping the oldest, so a pull returns one of the most recent frames, while a replay always keeps what is queued and loses the arriving frame. A slow consumer therefore receives an older subset out of a replay than out of a camera.
auto player = optris::sdk::Player::Open("/data/run.mkv"); player->SetSpeed(2.0f); player->SetLoop(true); player->SetThermalCallback([](const optris::sdk::ThermalFrame &f) { Process(f); }); player->Start();
optris_sdk_imager *playback = NULL; optris_sdk_frame *frame = NULL; optris_sdk_imager_create_from_file("/data/run.mkv", &playback); optris_sdk_imager_set_playback_speed(playback, 2.0F); optris_sdk_imager_set_loop(playback, 1); optris_sdk_imager_start(playback); while (optris_sdk_imager_acquire_frame(playback, 2000, &frame) == OPTRIS_SDK_OK) { Process(frame); optris_sdk_frame_free(frame); frame = NULL; }
await using var playback = ThermalCamera.OpenRecording("run.mkv"); playback.PlaybackSpeed = 2.0f; playback.IsLooping = true; playback.Start(); await foreach (ThermalFrame frame in playback.FramesAsync(token)) { using (frame) { Process(frame); } }
playback = optris_sdk.Camera.open_recording('run.mkv') playback.playback_speed = 2.0 playback.is_looping = True playback.start() for frame in playback.frames(): process(frame)
let mut playback = Camera::from_file("run.mkv")?; playback.set_playback_speed(2.0)?; playback.set_loop(true)?; playback.start()?; while let Some(frame) = playback.acquire_frame(2000)? { process(&frame); }
Seeking takes either unit:
player->SeekToTimestamp(player->GetDurationUs() / 2); // halfway player->SeekToFrame(100);
uint64_t duration_us = 0; optris_sdk_imager_get_playback_duration_us(playback, &duration_us); optris_sdk_imager_seek_to_timestamp_us(playback, duration_us / 2); optris_sdk_imager_seek_to_frame(playback, 100);
playback.SeekTo(playback.PlaybackDuration / 2); // halfway playback.SeekToFrame(100);
playback.seek_to(playback.playback_duration_s / 2) # halfway playback.seek_to_frame(100)
playback.seek_to_timestamp_us(playback.playback_duration_us()? / 2)?; playback.seek_to_frame(100)?;
What a recording can be asked, and what it cannot
GetRadiation(), GetTelemetry() and GetConfig() are on FrameSource, not on Imager: a camera reports what is in force, a recording what it was made with. The C entry points follow: optris_sdk_imager_get_radiation(), optris_sdk_imager_copy_config() and optris_sdk_imager_get_flag_open() all take a recording handle as well as a camera.
Setting the global radiation reaches the pixels
It does follow, on a recording that carries what the change needs, and it reaches the pixels, not just the report. A .mkv stores finished temperatures, so the emissivity and the transmissivity that produced every reading are baked in. The way out is not to relabel them but to recover the energy each stored temperature came from, through the characteristic curve the file carries, and read it back out of a table rebuilt at the new value. It costs the stored tenth of a kelvin and nothing else: measured, 0.20 K at emissivity 0.90 and 0.30 K at 0.50.
CanChangeRadiation: ask first rather than catching
Player::CanChangeRadiation() (optris_sdk_imager_playback_can_change_radiation(), ThermalCamera.PlaybackCanChangeRadiation, Camera.playback_can_change_radiation, Camera::playback_can_change_radiation()) answers whether this file can take the change, fixed when the file is opened. It is false for a recording written before the radiometry bundle was carried, for one from a camera with no characteristic curve, and for one whose bundle does not reproduce its own curve; ApplyConfig() then throws FeatureNotSupportedException rather than answering out of a calibration that does not match the frames. A user interface greys the emissivity slider on that answer, which an exception is a poor way to discover. On a paused replay, call Refresh() after the change or the picture does not move until the next frame.
Two things a recording cannot be told
A different temperature range: ApplyConfig() throws, because a different range is a different calibration. And ambient estimation and the two emissivity-image flags are not carried over by the C setter even where the rest is accepted: estimation is a live pipeline refolding its table from a housing temperature, and the image flags describe what a GPU backend does with a per-region map, neither of which a replay has. Applying a recording's own record back is always accepted, so round-tripping a configuration works.
Re-deriving a recording fully is not here yet
Re-deriving a recording fully (size-of-source correction, the noise filters, detail enhancement, distortion) is a wanted feature and is not here yet. Those have no setter on Player at all: they live on Imager::Processing() and a replay runs no pipeline backend. What that needs is a recording that stores what the camera measured rather than what the SDK made of it (the schema already names raw_adu and energy) and a replay that runs those values back through the pipeline.
What the per-frame record does not hold
A recording cannot answer anything its frame records do not carry. optris_sdk_imager_get_nuc_in_progress() and optris_sdk_imager_get_temperature_range() refuse a recording: the per-frame record holds the sequence, the timestamp, three temperatures and the shutter state, and nothing else, so answering would mean reporting a default that no caller could tell from a reading. The range the recording was made with is in the configuration record instead.
Opening a still as a measurable source
A snapshot is a measurement, not a picture of one: it carries the temperatures and the settings they were computed at. StillSource::Open() turns one back into something an operator can interrogate: open the file, drop a measuring area on it, read what the temperature was. It is the third implementation of FrameSource, beside Imager and Player, so regions, alarms, palettes and colour scaling behave exactly as they do on a camera.
#include <optrissdk.h> auto still = optris::sdk::StillSource::Open("/data/capture.png"); // What it was measured with, out of the file's own metadata. const auto radiation = still->GetRadiation(); // emissivity, transmissivity, ambient const auto& device = still->GetDeviceInfo(); // model, serial, revisions const uint64_t id = still->Regions().Add( optris::sdk::Region::Rect({0.5F, 0.375F}, {0.2F, 0.2F})); still->Refresh(); const auto area = still->Regions().Get(id); // area->stats.max_c is the hottest pixel inside that rectangle.
optris_sdk_imager *still = NULL; optris_sdk_radiation_config radiation; optris_sdk_vec2 centre = {0.5F, 0.375F}; optris_sdk_vec2 size = {0.2F, 0.2F}; optris_sdk_region *area = NULL; optris_sdk_region_stats stats; uint64_t id = 0; optris_sdk_still_open("/data/capture.png", &still); /* What it was measured with, out of the file's own metadata. */ optris_sdk_radiation_config_init(&radiation, sizeof(radiation)); optris_sdk_imager_get_radiation(still, &radiation); optris_sdk_region_create_rect(centre, size, 0.0F, &area); optris_sdk_imager_add_region(still, area, &id); optris_sdk_region_free(area); optris_sdk_still_refresh(still); optris_sdk_region_stats_init(&stats, sizeof(stats)); optris_sdk_imager_get_region_stats(still, id, &stats); /* stats.max_c is the hottest pixel inside that rectangle. */
using var still = ThermalCamera.OpenStill("/data/capture.tiff"); // What it was measured with, through the camera's own property. Console.WriteLine(still.Radiation.Emissivity); ulong id = still.AddRegion(Region.Rect(new(0.5f, 0.375f), new(0.2f, 0.2f))); still.Refresh(); Console.WriteLine(still.GetRegionStats(id).Maximum); // The global knob, and it is the camera's own line. still.Radiation = still.Radiation with { Emissivity = 0.80f };
still = optris_sdk.Camera.open_still('capture.png') # What it was measured with, through the camera's own property. print(still.emissivity) area = optris_sdk.Region.rect((0.5, 0.375), (0.2, 0.2)) area_id = still.regions.add(area) still.refresh() stats = still.regions.stats(area_id) # stats.max_c is the hottest pixel inside that rectangle.
let mut still = Camera::open_still("capture.png")?; // What it was measured with, through the camera's own getter. let radiation = still.radiation()?; println!("{}", radiation.emissivity); let area = Region::rect((0.5, 0.375), (0.2, 0.2), 0.0)?; let id = still.add_region(&area)?; still.refresh_still()?; let state = still.region(id)?; // its stats carry the hottest pixel inside that rectangle.
Refresh() measures and delivers the still once, on the calling thread. That is the call for a program that wants an answer rather than a stream: add or move a region, Refresh(), read the statistics.
A running still keeps delivering its one frame, as a camera pointed at an unchanging scene would, so code written against FrameSource needs no special case and a region moved while it runs is measured without anything being restarted. SetFrameRate() sets how often; the default is 10 Hz.
Region::Rect and its siblings take region-space coordinates, normalised on the frame's width in both axes. The centre of a 640×480 frame is therefore {0.5F, 0.375F}, not {0.5F, 0.5F}.
What a still refuses, and why
A raw-ADU or energy still does not open
It holds uncalibrated counts with no radiometric model beside them, so every temperature a source reported for it would be an invention. Open() throws FeatureNotSupportedException naming the encoding it found. Use rec::Snapshot::LoadRaw() for the counts themselves.
A CSV is not a still source
It carries no metadata document, so it cannot say what its numbers mean. Open() throws IoException, as it does for a file that carries no otc:meta at all.
The global emissivity can be changed
It is the same knob as on a camera. Set it through StillSource::ApplyConfig() or Player::ApplyConfig(); ask for the value the file was written at and the recorded pixels come back exactly.
A camera folds the global emissivity into its energy-to-temperature table, and this does the same: the table is rebuilt by the camera's own TempTable, from the calibration the file carries, and every pixel is re-derived through it. Verified against a real PI 640i: a table rebuilt from a file's own calibration is identical to the camera's entry for entry, all 12183 of them, at every emissivity from 1.00 to 0.30. A scene the camera reads as 50.00 °C at emissivity 0.95 reads 51.20 at 0.90, 54.30 at 0.80 and 70.00 at 0.50, on the camera, on a reopened still and on a replay alike, to the same three decimals.
The calibration this needs is a second attachment, radiometry.otc, 43,142 bytes on that camera: the camera's characteristic curve, 365,551 bytes of text, and its normalizing table, another 2,678, both carried as the measured pairs rather than as text. That is larger than the 665-byte curve, and the curve alone cannot do this. Both are carried rather than looked for on the playback machine, so the table a replay rebuilds is the camera's on any machine.
The global knob and a region's own emissivity are different arithmetic, and they can disagree. This is true of a camera and is reproduced here deliberately. A region's own value is applied algebraically at measure time; the global value goes through the table. From emissivity 0.95, the two agree only to within 3–10 % of the response: 0.40 K at 0.90, and 6.9 K at 0.50, the latter on a correction of +40.7 K. A display that offers both should not present them as interchangeable at low emissivity.
What the global knob refuses
Two things are refused rather than approximated. The global value is refused by name on a file with no radiometry.otc this reader understands: one written before 12.0, one from a camera with no characteristic curve, one whose bundle is an earlier version of the block than this build writes, or one whose bundle does not reproduce the curve the file also carries (that check runs at open, comparing two tables that both came out of the file). The version is checked for equality, and an older one is refused rather than read with the missing part left out: the bundle now carries the camera's normalizing table, and an absent one means "this camera had none", so reading an older file would assert the opposite of what the camera decided and rebuild a slightly different table in silence. The temperature range is refused always: a different range is a different calibration, with its own characteristic curve and its own table parameters, and the file holds only the one it was written in.
A re-derived pixel costs the stored tenth of a kelvin and nothing else. A temperature sits on a plateau of the curve (a mean of 7.16 energies per 0.1 K step on that camera) and which energy it came from is not in the file. Measured: 0.20 K at emissivity 0.90, 0.30 K at 0.50.
A region's own emissivity
It is applied when the file carries the camera's characteristic curve, and refused out loud when it does not. StillSource::HonoursRegionEmissivity() answers for the file that was opened.
Honouring Region::emissivity means undoing the radiometric correction the pipeline already made and redoing it at a different value, and both directions go through the camera's own characteristic curve. A still holds finished temperatures, so that curve is the one thing needed to invert them, and since 12.0 the SDK writes it into every still it saves from a camera that has one, as an attachment named characteristic-curve.otc. On a real PI 640i, 12183 table entries encode to 665 bytes, once per file.
With the curve, the still resolves the region through the same object a live camera resolves it with, over a table of the same kind: BackendEmissivityResolver, unchanged. So the number a region reports on a reopened still is the number the camera that took the picture would have reported. The picture itself is never corrected, so such a region reports RegionEmissivityState::kReadingOnly.
Without the curve (a still written before 12.0, or one saved from a source that has none) the region reads at the camera's emissivity, RegionEmissivityState::kCameras says so, and a warning names the first such region. The camera's emissivity (the one every pixel in the file was computed at) is recorded either way and is what GetRadiation() returns.
A still's recorded regions are not measuring areas
SnapshotInfo::rois travels with the file and is reachable through GetMetadata().rois, but nothing in the SDK builds one from a live Region and nothing maps one back, so a still carries only the regions a caller filled in by hand. Adding your own, as above, is how a still gets measured today.
From C, .NET, Python and Rust
A still is carried as the same handle or object a camera is, so the measuring areas, the alarm rules, the palette, the colour scaling, the frame delivery and the radiation parameters are the members you already use.
| open a still | measure it once | does a region's own emissivity reach the numbers | |
|---|---|---|---|
| C++ | StillSource::Open() |
Refresh() |
HonoursRegionEmissivity() |
| C | optris_sdk_still_open() |
optris_sdk_still_refresh() |
optris_sdk_still_honours_region_emissivity() |
| .NET | ThermalCamera.OpenStill() |
Refresh() |
HonoursRegionEmissivity |
| Python | Camera.open_still() |
refresh() |
honours_region_emissivity |
| Rust | Camera::open_still() |
refresh_still() |
honours_region_emissivity() |
The global emissivity is set through the radiation parameters, not through the configuration record. In C the call is optris_sdk_still_set_radiation(), which takes the same struct optris_sdk_imager_set_radiation() takes. optris_sdk_still_apply_config() exists and applies a whole record, but it cannot move the knob on its own: an optris_sdk_config is opaque and the ABI has no setters on one, so a record from optris_sdk_imager_copy_config() carries the values it was copied with. In .NET, Python and Rust the existing radiation setter routes to the still's entry point for you.
What a still refuses, it refuses by name in every language, as FeatureNotSupportedException / OPTRIS_SDK_ERROR_NOT_SUPPORTED / NotSupportedError / Status::NotSupported: the shutter, the focus motor, the network settings, the transport, and the colour windows, which need a pipeline a file does not have. Branch on is_still / IsStill / optris_sdk_imager_is_still() rather than calling and ignoring the result.
A still delivers only while it is running or once per Refresh(). Acquiring a frame from one that has been opened and neither started nor refreshed reports OPTRIS_SDK_ERROR_INVALID_STATE, exactly as it does on a camera that has not been started, and the message names Refresh() as the remedy.
Rotating and mirroring any source (a camera, a recording or a still) is reachable from the bindings by the same change: optris_sdk_imager_set_orientation(), ThermalCamera.SetOrientation(), Camera.set_orientation(), Camera::set_orientation(), with the detector's own size available as SensorWidth / sensor_width beside the delivered size. Quarter turns only, and they are an exact index remap, so a turned frame measures identically to an unturned one.
auto frame = player->AcquireFrame(); float hottest = frame.GetMaxTemperature(); if (const auto at = frame.MaxLocation()) { // the hot spot, row-major, in the same (X, Y) order every language // uses: at->x, at->y }
optris_sdk_frame *frame = NULL; optris_sdk_frame_info info; optris_sdk_imager_acquire_frame(playback, 2000, &frame); optris_sdk_frame_info_init(&info, sizeof(info)); optris_sdk_frame_get_info(frame, &info); /* the hot spot, row-major: x = max_index % width, y = max_index / width */ optris_sdk_frame_free(frame);
using ThermalFrame frame = await playback.AcquireFrameAsync(token); float hottest = frame.MaxTemperature; if (frame.MaxLocation is (int x, int y)) { // the hot spot, row-major, in the same (X, Y) order every language uses }
frame = playback.acquire(2000) hottest = frame.max_c location = frame.max_location if location is not None: x, y = location # the same (X, Y) order every language uses
let frame = playback.acquire_frame(2000)?.expect("a frame"); if let Some((x, y)) = frame.as_frame().max_location() { // the same (X, Y) order every language uses }
Imager or Player
Imager and Player are separate types that share FrameSource. Code that only starts, stops, receives frames and measures them can take a FrameSource&. Transport controls (seeking, speed, looping) exist only on Player, camera controls (shutter, focus, operation modes, recording) only on Imager, so which one you have is known at compile time rather than tested at run time:
void Consume(optris::sdk::FrameSource& source) { source.SetThermalCallback([](const optris::sdk::ThermalFrame& f) { // Same code for a live camera and a recording. }); source.Start(); }
The transport on a live camera
Every one of these throws FeatureNotSupportedException on a live camera: the setters, the seeks and the getters alike. A camera has no transport.
v11 accepted them and did nothing, and the getters answered with hardcoded defaults: the speed read 1.0 and the duration read zero. That let one piece of code drive both without branching, at the price of making a seek that was silently dropped look exactly like one that worked, and of answering "the speed is 1.0" for a camera that has no speed. v12 refuses instead. Ask whether the source is a playback, which both kinds answer, before showing a transport bar.
Playback with Seeking
#include <optrissdk.h> #include <chrono> #include <print> #include <thread> int main() { auto player = optris::sdk::Player::Open("/tmp/test_recording.mkv"); const auto& device = player->GetDeviceInfo(); std::println("Playing back: {} ({}x{} @ {} fps)", device.model, player->GetWidth(), player->GetHeight(), device.frame_rate); uint64_t frame_count = 0; player->SetThermalCallback( [&](const optris::sdk::ThermalFrame& f) { // A recording keeps the mark on the frames from before the camera's // startup calibration had finished. They are not measurements. if (!f.GetMetadata().thermal_data_reliable) return; std::println("Frame {}: min={:.1f} max={:.1f}", frame_count++, f.GetMinTemperature(), f.GetMaxTemperature()); }); player->SetLoop(true); player->SetSpeed(2.0f); player->Start(); // Let it play for a few seconds. std::this_thread::sleep_for(std::chrono::seconds(3)); // Seek back to the beginning. player->SeekToFrame(0); std::println("Seeked to frame 0."); // Play at half speed. player->SetSpeed(0.5f); std::this_thread::sleep_for(std::chrono::seconds(3)); player->Stop(); }
optris_sdk_imager *playback = NULL; optris_sdk_frame *frame = NULL; char model[64]; uint32_t w = 0; uint32_t h = 0; int i; optris_sdk_imager_create_from_file("/tmp/test_recording.mkv", &playback); optris_sdk_imager_get_model(playback, model, sizeof(model), NULL); optris_sdk_imager_get_width(playback, &w); optris_sdk_imager_get_height(playback, &h); printf("Playing back: %s (%ux%u)\n", model, w, h); optris_sdk_imager_set_loop(playback, 1); optris_sdk_imager_set_playback_speed(playback, 2.0F); optris_sdk_imager_start(playback); /* Let it play for a while, pulling frames as the clock. */ for (i = 0; i < 100; ++i) { optris_sdk_frame_info info; if (optris_sdk_imager_acquire_frame(playback, 2000, &frame) != OPTRIS_SDK_OK) { break; } optris_sdk_frame_info_init(&info, sizeof(info)); optris_sdk_frame_get_info(frame, &info); /* A recording keeps the mark on the frames from before the camera's * startup calibration had finished. They are not measurements. */ if (info.thermal_data_reliable) { printf("Frame %d: min=%.1f max=%.1f\n", i, (double)info.min_temp_c, (double)info.max_temp_c); } optris_sdk_frame_free(frame); frame = NULL; } /* Seek back to the beginning and play at half speed. */ optris_sdk_imager_seek_to_frame(playback, 0); optris_sdk_imager_set_playback_speed(playback, 0.5F); optris_sdk_imager_stop(playback); optris_sdk_imager_destroy(playback);
await using var playback = ThermalCamera.OpenRecording( "test_recording.mkv"); Console.WriteLine($"Playing back: {playback.Model} " + $"({playback.Width}x{playback.Height})"); playback.IsLooping = true; playback.PlaybackSpeed = 2.0f; playback.Start(); for (int i = 0; i < 100; i++) { using ThermalFrame frame = await playback.AcquireFrameAsync(TimeSpan.FromSeconds(2)); // A recording keeps the mark on the frames from before the camera's // startup calibration had finished. They are not measurements. if (frame.Metadata.IsThermalDataReliable) { Console.WriteLine($"Frame {i}: min={frame.MinTemperature:F1} " + $"max={frame.MaxTemperature:F1}"); } } // Seek back to the beginning and play at half speed. playback.SeekToFrame(0); playback.PlaybackSpeed = 0.5f; playback.Stop();
playback = optris_sdk.Camera.open_recording('test_recording.mkv') print(f"Playing back: {playback.model} " f"({playback.width}x{playback.height})") playback.is_looping = True playback.playback_speed = 2.0 playback.start() for i, frame in enumerate(playback.frames(100)): # A recording keeps the mark on the frames from before the camera's # startup calibration had finished. They are not measurements. if frame.thermal_data_reliable: print(f"Frame {i}: min={frame.min_c:.1f} max={frame.max_c:.1f}") # Seek back to the beginning and play at half speed. playback.seek_to_frame(0) playback.playback_speed = 0.5 playback.stop() playback.close()
let mut playback = Camera::from_file("test_recording.mkv")?; println!("Playing back: {} ({}x{})", playback.model()?, playback.width()?, playback.height()?); playback.set_loop(true)?; playback.set_playback_speed(2.0)?; playback.start()?; for i in 0..100 { if let Some(frame) = playback.acquire_frame(2000)? { let info = frame.info()?; // A recording keeps the mark on the frames from before the // camera's startup calibration had finished. They are not // measurements. if info.thermal_data_reliable { println!("Frame {i}: min={:.1} max={:.1}", info.min_temp_c, info.max_temp_c); } } } // Seek back to the beginning and play at half speed. playback.seek_to_frame(0)?; playback.set_playback_speed(0.5)?; playback.stop()?;
Regions in a recording
A recording carries the measuring areas it was made with, and what they read over time.
- The static definition (geometry, styling, apertures and rules) is written once into the recording's
config.jsonattachment. - A per-frame record carries each region's readings and alarm state, and the leaf matrices of any region that moved since the previous frame. A static region therefore costs a couple of dozen bytes a frame rather than a re-dump of the whole model.
- The first record of every file states every region in full: its definition and its matrices as well as its readings. That includes the first frame of a take, the first frame a pre-roll hands over, and the first frame of every part of a segmented recording, so each file can be replayed on its own.
Opening the file with Player::Open() restores both, keeping the recorded ids:
auto player = optris::sdk::Player::Open("/tmp/alarm_event.mkv"); player->SetThermalCallback([&](const optris::sdk::ThermalFrame &) { for (const auto &state : player->Regions().States()) { // Where the region was, and what it read, at this point in the // recording -- including whether it was alarming. } }); player->Start();
optris_sdk_imager *playback = NULL; optris_sdk_frame *frame = NULL; optris_sdk_region_state states[16]; size_t written = 0; size_t i; optris_sdk_imager_create_from_file("/tmp/alarm_event.mkv", &playback); optris_sdk_imager_start(playback); while (optris_sdk_imager_acquire_frame(playback, 2000, &frame) == OPTRIS_SDK_OK) { optris_sdk_imager_read_region_states(playback, states, 16, &written); for (i = 0; i < written; ++i) { /* Where the region was, and what it read, at this point in the * recording -- including whether it was alarming. */ } optris_sdk_frame_free(frame); frame = NULL; }
await using var playback = ThermalCamera.OpenRecording("alarm_event.mkv"); playback.Start(); var states = new RegionState[16]; await foreach (ThermalFrame frame in playback.FramesAsync(token)) { using (frame) { int written = playback.ReadRegionStates(states); for (int i = 0; i < written; i++) { // Where the region was, and what it read, at this point // in the recording -- including whether it was alarming. } } }
playback = optris_sdk.Camera.open_recording('alarm_event.mkv') playback.start() for frame in playback.frames(): for state in playback.regions.states(): # Where the region was, and what it read, at this point in # the recording -- including whether it was alarming. pass
let mut playback = Camera::from_file("alarm_event.mkv")?; playback.start()?; while let Some(_frame) = playback.acquire_frame(2000)? { for state in playback.read_region_states()? { // Where the region was, and what it read, at this point in // the recording -- including whether it was alarming. } }
Replayed frames are measured exactly as live ones, then the recorded record is applied over the top. So a recording made without regions still plays back, regions you add at playback time are measured against the replayed frames, and a recorded region reports every statistic it asks for: what the file recorded as recorded, and the rest computed from the replayed temperatures (see Which statistics a recorded region reports).
The record governs the recording's own regions and only those. One the file carried, or one drawn while the take was running, is moved, restyled and removed by the record exactly as it was on the camera, so an area deleted mid-take disappears on the replay at the frame it was deleted on. A region you add on the playback handle is yours: it is absent from every record, and it stays for as long as you keep it.
Who owns a region on a replay
A region you add on a replay is numbered from kReplayRegionIdBase, which is 2³². Every id a recording can name comes from a recorder's own counter, which starts at 1 and steps once per region created, so nothing above that floor can be named by any file, and a record is in any case applied only to ids the recording owns.
Do not use that floor to decide who owns a region. Ask. Regions().IsFromRecording(id) (optris_sdk_imager_is_region_from_recording() in C, IsRegionFromRecording in .NET, regions.is_from_recording() in Python, region_is_from_recording() in Rust) answers from the ownership the per-frame records are pruned by, so the answer and the pruning decision cannot disagree. The floor is a numbering convention and nothing here promises to keep it. It is also already not the whole answer, in three ways:
- a region the take drew part way through is the recording's, carries a recorded id, and did not exist when the file opened: it joins the owned set on the frame its definition arrives on;
- a region the take deleted stops being the recording's on the frame it goes, while its id stays below the floor;
- on a live camera and on a still, ids start at 1, so a comparison against the floor reports every region on every camera as belonging to a recording. The query answers false there, because nothing on either is a recording's.
It says nothing about whether a region can be edited: a replay accepts an edit to a recorded region. The next record naming it sets again what the recording states (where it is, its shape, name, style and emissivity, and its readings and alarm state), so an edit to any of those lasts one frame. Which optional statistics it computes is yours once you change it; the next section says exactly what that covers.
Both are needed, because the ids a file uses are not all visible when it opens. A take that drew its fourth region part way through names id 4 only in its per-frame records, and reading the whole record track at open is a read of the entire file before the first frame decodes. Before the floor existed, an application's first region on such a replay was handed id 4 and, on the frame that region appeared, was renamed, moved and given the recorded readings.
Which statistics a recorded region reports
A recording carries, for each region and each frame, its minimum, maximum and mean, its coverage, whether it was measured, and its alarm state. Nothing else. Everything else a recorded region reports on a replay is the replay's own measurement of the recorded temperatures, computed for the statistics the region asks for, exactly as a live region computes them:
| statistic | on a replay |
|---|---|
| minimum, maximum, mean, coverage, measured or not, alarm state | as recorded, every frame |
| standard deviation | computed from the replayed temperatures |
| median and percentiles | computed when the region asks for percentiles |
| threshold share | computed when the region has a threshold |
| samples (a line's profile) | kept when the region asks for samples |
Where the file has a value, the file's value is shown, even where the replay would compute something slightly different from the same pixels. One exception: a file written before 12.0.11 carries with each frame the readings of the frame before it, so its first frame says "not measured" about pixels that were measured; there the replay's own reading of that frame is shown. A statistic the file does not have is computed, never left at zero and never guessed.
Which optional statistics a recorded region computes is yours to choose. It starts as the recording's choice, and follows a change the take made part way through: a take that switched the median on at some frame computes it from that frame. Once you change the choice on the playback handle (Regions().Edit(), optris_sdk_imager_update_region(), UpdateRegion, regions.update(), update_region()), no record changes it again, including when a seek removes the region and a later record brings it back under the same id. Removing the region yourself forgets the choice.
To ask a region that came with the file for its median:
player->Regions().Edit(id, [](optris::sdk::Region ®ion) { region.want_percentiles = true; // the median and the percentiles }); // From the next frame on: // player->Regions().Get(id)->stats.median_c
optris_sdk_region *region = NULL; optris_sdk_imager_copy_region(playback, id, ®ion); optris_sdk_region_set_want_percentiles(region, 1); optris_sdk_imager_update_region(playback, id, region); optris_sdk_region_free(region); /* From the next frame on, optris_sdk_imager_get_region_stats() reports * the median in median_c. */
using (Region region = playback.GetRegion(id)!) { region.ComputePercentiles = true; // the median and the percentiles playback.UpdateRegion(id, region); } // From the next frame on: playback.GetRegionStats(id).Median
region = playback.regions.copy(id) region.want_percentiles = True # the median and the percentiles playback.regions.update(id, region) # From the next frame on: playback.regions.stats(id).median_c
let mut region = playback.region(id)?; region.want_percentiles(true)?; // the median and the percentiles playback.update_region(id, ®ion)?; // From the next frame on: playback.region_stats(id)?.median_c
What is withheld rather than computed. A computed statistic reads as not computed (NaN, and valid false on the percentiles and the threshold share) in two cases, because a number there would not be of the same thing as the readings beside it:
- on a frame where the record says the region was not measured;
- for a region with an emissivity of its own whose recorded pixels do not carry it. A camera on the CPU pipeline applies a region's own emissivity to its readings and not to the picture, so the recorded minimum, maximum and mean are at the region's emissivity while the pixels are at the camera's. The file does not say which kind of camera wrote it, so the replay asks the pixels: where its own minimum, maximum and mean over them match the recorded ones to 0.1 °C, the pixels carry what the camera measured and the computed statistics are shown; where they do not, they are withheld. A camera that colours through a per-region emissivity map on the GPU records pixels that do carry it.
A recording with no temperatures computes nothing. A picture recording (colorized video, Player::IsPicture()) has no temperatures to compute from, and a region on it reports nothing at all. A recording written before 12.0 shows none of its own regions (see A recording written before 12.0 cannot show its regions), so there is nothing recorded to compute for; regions you add to it are measured from its temperatures as on any replay.
A seek and a loop rebuild the measuring areas
The record is a delta in its definitions and its matrices (a region's full definition is written on the frame it first appeared on and on any frame it changed), so arriving at a frame by seeking has to account for records the replay never passed. A seek forward replays only the records between where it was and where it is going; a seek backward, or a seek on a replay that has played nothing, replays them from the start of the file. Nothing is decoded: the records are a text track, and the video is handed to the demuxer to skip. GetLastSeekReplayedRecords() says what the last seek paid.
That includes arriving at a stretch the take had no regions on. A frame the camera had no regions on carries no region record at all, and three things look identical from downstream: a frame with no regions, a file written before the region track existed, and a metadata packet that did not arrive. The player tells them apart, so a seek back into an empty stretch, and a loop wrap onto a take whose first frame had no regions, now remove the regions rather than leaving them on screen with their last readings.
One stretch is read differently: the frames before a file's first region record, in a file whose config.json says the take started with regions. Recordings made with an SDK before 12.0.9 often left the first frame of a take without its record, although the camera had regions on it. Such a frame is not read as "no regions"; it carries the first record in the file, so a seek to the start or a loop wrap shows the regions the take started with instead of removing them for a frame. A take that started with no regions keeps the rule above.
A region the replay removes this way and later brings back, under the same id, is the same region: the rules attached to it follow it. While it is absent they read kOrphaned, and from the frame after it returns they read it again, with nothing for the application to do. Its signal slot changes, as it does whenever a region is created, so ask SignalSlot() again rather than keeping the old one. A region you remove with Regions().Remove() takes its rules with it, on a replay as on a camera.
A recording written before 12.0 cannot show its regions
Those files define no region in config.json and their records name ids whose definitions are nowhere in the file, and there is nothing to repair in a file already written. A replay of one of those files shows the regions you added and none of the recording's.