RecordingSession
class optris_sdk.session.RecordingSession
Several cameras writing into one file on one clock.
Three phases, in order::
with optris_sdk.RecordingSession.create('plant.mkv') as run:
north = run.add_source(optris_sdk.SessionSource(
160, 120, 32.0, name='Furnace north'))
run.open()
for frame in camera.frames(100):
run.write_frame(north, frame)
The with block stops the session, which is what makes the file
complete on disk. Without it, call stop -- and note that a
write_frame returning without raising does not mean the
frame is in the file: a failure on the writer thread arrives in
statistics and on on_event, not at the call.
Frames in, not cameras in. The SDK does not reach into your cameras; you hand over frames you already have, from a live camera, a replay or anywhere else.
RecordingSession — properties
source_count
How many cameras this session has.
elapsed_s
Session time now, in seconds since open.
Zero before that. A stopwatch, not a date -- say when with
started_at.
started_at
When the session opened, as an aware UTC
datetime.datetime, or None before it opened.
Read once, in the same breath as the session clock's origin. Neither is derived from the other, and this one is not monotonic: NTP can step it.
bytes_written
Total bytes written, across every segment.
RecordingSession — methods
create(cls, path, options = None)
Create a session for path. Nothing is written yet.
Raises optris_sdk.errors.AlreadyExistsError when a
file is already at path -- it is refused before anything is
opened and the existing file is not touched. A caller that
means to overwrite removes it first.
- Parameter
path— where the session goes. Required. - Parameter
options— aSessionOptions, orNonefor the SDK's own defaults.
add_source(source)
Declare one camera and return its index.
Before open and before the first frame. Every track
of a Matroska file is declared in its header, so a camera that
joins later cannot go into this file; a late call raises
optris_sdk.errors.StateError rather than quietly
dropping the camera.
The returned index is what every other call about this camera takes.
open()
Write the header and take the session clock's origin.
Call this yourself. Until the file is open an unwritable path is indistinguishable from a good one, and if the first frame opened it the caller who could have been told would be gone. Calling it twice does nothing.
Session time means "since this returned" rather than "since some camera happened to produce something", which is what lets two cameras' frames be placed against each other at all.
write_frame(source, frame, annotation = None)
Hand one thermal frame to one source.
Stamped with the session clock now, on this thread, then queued. Safe to call from several threads at once -- it has to be, because N cameras deliver on N callback threads.
The frame is copied; you may reuse or free it as soon as this returns.
Returning does not mean the frame is on disk. What this
reports is why a frame is not in the file: an unknown source,
a dimension mismatch, a full queue, a source of the wrong kind
or a stopped session. A failure later, on the writer thread,
lands in statistics and on on_event instead.
Under SESSION_BACKLOG_BLOCK this blocks until the queue
has room, so a slow disk becomes back-pressure here.
write_color_frame(source, rgb, width, height, annotation = None)
Hand one visual picture to a colour source.
rgb is packed RGB24, row-major from the top-left, three
bytes a pixel and no row padding, so it must be exactly
width * height * 3 bytes. It is checked here rather than
left to the SDK: a sliced buffer is a mistake in the calling
code, and a status code arriving from the library says nothing
about which slice was wrong.
The source must have been added with
SESSION_SOURCE_COLOR; a thermal source is refused rather
than converted.
mark_source_lost(source, reason = None)
Record that one camera has gone away.
A hole, not an ending. The source stays open, its track is not closed, and the moment frames arrive again they continue that same track at wherever the session clock has got to. Nothing is padded across the hole and no frame is invented.
Worth doing even though a gap is visible anyway: a busy disk, a shutter cycle and an idle camera all look the same in the track itself, and this is what lets a player show a disconnected picture rather than holding the last frame -- which reads as a live scene.
reason is whatever words you have, written into the file.
Calling it for a source already lost does nothing.
mark_source_resumed(source)
Record that one camera is back.
Optional: the first frame after an outage resumes the source by itself, because a frame arriving is what "it is back" means. Calling it is how an application that knows the transport reconnected ends the recorded outage at the reconnection rather than at the first frame after it -- which on a camera that calibrates on connect is most of a shutter cycle later.
Does nothing for a source that is not lost.
end_source(source, reason = None)
Finish one camera's track. Final and irreversible.
The track ends where the camera stopped: nothing is padded, no frame is invented, and the other cameras are neither slowed to it nor stopped with it. Frames written for an ended source afterwards are refused.
source_state(source)
Where one camera stands: one of the SESSION_SOURCE_*
states.
SESSION_SOURCE_STALLED only ever appears when
SessionOptions.stall_timeout_s was set; with no timeout
a camera that has delivered nothing for an hour still reads
live, because nothing has been decided about it.
statistics(source)
One camera's SessionSourceStats.
on_event(handler)
Be told when the session or one of its cameras changes.
handler takes a SessionEvent. None stops
delivery.
Register this before open. A segment rollover
reports to the handler that was installed when the session
opened.
The handler runs on the session's writer thread. Do not
close the session from it -- closing joins that very thread, so
it would deadlock. Set a flag and act on a thread of your own.
An exception cannot propagate out of it; see
optris_sdk.callbacks.
stop()
Finish the session. The file is complete on disk when this returns.
Drains the queue, flushes every encoder, writes the trailer and
closes the file. Called for you by close and by the
with block; calling it twice is harmless.
A trailer that could not be written does not raise here --
it arrives as a failed on_event naming the file, before
the stop. That is the only way to learn the file came out
damaged.
close()
Stop the session if it is running, then release it.
Closing twice is a no-op.