OptrisOptrisDocumentation

Documentation/OTC SDK/Optris.Sdk — C# API referencev12.0

RecordingFile

public sealed class RecordingFile : IDisposable

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.

Use ThermalCamera.Attachments instead when a recording is already open for playback; there is no reason to read the file twice.

Dispose it. It holds every attachment payload the open read in, which is native memory until it is released.

The still-image counterpart is Snapshot. RecordingAttachments.Read(…) covers both behind one call when you do not know which kind of file you have.

Example

using RecordingFile file = RecordingFile.Open("session.mkv");
foreach (AttachmentInfo carried in file.Attachments)
{
    Console.WriteLine($"{carried.Name} ({carried.Size} bytes)");
}

RecordingFile: properties

public IReadOnlyList<AttachmentInfo> Attachments { get; }

Every file carried inside this recording, in container order.

The SDK's own otc-meta.json comes first, followed by device.json, config.json and whatever an attachment provider supplied while the file was being written. Telling your files from the SDK's is a comparison on AttachmentInfo.Name.

The index only: reading a payload is RecordingFile.ReadAttachment(…).

AttachmentInfo.Sha256 is the digest the file's own index recorded, and unlike a snapshot's it is not re-verified on read: an MKV attachment stream is stored verbatim rather than deflated, so there is no decode step that could go wrong unnoticed. A file this SDK did not write carries no index and reports an empty string, which means "the file does not say" rather than "it matched".

RecordingFile: methods

public static void AttachFiles(string path, IReadOnlyList<Attachment> files)

Add files to a recording that has already been written.

  • path: An .mkv this SDK or another Matroska writer wrote. Replaced by the rewritten file on success, and left exactly as it was on any failure.

  • files: What to add. Each needs a non-empty name and at least one byte of content; Matroska stores no entry for an empty attachment, so one is refused rather than silently dropped. An empty Attachment.Mime is written as application/octet-stream. Names need not be unique; a name the recording already carries gets a second entry rather than replacing the first.

  • Throws ArgumentException: path is null or empty, or files is empty. Rewriting a container to add nothing is an expensive no-op, so it is reported rather than performed.

  • Throws OptrisSdkException: The recording cannot be read, is not Matroska, the disk has not the room, or the rewrite cannot be put in place.

  • Throws SdkConfigurationException: The result would be larger than one file may be on the destination's file system. See the remarks.

The counterpart to ThermalCamera.SetAttachmentProvider(…), 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 anything that only exists once the recording has ended (a log, a per-widget history, a report) can never travel inside the file through it. This is how it gets there.

Nothing distinguishes what this adds from what a provider added. The files come back through RecordingFile.Attachments, ThermalCamera.Attachments and RecordingAttachments.Read(…) in the same enumeration, at the same place in it, with the same digest recorded in the recording's own otc-meta.json. A reader cannot tell when an attachment arrived.

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: the operation ffmpeg -i in.mkv -attach … -c copy out.mkv performs. On a 5 GB recording it costs 5 GB read, 5 GB written and 5 GB of free space while it runs. Pass every file in one call rather than calling once per file.

That is minutes on a removable drive. Measured: 5,160,582,106 bytes in 10.2 s on a workstation SSD, and 4,292,417,332 bytes in 443.2 s (seven and a half minutes, at 9.7 MB/s) on a FAT32 USB stick, to add 8,729 bytes. The call blocks for the whole of it, with no progress and no way to cancel, so an application doing this after a stop has to say so to its user rather than appear to have hung.

The result has to fit one file, and that is checked separately from free space. Where a file system caps one file (commonly at 4,294,967,295 bytes), a part the recorder split just under that cap ends within a few megabytes of it: a measured one had 2,540,804 bytes of headroom left, so an attachment 2.5 MB larger would not have fitted. If you mean to attach to a part, leave room for it in RecordingOptions.MaxSegmentBytes. A result that certainly cannot fit is refused before anything is copied; one that turns out not to is stopped as the copy runs rather than at the very end. Either way the original is untouched. It comes back as SdkConfigurationException rather than SdkIOException so it can be told apart from a full disk: more free space does not help, and the fix is a different destination or less to attach. On a file system whose limit cannot be identified nothing is checked.

It cannot cost you the recording. The source is opened for reading only. The result is written to a temporary beside it, flushed, 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 a single atomic operation on both Linux and Windows. A crash, a power cut, a full disk or a muxer failure at any point before that rename costs the temporary and nothing else.

On Windows the final rename fails when the recording is open in another program, and this throws with the original intact. On Linux it succeeds, and a reader that already has the file open keeps reading the bytes it opened until it reopens the path.

Attachment.Compress is ignored: an MKV attachment stream is stored verbatim, exactly as it is for a provider's files.

Example

RecordingFile.AttachFiles(
    "session.mkv",
    [new Attachment("widget-7-history.csv", csvBytes)
         { Mime = "text/csv" }]);
public static void AttachFilesToCopy(string source, string destination, IReadOnlyList<Attachment> files)

The same, writing the result somewhere else and leaving the source untouched.

  • source: The .mkv to read. Never modified.

  • destination: Where the rewritten file goes. Overwritten if it exists, and only by a rename of a verified temporary.

  • files: What to add; see RecordingFile.AttachFiles(…).

  • Throws ArgumentException: Either path is null or empty, or files is empty.

  • Throws OptrisSdkException: As RecordingFile.AttachFiles(…), and additionally when destination is the same file as source; use RecordingFile.AttachFiles(…) for that, which does it safely.

For a caller who wants to keep the original as it is, or who is building a copy to hand on. RecordingFile.AttachFiles(…) 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.

public void Dispose()

Release what the open read in.

Disposing twice is safe.

public static RecordingFile Open(string path)

Open a recording and read what it carries into memory.

  • path: An .mkv written by this SDK. A plain recording, one segment of a segmented one, and a multi-camera session file are all accepted; a session's own otc-session.json comes back as one of the attachments, so a session can be recognized without decoding it.

Returns: The opened recording. Dispose it.

  • Throws ArgumentException: path is null or empty.
  • Throws OptrisSdkException: The file cannot be opened, or is not a container this SDK can read.
public byte[] ReadAttachment(int index)

Copy one carried file's bytes out.

Returns: The file's content.

  • Throws ArgumentOutOfRangeException: index is not a position in RecordingFile.Attachments.
  • Throws ObjectDisposedException: The recording has been disposed.