RecordingFile
class optris_sdk.recording.RecordingFile
A recording this SDK wrote, opened for the files it carries.
The no-camera, no-playback read. Opening one parses the container header and stops: no decoder is created, no playback thread is started and no frame is touched, so it costs the same on an hour-long take as on a one-second one. That is what makes listing a folder of recordings, or restoring the session that wrote them, affordable.
It is a context manager; use it as one::
with optris_sdk.RecordingFile.open('session.mkv') as carried:
for one in carried.attachments:
print(one.name, one.size, len(one.data))
Use optris_sdk.camera.Camera.attachments instead when the
recording is already open for playback -- there is no reason to read
the file twice. The still-image counterpart is
optris_sdk.snapshot.Snapshot.
Every file the recording carries, the SDK's own included. The
SDK writes otc-meta.json, device.json, config.json and,
for a multi-camera session file, otc-session.json; all of them
are in attachments at their container position, which is
what the C ABI and .NET both report. That is the opposite of
optris_sdk.snapshot.Snapshot.attachments, which leaves three
of the SDK's own out -- and the difference is deliberate in both
places rather than an inconsistency here: a snapshot's excluded
files are the measurement itself and the calibration behind it,
reached through Snapshot.load_thermal and
optris_sdk.camera.Camera.open_still, while a recording's
are documents nothing else can hand back. Telling your files from
the SDK's is a comparison on Attachment.name.
RecordingFile — properties
attachment_count
How many files are carried inside this recording.
attachments
Every file carried inside this recording, in container order.
A list of optris_sdk.snapshot.Attachment, the same
type a provider builds and a snapshot hands back. Their bytes
are not read until something asks for them, so listing a folder
of recordings costs no payload at all.
Attachment.sha256 is the digest the file's own
otc-meta.json index recorded, and -- unlike a snapshot's --
it is not re-verified at open: an MKV attachment stream is
stored verbatim rather than deflated, so there is no decode step
that could go wrong unnoticed. A file written by something other
than this SDK, or by a version of it older than the attachment
index, carries none and reports '', which means "the file
does not say" and never "it matched".
Attachment.compress is None here for the same reason
it is on a snapshot read: the container does not record it.
RecordingFile — methods
open(cls, path)
Open a recording and read what it carries into memory.
Works on anything this SDK writes as Matroska: a plain
recording, one segment of a segmented one, and a multi-camera
session file -- whose own otc-session.json comes back as one
of the attachments, so a session can be recognised without
decoding it.
Raises optris_sdk.errors.IoError when the file cannot
be opened or is not a container this SDK can read.
read_attachment(index)
Copy one carried file's bytes out, as bytes.
index is a position in attachments. A negative one
is refused rather than counting from the end: the ABI's index is
an unsigned size_t, so -1 would arrive as
18,446,744,073,709,551,615 and the refusal would come back as a
bare invalid-argument status with no hint of what was wrong.
attach_files(path, files)
Add files to a recording that has already been written.
The counterpart to
optris_sdk.camera.Camera.set_attachment_provider, for
what a session produces rather than what is known before it
starts. A provider is asked immediately before the MKV header
goes down, so a log, a report or a per-widget history -- which
only exist once the recording has ended -- can never travel
inside the file through it. This is how they get there.
Nothing distinguishes what this adds from what a provider added.
The files come back through attachments and through
optris_sdk.camera.Camera.attachments in the same
enumeration, at the same place in it, with the same digest
recorded in the recording's own otc-meta.json.
This rewrites the file. Matroska keeps its attachments in the Segment header, ahead of the first Cluster, so adding one to a finished recording means writing the whole container out again. On a 5 GB recording that is 5 GB read, 5 GB written and 5 GB of free space while it runs -- measured at 10.2 s on a workstation SSD and 443.2 s, seven and a half minutes, on a USB stick, to add 8,729 bytes. The call blocks for all of it with no progress and no way to cancel, so an application doing this after a stop has to say so rather than appear to have hung. Pass every file in one call rather than calling once per file.
It cannot cost you the recording. The source is opened for reading only; the result is written to a temporary beside it, reopened and checked -- every attachment present at its recorded size, every track still there, the duration unchanged -- and only then renamed over the original, which is one atomic operation on both Linux and Windows. A crash, a power cut, a full disk or a muxer failure before that rename costs the temporary and nothing else.
Raises ValueError for an empty list -- rewriting a
container to add nothing is an expensive no-op, so it is
reported rather than performed -- and
optris_sdk.errors.OutOfRangeError when the result
would be larger than one file may be on the destination's file
system. That one is deliberately not an
optris_sdk.errors.IoError: more free space does not
help, and the fix is a different destination or less to attach.
- Parameter
path— an.mkvthis SDK or another Matroska writer wrote. Replaced by the rewritten file on success and left exactly as it was on any failure. - Parameter
files— theoptris_sdk.snapshot.Attachmentobjects to add. Each needs a name and at least one byte: Matroska stores no entry for an empty attachment, so one is refused rather than accepted and silently dropped. AnAttachment.mimeofNoneis written asapplication/octet-stream, andAttachment.compressis ignored -- an MKV attachment stream is stored verbatim, exactly as it is for a provider's files. Names need not be unique; a name the recording already carries gets a second entry rather than replacing the first.
attach_files_to_copy(source, destination, files)
The same, writing the result somewhere else.
For a caller who wants to keep the original as it is, or who is
building a copy to hand on. attach_files is this plus
the atomic rename, so the safety described there is the safety
of this call -- the source is opened read-only either way.
Raises optris_sdk.errors.InvalidArgumentError when
destination names the same file as source -- use
attach_files for that, which does it safely.
- Parameter
source— the.mkvto read. Never modified. - Parameter
destination— where the rewritten file goes. Overwritten if it exists, and only by a rename of a verified temporary, so a failure leaves no half-written file there either. - Parameter
files— what to add; seeattach_files.
close()
Release what the open read in. Closing twice is a no-op.