A Running Recording
What a running recording tells you, what it needs from the disk under it, and the one setting that changes the frames going into it. Starting and stopping are Recording; the file itself is Recording File Format.
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? |
Being told what a recording is doing
IsRecording() cannot say that a timed recording reached its end rather than being stopped by somebody, that an alarm rule started one you never asked for, or that a recording died on a full disk: a recording that died and one that finished look identical from outside.
OnRecording() reports all of it. Register it before starting a recording.
#include <optrissdk.h> #include <print> auto imager = optris::sdk::Imager::Create(); imager->Recorder().OnRecording( [](const optris::sdk::rec::RecordingEvent &event) { switch (event.phase) { case optris::sdk::rec::RecordingPhase::kStarted: std::println("recording to {}", event.path); break; case optris::sdk::rec::RecordingPhase::kStopped: std::println("finished {}", event.path); break; case optris::sdk::rec::RecordingPhase::kFailed: std::println("recording failed: {}", event.message); break; case optris::sdk::rec::RecordingPhase::kSegmentCompleted: std::println("segment finished: {}", event.path); break; } });
static void OTC_SDK_C_CALL OnRecordingEvent( optris_sdk_recording_phase phase, const char *path, const char *message, optris_sdk_recording_stop_reason stop_reason, void *user_data) { (void)stop_reason; (void)user_data; switch (phase) { case OPTRIS_SDK_RECORDING_STARTED: printf("recording to %s\n", path); break; case OPTRIS_SDK_RECORDING_STOPPED: printf("finished %s\n", path); break; case OPTRIS_SDK_RECORDING_FAILED: printf("recording failed: %s\n", message); break; case OPTRIS_SDK_RECORDING_SEGMENT_COMPLETED: printf("segment finished: %s\n", path); break; default: break; } } optris_sdk_imager_set_recording_callback(imager, OnRecordingEvent, NULL);
def on_recording(event): if event.phase == optris_sdk.RECORDING_STARTED: print(f"recording to {event.path}") elif event.phase == optris_sdk.RECORDING_STOPPED: print(f"finished {event.path}") elif event.phase == optris_sdk.RECORDING_FAILED: print(f"recording failed: {event.message}") elif event.phase == optris_sdk.RECORDING_SEGMENT_COMPLETED: print(f"segment finished: {event.path}") camera.on_recording(on_recording)
camera.on_recording_event(|event| match event.phase { RecordingPhase::Started => println!("recording to {}", event.path), RecordingPhase::Stopped => println!("finished {}", event.path), RecordingPhase::Failed => { println!("recording failed: {}", event.message); } RecordingPhase::SegmentCompleted => { println!("segment finished: {}", event.path); } _ => {} })?;
kFailed is reported once per recording, not once per lost frame: a full disk fails every frame, and one notification per frame at 32 Hz is a flood. The running totals are in the statistics below.
The handler runs on an SDK thread, never the camera's frame thread:
| Event | Thread |
|---|---|
| A start you asked for | the calling thread |
| A recording that reached its duration | the SDK's own timer thread |
kFailed, kSegmentCompleted |
the thread that writes the recording |
Do not destroy the camera from the handler: the thread that would have to be shut down is the one you are on. Calling back in is allowed, Stop() included, but a handler that blocks blocks the recording, so set a flag and act on your own thread.
Stop() waits for a kSegmentCompleted handler that is still running. When Stop() returns and kStopped arrives, every part the recording finished has been reported and its handler has returned, so the parts you were told of and the one kStopped ends are all the files there are. A handler that is still busy with a part holds Stop() up until it returns, for at most 5 seconds, after which the stop goes on and says so in the log. So never let that handler wait for the thread that calls Stop(): in a user interface, hand the event over with BeginInvoke or InvokeAsync, not with Invoke.
camera.OnRecording(e => { switch (e.Phase) { case RecordingPhase.Started: ui.ShowRecordingChip(e.Path); break; case RecordingPhase.Stopped: ui.Toast($"Saved {e.Path}"); break; case RecordingPhase.Failed: ui.Error($"Recording failed: {e.Message}"); break; case RecordingPhase.SegmentCompleted: ui.AddToFileSet(e.Path); break; case RecordingPhase.Discarded: // The recording captured nothing, so its file has been // deleted; e.Path is the file that is gone. This always // arrives before Stopped, which is what lets you drop the // take here rather than save it above and remove it after. ui.Toast("Nothing was recorded"); ui.ForgetTake(e.Path); break; } });
What a recording did with its frames
IsRecording() stays true while every frame is refused, so a recording that has stopped growing looks healthy. Switch the camera's operating mode while recording and every frame after the switch is the wrong size for the open file.
#include <optrissdk.h> #include <print> auto imager = optris::sdk::Imager::Create(); imager->Start(); imager->Recorder().Start("/data/run.mkv"); // ... later ... imager->Recorder().Stop(); const auto stats = imager->Recorder().GetStatistics(); std::println("{} frames written, {} lost, {} bytes", stats.frames_written, stats.frames_dimension_mismatch + stats.frames_write_error + stats.frames_dropped_backlog, stats.bytes_written); if (!stats.last_error.empty()) { std::println("last failure: {}", stats.last_error); }
optris_sdk_recording_stats stats; optris_sdk_imager_start_recording(imager, "/data/run.mkv"); /* ... later ... */ optris_sdk_imager_stop_recording(imager); optris_sdk_recording_stats_init(&stats, sizeof(stats)); optris_sdk_imager_get_recording_stats(imager, &stats); printf("%llu frames written, %llu lost, %llu bytes\n", (unsigned long long)stats.frames_written, (unsigned long long)(stats.frames_dimension_mismatch + stats.frames_write_error + stats.frames_dropped_backlog), (unsigned long long)stats.bytes_written); if (stats.last_error[0] != '\0') { printf("last failure: %s\n", stats.last_error); }
camera.StartRecording("run.mkv"); // ... later ... camera.StopRecording(); RecordingStatistics stats = camera.RecordingStatistics; Console.WriteLine( $"{stats.FramesWritten} frames written, {stats.FramesLost} lost, " + $"{stats.BytesWritten} bytes");
camera.start_recording('run.mkv') # ... later ... camera.stop_recording() stats = camera.recording_stats print(f"{stats.frames_written} frames written, " f"{stats.frames_lost} lost, {stats.bytes_written} bytes") if stats.last_error: print(f"last failure: {stats.last_error}")
camera.start_recording("run.mkv")?; // ... later ... camera.stop_recording()?; let stats = camera.recording_stats()?; println!("{} frames written, {} lost, {} bytes", stats.frames_written, stats.frames_lost(), stats.bytes_written); if !stats.last_error.is_empty() { println!("last failure: {}", stats.last_error); }
The counters are reset when a recording starts and kept after it stops, so the totals are readable once the file is closed.
Add all three loss counters, not two. frames_dropped_backlog is the one a target too slow for the stream shows up in, so a sum that leaves it out prints "0 lost" for exactly the case that loses the most frames. .NET's RecordingStatistics.FramesLost and Python's RecordingStats.frames_lost add all three for you; in C++ and C, add all three yourself.
The accounting rule. Every frame the recording was offered is in exactly one of the four counters, or still waiting to be written:
offered == frames_written + frames_dimension_mismatch + frames_write_error + frames_dropped_backlog + queue_depth
The last term is what makes it an identity rather than an approximation while a recording runs: a frame is accepted on the camera's thread and accounted for by the thread that writes it. After a stop the queue is empty and the counters account for everything.
frames_written is not "on the disk". It counts a frame once the container has accepted it, which is a moment earlier than the frame's bytes reaching the file: the container holds packets back so that it can interleave the file's streams, and releases them as it goes and finally when the recording is stopped. So the counter answers "did the recording get my frame", which is what it is for, and a program that polls it and then opens the file while the recording is still running can read back fewer frames than the counter says, without anything having gone wrong.
Stopping is the barrier. StopRecording() drains the write queue, finishes the container and closes the file before it returns, so a file opened after that call holds every frame the counter has counted. That is the point at which to read the file, and it is why the counters are documented as exact after a stop.
camera.StopRecording(); RecordingStatistics stats = camera.RecordingStatistics; Console.WriteLine( $"{stats.FramesWritten} frames written, {stats.FramesLost} lost, " + $"{stats.BytesWritten} bytes");
And the barrier makes a plain existence check meaningful:
camera.StopRecording(); var file = new FileInfo("run.mkv"); if (!file.Exists || file.Length == 0) { // The recording did not happen. }
Reading a recording's figures after the next one has started
The statistics above describe the recording that is current when you read them. A start resets them. So a program that hands each recording event to a thread of its own, as the handler's rules ask, and reads the statistics there when it gets to a Stopped, can read the next recording's figures: an alarm rule's recording action that activates again right after its recording ended, or your own code starting the next file at once, makes a complete file read as 0 frames written.
The Stopped event carries the figures of the recording it ends, taken when it ended, and a number that ties it to its Started. Read those instead. In C# and Python they are on the event OnRecording() already delivers (Statistics and RecordingId, statistics and recording_id). In C++, C and Rust they come with a second handler, which you register beside the first or instead of it: OnRecordingDetail(), optris_sdk_imager_set_recording_event_callback() and on_recording_event_detail(). Added in 12.0.15.
#include <optrissdk.h> #include <chrono> #include <mutex> #include <print> #include <thread> #include <vector> // Before the camera, so they outlive the last event it delivers. std::mutex mutex; std::vector<optris::sdk::rec::RecordingEventDetail> held; auto imager = optris::sdk::Imager::Create(); imager->Start(); imager->Recorder().OnRecordingDetail( [&](const optris::sdk::rec::RecordingEventDetail &detail) { std::lock_guard lock(mutex); held.push_back(detail); // Acted on later, on your own thread. }); imager->Recorder().Start("held_first.mkv"); std::this_thread::sleep_for(std::chrono::seconds(1)); imager->Recorder().Stop(); imager->Recorder().Start("held_second.mkv"); // The next one, at once. std::lock_guard lock(mutex); for (const auto &detail : held) { if (detail.event.phase == optris::sdk::rec::RecordingPhase::kStopped && detail.statistics) { // GetStatistics() is the second recording's by now; this is not. std::println("recording {} kept {} frames in {}", detail.recording_id, detail.statistics->frames_written, detail.event.path); } }
static void OTC_SDK_C_CALL OnHeldEvent(const optris_sdk_recording_event *event, void *user_data) { (void)user_data; /* Everything the event points to is borrowed: copy what you keep. */ if (event->phase == OPTRIS_SDK_RECORDING_STOPPED && event->statistics != NULL) { printf("recording %llu kept %llu frames in %s\n", (unsigned long long)event->recording_id, (unsigned long long)event->statistics->frames_written, event->path); } } optris_sdk_imager_set_recording_event_callback(imager, OnHeldEvent, NULL);
var held = new System.Collections.Concurrent.ConcurrentQueue<RecordingEvent>(); camera.OnRecording(held.Enqueue); // Acted on later, on your own thread. camera.StartRecording("held_first.mkv"); Thread.Sleep(TimeSpan.FromSeconds(1)); camera.StopRecording(); camera.StartRecording("held_second.mkv"); // The next one, at once. while (held.TryDequeue(out RecordingEvent? e)) { // RecordingStatistics is the second recording's by now; this is not. if (e.Phase == RecordingPhase.Stopped && e.Statistics is { } stats) { Console.WriteLine( $"recording {e.RecordingId} kept {stats.FramesWritten} frames " + $"in {e.Path}"); } }
import queue held = queue.Queue() camera.on_recording(held.put) # Acted on later, on your own thread. camera.start_recording('held_first.mkv') time.sleep(1.0) camera.stop_recording() camera.start_recording('held_second.mkv') # The next one, at once. while not held.empty(): event = held.get() # recording_stats is the second recording's by now; this is not. if (event.phase == optris_sdk.RECORDING_STOPPED and event.statistics is not None): print(f"recording {event.recording_id} kept " f"{event.statistics.frames_written} frames in {event.path}") camera.stop_recording()
let (sender, receiver) = std::sync::mpsc::channel(); camera.on_recording_event_detail(move |detail| { let _ = sender.send(detail); // Acted on later, on your own thread. })?; camera.start_recording("held_first.mkv")?; std::thread::sleep(Duration::from_secs(1)); camera.stop_recording()?; camera.start_recording("held_second.mkv")?; // The next one, at once. for detail in receiver.try_iter() { // recording_stats() is the second recording's by now; this is not. if let Some(stats) = &detail.statistics { if detail.event.phase == RecordingPhase::Stopped { println!("recording {} kept {} frames in {}", detail.recording_id, stats.frames_written, detail.event.path); } } }
The figures are on Stopped and on Discarded, the two events that end a recording, and absent on every other phase. They are the ones the statistics read gives at the moment of the stop, with one difference: a recording that ended at its segment limit and started the next one (see What happens at the limit) gets the frame and byte counters of its own file, where the statistics read counts on across the files. The number is the same on a recording's Started and its Stopped, different for every other recording of the same camera, and never 0 for a recording's own events.
What a recording needs from its target
A recording is lossless, so what it needs from a disk is the size of a compressed frame times the frame rate, and nothing in the SDK can reduce it. Measure the frame size on the recording itself (bytes_written / frames_written); it depends on the scene as much as on the sensor. A 640x480 frame of a real scene compresses to about 78 KB, which at 32 Hz is 2.5 MB/s for one camera. Three cameras on one stick needed about 2.2 MB/s together, and the stick sustained 1.33.
A USB stick is a reasonable target for a single camera and a poor one for several. The bursts bite before the sustained rate: the Matroska muxer hands a whole Cluster to the operating system at once, 0.77 MB every twelve frames for that camera, and a cheap stick can take a second over one.
When the target is slower, the file gives way, not the camera. Frames are encoded and written on a thread of the SDK's own, so the camera keeps its rate whatever the disk does, and the live picture, the region statistics, the alarms and the PIF fail-safe heartbeat are not behind the drive.
| statistic | what it says |
|---|---|
queue_depth |
How many frames are waiting to be written now. Near zero is a target with room to spare. |
queue_capacity |
How deep the queue may get: about two seconds of frames, sized from the sensor and the rate, plus whatever the pre-roll handed over at the start. |
queue_preroll |
How many of the waiting frames are that handover. Zero without a pre-roll, and falls to zero as it is written out, so queue_depth - queue_preroll is the live depth. |
queue_live_capacity |
The room for live frames: queue_capacity less the handover. The same two seconds whatever the pre-roll was, and equal to queue_capacity when there was none. |
queue_peak |
The deepest it has been. A stall of a second at 32 Hz fills and empties the queue between two polls a second apart, and this is the only trace it leaves. |
queue_preroll_peak |
The largest the handover ever was, which is its size at the instant it was made. A queue_peak equal to this is fully accounted for by the handover; one well above it had live frames piling up behind one. |
frames_dropped_backlog |
Frames the recording was offered and did not store, because the queue was full. Non-zero means the target cannot sustain this camera. |
longest_write_ms |
The longest a single frame took to encode and put on disk. On a healthy disk this is the encode (about 5 ms for 640x480) and a figure in the hundreds of milliseconds is the drive. |
A full queue drops the newest frame, not the oldest, so a gap in the file is always a gap in time and never a re-ordering. Watch the queue fill to warn a user before a frame is lost; read frames_dropped_backlog to report the ones that were.
With a pre-roll, watch the live figures, not queue_depth against queue_capacity
A recording takes the whole pre-roll ring at once, and the capacity holds that handover plus the live queue, so 30 s of pre-roll on a 640x480 camera at 32 Hz opens at 960 of 1024, 94 % full, on a healthy drive: 960 encodes, which takes seconds on a large sensor. Compare queue_depth - queue_preroll against queue_live_capacity instead; those two mean the same thing for every pre-roll length, including none. queue_peak near the capacity is that same handover on a pre-rolled recording and a drive falling behind on any other, so read it with queue_preroll_peak beside it.
The queue is bounded on purpose: one that absorbed a slow disk indefinitely would convert the data loss into an out-of-memory. It is about two seconds of frames, capped by bytes so a large sensor cannot blow the budget, and what will not fit is counted.
What a stop costs
Stop() writes out what is queued before it finishes the file, so the file holds every frame the recording accepted. On a slow target that costs the queue's depth times what one frame costs the drive, on top of the trailer and the index.
RecordingStatistics queue = camera.RecordingStatistics; uint live = queue.QueueDepth - queue.QueuePreRoll; if (queue.QueueLiveCapacity > 0 && live * 2 > queue.QueueLiveCapacity) { Console.WriteLine($"the drive is falling behind: {live} frames " + $"of {queue.QueueLiveCapacity} waiting"); }
And after a stop, the peak pair says whether the handover or the drive was behind it:
RecordingStatistics done = camera.RecordingStatistics; if (done.QueuePeak > done.QueuePreRollPeak) { Console.WriteLine($"the queue reached {done.QueuePeak} frames, " + $"{done.QueuePreRollPeak} of them pre-roll"); }
Splitting a long recording
FAT32 refuses any file above 4 GiB, and a lossless recording of a 640x480 sensor reaches that in well under an hour. Splitting it is what makes a long recording to a USB stick survivable as a file. Whether the stick is fast enough to hold the stream is answered in What a recording needs from its target.
You do not have to ask for the FAT32 case, and you cannot switch it off
The recorder asks the destination for its own per-file maximum at the first open and adopts it when you passed no limit; without that, a FAT volume would refuse a write at its ceiling mid-recording and leave the file without its trailer. That number is 4,294,967,295 for any FAT and no limit for ext4, NTFS, exFAT and network mounts, which are byte for byte unaffected. A limit you did set that the volume cannot honour is reduced to the volume's, with a warning.
rec::RecordingOptions carries the duration and both segment limits. Pass either limit, or both; whichever comes first rolls the file over. What you get on disk, for Start("run.mkv"):
| You asked for | Files written | series block in otc-meta.json |
|---|---|---|
| A segment limit | run_part000.mkv, run_part001.mkv, run_part002.mkv, and so on. Nothing is written at run.mkv itself. |
yes; series.part is the suffix number |
| No limit, on ext4, NTFS, exFAT or a network mount | run.mkv, one file, your path exactly |
(none) |
| No limit, on FAT | run.mkv, then run_part001.mkv, run_part002.mkv: the SDK adopts the volume's per-file maximum (see above) and rolls over anyway. The listing is ragged, part 0 keeping your path while the rest are suffixed |
none, on any part, so rec::OpenSeries() has only the file names and a reader handed run_part002.mkv cannot learn from the document that it belongs to anything |
kSegmentCompleted names every finished part, which is why it is the one way to learn the file set that is right whatever you asked for. The last part is not named by one: it is the part after the last kSegmentCompleted, the one kStopped ends, and kStopped itself carries the path you started with.
With a segment limit, the first file is run_part000.mkv, not the path you passed. An application that hands over run.mkv and later opens run.mkv finds nothing there. Do one of three things instead: take the name out of the kSegmentCompleted notification, which reports every finished file including the first; ask rec::OpenSeries() for the whole set; or open run_part000.mkv yourself. Ask for no segment limit and the file keeps your name exactly.
#include <optrissdk.h> #include <chrono> auto imager = optris::sdk::Imager::Create(); imager->Start(); optris::sdk::rec::RecordingOptions options; options.duration = std::chrono::hours(1); // The ready-made value for a FAT32 stick: 4 GiB less 4 MiB. options.max_segment_bytes = 4290772992; // whatever your destination holds // And a new file every ten minutes as well, whichever comes first. options.max_segment_duration = std::chrono::minutes(10); imager->Recorder().Start("/media/usb/run.mkv", options);
optris_sdk_recording_options options; optris_sdk_recording_options_init(&options, sizeof(options)); options.duration_ms = 3600000; /* The ready-made value for a FAT32 stick: 4 GiB less 4 MiB. */ options.max_segment_bytes = 4290772992ULL; /* And a new file every ten minutes as well, whichever comes first. */ options.max_segment_duration_ms = 600000; optris_sdk_imager_start_recording_ex(imager, "/media/usb/run.mkv", &options);
camera.StartRecording("/media/usb/run.mkv", new RecordingOptions { Duration = TimeSpan.FromHours(1), MaxSegmentBytes = 4290772992, MaxSegmentDuration = TimeSpan.FromMinutes(10), });
options = optris_sdk.RecordingOptions( duration_s=3600, # The ready-made value for a FAT32 stick: 4 GiB less 4 MiB. max_segment_bytes=4290772992, # And a new file every ten minutes, whichever comes first. max_segment_duration_s=600) camera.start_recording('/media/usb/run.mkv', options=options)
let mut options = RecordingOptions::default(); options.duration = Duration::from_secs(3600); // The ready-made value for a FAT32 stick: 4 GiB less 4 MiB. options.max_segment_bytes = 4_290_772_992; // And a new file every ten minutes as well, whichever comes first. options.max_segment_duration = Duration::from_secs(600); camera.start_recording_with("/media/usb/run.mkv", &options)?;
Every segment carries the full metadata and every attachment, so each file stands on its own.
What happens at the limit
By default a recording that reaches its limit carries on in the next file as the next part of the same recording, and Player::OpenSeries() plays all the parts back as one recording (see A recording in several files, played as one). That is one of three choices, set on the camera before the recording starts with Recorder().SetSegmentLimitAction():
| Choice | Files written for Start("run.mkv") |
What the recording reports |
|---|---|---|
kContinueSeries, the default |
run_part000.mkv, run_part001.mkv, ..., the parts of one recording, each carrying the same recording id |
kSegmentCompleted for each finished part |
kStartNewRecording |
run.mkv, then run_20261116_142233.mkv and so on: each a whole recording of its own, named with the local time it started, with -1, -2 added if two start in the same second |
kStopped with kSegmentLimit for each finished file, then at once kStarted with the next file's name |
kStopRecording (since 12.0.28) |
run.mkv only |
kStopped with kSegmentLimit, and nothing after it |
With kStartNewRecording the camera never stops recording: IsRecording() stays true and no frame is lost between one file and the next. Each file starts at its own zero and carries no part number, so each one opens and plays as the whole recording it is.
The choice applies to every recording the camera starts afterwards, whether your application starts it or an alarm rule does, and makes no difference to a recording with no limit. No choice depends on where the file is written: a limit is the number you picked.
Ending the recording at the limit
With kStopRecording (since 12.0.28) the limit ends the recording: a recording that must not pass a size or run past a time stops there by itself, without your application watching the bytes or the clock. The file is the path you passed and the only one, with no part number in its name. The last frame in it is the last one that fitted: the frame that reached the limit, and every frame after it, is not recorded. The file is finished exactly as Recorder().Stop() finishes one, so it opens and plays from its first frame to its last like any other recording.
The recording reports kStopped with kSegmentLimit (RecordingStopReason.SegmentLimit in C#, RECORDING_STOP_SEGMENT_LIMIT in Python, OPTRIS_SDK_RECORDING_STOP_SEGMENT_LIMIT in C), so your application can tell it from a stop it asked for. IsRecording() is false from then on, nothing else starts, and the next Start() records as usual. A size limit stops the recording before the file passes max_segment_bytes; a time limit stops it once the next frame would be max_segment_duration past the first.
#include <optrissdk.h> #include <chrono> auto imager = optris::sdk::Imager::Create(); imager->Recorder().OnRecording([](const optris::sdk::rec::RecordingEvent &e) { if (e.phase == optris::sdk::rec::RecordingPhase::kStopped && e.stop_reason == optris::sdk::rec::RecordingStopReason::kSegmentLimit) { std::println("{} reached its limit and is finished", e.path); } }); imager->Start(); // One recording of at most ten minutes, ended by the SDK. imager->Recorder().SetSegmentLimitAction( optris::sdk::rec::SegmentLimitAction::kStopRecording); optris::sdk::rec::RecordingOptions options; options.max_segment_duration = std::chrono::minutes(10); imager->Recorder().Start("/data/run.mkv", options);
optris_sdk_recording_options options; /* One recording of at most 2 GB, ended by the SDK. */ optris_sdk_imager_set_segment_limit_action( imager, OPTRIS_SDK_SEGMENT_LIMIT_STOP_RECORDING); optris_sdk_recording_options_init(&options, sizeof(options)); options.max_segment_bytes = 2000000000ULL; optris_sdk_imager_start_recording_ex(imager, "/data/run.mkv", &options);
using var camera = ThermalCamera.OpenSimulated(); camera.OnRecording(e => { if (e.Phase == RecordingPhase.Stopped && e.StopReason == RecordingStopReason.SegmentLimit) { Console.WriteLine($"{e.Path} reached its limit and is finished"); } }); camera.Start(); // One recording of at most ten minutes, ended by the SDK. camera.SegmentLimitAction = SegmentLimitAction.StopRecording; camera.StartRecording("run.mkv", new RecordingOptions { MaxSegmentDuration = TimeSpan.FromMinutes(10), });
import os import tempfile folder = tempfile.mkdtemp() events = [] camera.on_recording(events.append) # One recording of at most one second, ended by the SDK. camera.segment_limit_action = optris_sdk.SEGMENT_LIMIT_STOP_RECORDING camera.start_recording(os.path.join(folder, 'run.mkv'), options=optris_sdk.RecordingOptions( max_segment_duration_s=1.0)) while camera.is_recording: time.sleep(0.1) for event in events: if (event.phase == optris_sdk.RECORDING_STOPPED and event.stop_reason == optris_sdk.RECORDING_STOP_SEGMENT_LIMIT): print(f'{event.path} reached its limit and is finished') print(sorted(os.listdir(folder)))
camera.on_recording_event(|e| { if e.phase == RecordingPhase::Stopped && e.stop_reason == RecordingStopReason::SegmentLimit { println!("{} reached its limit and is finished", e.path); } })?; // One recording of at most ten minutes, ended by the SDK. camera.set_segment_limit_action(SegmentLimitAction::StopRecording)?; let options = RecordingOptions { max_segment_duration: Duration::from_secs(600), ..RecordingOptions::default() }; camera.start_recording_with("/data/run.mkv", &options)?;
Starting a new recording at the limit
With kStartNewRecording each file ends with kStopped carrying the same kSegmentLimit, and the next recording starts at once:
#include <optrissdk.h> #include <chrono> auto imager = optris::sdk::Imager::Create(); imager->Recorder().OnRecording([](const optris::sdk::rec::RecordingEvent &e) { if (e.phase == optris::sdk::rec::RecordingPhase::kStopped && e.stop_reason == optris::sdk::rec::RecordingStopReason::kSegmentLimit) { std::println("{} is finished, the next one has started", e.path); } }); imager->Start(); // A new recording, with its own name and its own start, every hour. imager->Recorder().SetSegmentLimitAction( optris::sdk::rec::SegmentLimitAction::kStartNewRecording); optris::sdk::rec::RecordingOptions options; options.max_segment_duration = std::chrono::hours(1); imager->Recorder().Start("/data/run.mkv", options);
optris_sdk_recording_options options; /* A new recording, with its own name and its own start, every hour. */ optris_sdk_imager_set_segment_limit_action( imager, OPTRIS_SDK_SEGMENT_LIMIT_START_NEW_RECORDING); optris_sdk_recording_options_init(&options, sizeof(options)); options.max_segment_duration_ms = 3600000; optris_sdk_imager_start_recording_ex(imager, "/data/run.mkv", &options);
using var camera = ThermalCamera.OpenSimulated(); camera.OnRecording(e => { if (e.Phase == RecordingPhase.Stopped && e.StopReason == RecordingStopReason.SegmentLimit) { Console.WriteLine($"{e.Path} is finished, the next one has started"); } }); camera.Start(); // A new recording, with its own name and its own start, every hour. camera.SegmentLimitAction = SegmentLimitAction.StartNewRecording; camera.StartRecording("run.mkv", new RecordingOptions { MaxSegmentDuration = TimeSpan.FromHours(1), }); camera.StopRecording();
import os import tempfile folder = tempfile.mkdtemp() events = [] camera.on_recording(events.append) # A new recording, with its own name and its own start, every second. camera.segment_limit_action = optris_sdk.SEGMENT_LIMIT_START_NEW_RECORDING camera.start_recording(os.path.join(folder, 'run.mkv'), options=optris_sdk.RecordingOptions( max_segment_duration_s=1.0)) time.sleep(2.5) camera.stop_recording() for event in events: if (event.phase == optris_sdk.RECORDING_STOPPED and event.stop_reason == optris_sdk.RECORDING_STOP_SEGMENT_LIMIT): print(f'{event.path} is finished, the next one has started') print(sorted(os.listdir(folder)))
camera.on_recording_event(|e| { if e.phase == RecordingPhase::Stopped && e.stop_reason == RecordingStopReason::SegmentLimit { println!("{} is finished, the next one has started", e.path); } })?; // A new recording, with its own name and its own start, every hour. camera.set_segment_limit_action(SegmentLimitAction::StartNewRecording)?; let options = RecordingOptions { max_segment_duration: Duration::from_secs(3600), ..RecordingOptions::default() }; camera.start_recording_with("/data/run.mkv", &options)?;
The size limit is a ceiling for the finished file, trailer included
A rolled-over part is never larger than the limit you set: the recorder projects what the part will hold (the open Matroska Cluster, the muxer's interleaving queue, the frame about to be written, and the Cues the trailer puts down) and rolls over while all of it still fits. Until v12 it compared the muxer's position against the limit, so parts ended past it by everything written after the last check: 1.6 MB past a 4 GiB limit on a PI 640i, and 31 % past a 1 MiB limit on 160×120 noise. No margin of your own is needed, and no fixed one would have worked: the Cues grow at about 24 B a frame. Leave a margin for what you write afterwards: attaching a file to a finished part rewrites it.
Turning the flag off while recording
The camera's shutter closes every so often to re-reference the detector (that closure is the non-uniformity correction, there is no other kind on this hardware), at a cost of a gap of a second or two in which no frame arrives. In a recording of a part going past on a line, that gap is in the file for good and the part that went past during it was not measured.
So the shutter can be held back for as long as a recording runs:
#include <optrissdk.h> auto imager = optris::sdk::Imager::Create(); auto nuc = imager->Detector().GetAuto(); nuc.while_recording = optris::sdk::FlagWhileRecording::kAvoid; imager->Detector().SetAuto(nuc); imager->Start(); imager->Recorder().Start("/data/run_041.mkv");
optris_sdk_imager_set_flag_while_recording( imager, OPTRIS_SDK_FLAG_WHILE_RECORDING_AVOID, 0.0F); optris_sdk_imager_start(imager); optris_sdk_imager_start_recording(imager, "/data/run_041.mkv");
camera.SetFlagWhileRecording(FlagWhileRecording.Avoid); camera.Start(); camera.StartRecording("run_041.mkv");
camera.detector.set_flag_while_recording( optris_sdk.FLAG_WHILE_RECORDING_AVOID) camera.start_recording('run_041.mkv') camera.stop_recording()
camera.set_flag_while_recording(FlagWhileRecording::Avoid, 0.0)?; camera.start_recording("run_041.mkv")?; camera.stop_recording()?;
AutoNucConfig::while_recording |
What happens while a recording runs |
|---|---|
kUse |
The shutter closes on its own schedule, as it does the rest of the time. The default, so a camera nobody configures behaves exactly as it always has. |
kAvoid |
No scheduled closure happens at all. The stream has no gap and the detector is never re-referenced. |
kAvoidUnlessDrift |
No scheduled closure happens unless the detector has actually drifted past recording_override_drift_c. |
kAvoidUnlessDrift exists because the SDK measures something PIX Connect does not: how far the camera's three internal temperature probes have moved since the last correction. The drift is compared against recording_override_drift_c and not against temp_drift_threshold_c, which defaults to 0.1 °C and is a hair trigger by design; comparing against that would let every closure through and make the mode indistinguishable from kUse.
There is deliberately no default for recording_override_drift_c, and zero is refused. How much drift a measurement can bear is a property of what you are measuring, not of the camera. Zero would behave as kUse, because every drift is more than zero, so the override would fire every time. SetAuto() throws ConfigException for that pair instead of accepting it and quietly doing something else.
A manual closure still works. Detector::TriggerShutter() is an instruction, not a schedule, and none of these affect it. The startup calibration, a temperature-range change and an optics change also still close the shutter, because none of those is the automatic schedule.
What it costs, and why the file says so
A recording stores finished temperatures. Every number in the file was computed before it was written, so drift the camera did not correct is in those pixels permanently. Opening the file later and reprocessing it does not take the drift out; nothing does.
A suppressed recording is therefore indistinguishable from a good one by inspection: no gap in the stream, a normal-looking picture, and temperatures that look like temperatures. They are simply wrong, by an amount that grows over the take.
The file therefore says what was done to it, in two places. An ordinary recording carries neither, so a file that carries one is a file something was done to.
In the header, in otc-meta.json, written as the file opens:
"flag_policy": { "while_recording": "avoid_unless_drift", "override_drift_c": 2.0 }
That is what was configured. It sits in the first few kilobytes, before any video, so "was this recording made with the shutter held back" is answered without decoding a frame, the same promise every other marker in the format contract makes. The key is absent for a recording made at kUse, and absent in every recording written before this existed; for those files the absence is also the truth, because nothing could be suppressed then.
On the per-frame telemetry track, on each frame where a correction was actually refused:
"flag_policy": { "while_recording": "avoid", "held": true, "drift_c": 0.73 }
That is what happened. drift_c is the worst of the three internal probes' drift since the last correction, roughly how wrong that frame is. It is present only on the degraded frames, so a reader sees which stretch to distrust and by how much, and the largest drift_c is the worst the take ever got. drift_c is omitted rather than written as zero before the camera's minimum flag interval has elapsed, because the probes are not read until then: a missing value is "not measured yet", never "no drift".
Reading it back:
#include <optrissdk.h> #include <print> auto player = optris::sdk::Player::Open("/data/run_041.mkv"); if (const auto policy = player->GetRecordedFlagPolicy()) { std::println("made with the shutter policy '{}'", policy->while_recording); if (policy->held.value_or(false)) { std::println("this frame is degraded by about {} C", policy->drift_c.value_or(0.0f)); } } else { std::println("the shutter was not held back while this was recorded"); }
optris_sdk_imager *playback = NULL; optris_sdk_recorded_flag_policy policy; optris_sdk_imager_create_from_file("/data/run_041.mkv", &playback); optris_sdk_recorded_flag_policy_init(&policy, sizeof(policy)); if (optris_sdk_imager_get_recorded_flag_policy(playback, &policy) == OPTRIS_SDK_OK) { printf("made with the shutter policy %d\n", (int)policy.policy); } else { /* NOT_FOUND: the shutter was not held back while this was * recorded. */ }
await using var playback = ThermalCamera.OpenRecording("run_041.mkv"); if (playback.RecordedFlagPolicy is { } policy) { Console.WriteLine($"made with the shutter policy '{policy.Policy}'"); } else { Console.WriteLine( "the shutter was not held back while this was recorded"); }
playback = optris_sdk.Camera.open_recording('run_041.mkv') policy = playback.detector.recorded_flag_policy if policy is not None: print(f"made with the shutter policy {policy.policy}") else: print('the shutter was not held back while this was recorded')
let playback = Camera::from_file("run_041.mkv")?; match playback.recorded_flag_policy()? { Some(policy) => println!("made with the shutter policy '{}'", policy.policy_name), None => println!( "the shutter was not held back while this was recorded"), }
GetRecordedFlagPolicy() merges the two halves, so one call answers both questions: the policy and its override come from the header, held and drift_c from the frame now on screen. An empty answer means nothing was suppressed.
Watching it live
Detector::GetShutterDeferral() is the same facts while the recording is still running:
#include <optrissdk.h> #include <print> void ShowShutterState(optris::sdk::Imager& imager) { const auto held = imager.Detector().GetShutterDeferral(); if (!held.policy_in_force) { return; // nothing is being suppressed } std::println("flag suppressed; drift {} C, worst so far {} C, " "{} frames uncorrected", held.drift_c, held.peak_drift_c, held.deferred_frames); }
Read policy_in_force first, and drive any "flag suppressed" indicator from it rather than from the configured mode. It is false when no recording is running, when the policy is kUse, when the automatic shutter is switched off, and, the case that matters, while a process-interface input owns the flag. The SDK runs no shutter cycle of its own then (see Shutter Control and Detector::IsShutterExternallyControlled()), so there is no closure to hold and the setting does nothing. The setting is still stored and still read back: moot rather than working, and policy_in_force is how to find that out.
peak_drift_c and deferred_frames are reset when a recording starts and kept after it stops, so the summary is readable once the file is closed, the same contract GetStatistics() has. They are the two fields policy_in_force does not gate. drift_c and deferring_now are zero and false whenever the policy is not in force, so a camera running the default cannot hand back a live drift reading that looks like a suppression. The SDK also writes one log line as each suppressed recording ends, naming the policy, the count and the worst drift.
deferred_frames counts frames, not corrections. A refused cycle stays due (the interval goes on elapsing and the drift goes on growing), so every frame from the refusal onwards is one that went out uncorrected. Under kAvoid a ten-minute recording at 27 Hz reports some sixteen thousand. Read it against the recording's own frame count: "16 000 of 16 200 frames uncorrected" says how much of the file is degraded, and peak_drift_c says what that cost in kelvin.
From C, .NET, Python and Rust
| Set it | Watch it live | Read it off a file | |
|---|---|---|---|
| C++ | Detector::SetAuto() with AutoNucConfig::while_recording |
Detector::GetShutterDeferral() |
Player::GetRecordedFlagPolicy() |
| C | optris_sdk_imager_set_flag_while_recording() |
optris_sdk_imager_get_shutter_deferral() |
optris_sdk_imager_get_recorded_flag_policy() |
| .NET | ThermalCamera.SetFlagWhileRecording() |
ThermalCamera.ShutterDeferral |
ThermalCamera.RecordedFlagPolicy |
| Python | camera.detector.set_flag_while_recording() |
camera.detector.shutter_deferral |
camera.detector.recorded_flag_policy |
| Rust | Camera::set_flag_while_recording() |
Camera::shutter_deferral() |
Camera::recorded_flag_policy() |
#include "optris/sdk_c.h" #include <stdio.h> void watch_the_shutter(optris_sdk_imager *imager) { optris_sdk_shutter_deferral held; optris_sdk_shutter_deferral_init(&held, sizeof(held)); if (optris_sdk_imager_get_shutter_deferral(imager, &held) != OPTRIS_SDK_OK) { return; } if (held.policy_in_force && held.deferring_now) { printf("flag suppressed, drift %.2f C\n", (double)held.drift_c); } }
The C reader reports OPTRIS_SDK_ERROR_NOT_FOUND for a recording that declares no policy. Unlike most NOT_FOUND answers that is an answer rather than an absence: the block is omitted entirely at the default policy, so a file without it is a file whose shutter was never held. .NET, Python and Rust project it as null / None.