OptrisOptrisDocumentation

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

VideoExport

public sealed class VideoExport : IDisposable

A video being written.

Two kinds of output, chosen by VideoExportOptions.Content and not by the codec: radiometric, which produces a file only this SDK can read back as temperatures and keeps every one of them through FFV1, or through any codec into a Matroska (.mkv) file, which then carries a lossless track beside the lossy one (through a lossy codec into MP4, MOV or WebM it keeps none of them exactly, and VideoExport.KeepsTemperatures says so); and colorized, which produces an ordinary colour video any player opens and keeps no temperatures at all. The second is what an application wants for "share what this recording shows".

Not thread-safe. Write frames from one thread. The SDK does not lock this for you, deliberately: a lock would make the object look shareable while the encoder behind it still interleaved two threads' frames into one stream, which produces a file rather than an error.

Call VideoExport.Finish before reading the file. A video is not a valid file until its trailer is written, and an encoder holds frames back. VideoExport.Dispose finishes it for you, so a forgotten Finish still leaves a playable video, but it cannot report a flush failure, which is the reason to call it explicitly.

Example

var options = new VideoExportOptions
{
    OutputPath = "share.mkv",
    Width = replay.Width,
    Height = replay.Height,
    FrameRate = 30.0f,
    Content = VideoContent.Colorized,
};
using var export = VideoExport.Create(options);
//... per frame, with the recording's own time so gaps survive:
export.WritePicture(bgra, replay.Width, replay.Height,
                    replay.Width * 4, replay.PlaybackPosition);
export.Finish();

VideoExport: properties

public string EncoderName { get; }

Which encoder actually opened, by FFmpeg's name for it: mjpeg, libx264, h264_mf, av1_vaapi.

Worth showing or logging: VideoCodec.Av1 through libaom and through av1_vaapi are the same request answered fifty times apart, and this is the only thing that says which happened.

public bool KeepsTemperatures { get; }

Whether this export keeps every temperature it is handed.

Added in 12.0.28. True for a VideoContent.Radiometric export through VideoCodec.Ffv1, and for one through a lossy codec into a Matroska (.mkv) file, which carries the frames on a lossless track as well. False for a radiometric export through a lossy codec into an MP4, MOV or WebM file, whose double-height picture does not give the temperatures back, and for a VideoContent.Colorized export, which never had any. Ask it before telling anyone the file is a radiometric one.

VideoExport: methods

public static VideoExport Create(VideoExportOptions options)

Open a video file for writing.

  • Throws ArgumentNullException: options is null.
  • Throws FeatureNotSupportedException: The requested codec has no encoder in this build. Ask VideoExport.IsCodecAvailable(…) first to tell that apart from a configuration mistake.
  • Throws SdkConfigurationException: A zero dimension, a frame rate that is not greater than zero, or an empty path.
public void Dispose()

Release the export, finishing the file first if VideoExport.Finish was not called.

public void Finish()

Flush the encoder and close the container.

  • Throws SdkIOException: The encoder's last pictures, the trailer or the close could not be written, or an earlier write was refused. The file is then not a whole video, and calling this again raises the same. A file the file system would not let grow raises SdkConfigurationException instead.

Idempotent. A write afterwards raises InvalidOperationException rather than being accepted and going nowhere.

public static bool IsCodecAvailable(VideoCodec codec, int width = 0, int height = 0)

Whether the FFmpeg this library was linked against can encode codec.

  • codec: The codec to ask about.
  • width: The frame width you are going to ask for, or zero for a 640×480 probe. Pass the size you will use. Several hardware encoders have a minimum resolution (h264_nvenc is one), and VideoExport.Create(…) probes the same encoder list at the size in the options. Measured on one desktop: H.264 answers true at 640×480 and VideoExport.Create(…) at 64×48 then throws FeatureNotSupportedException, with a message telling the caller to ask this first. Zero is the right answer for building a menu before a size is known.
  • height: The frame height, with the same rule.

Ask before choosing. x264 and x265 are GPL and absent from the LGPL FFmpeg this SDK ships on Windows, and VideoCodec.Av1 falls back to libaom in software, fifty times slower than real time, when no hardware encoder works.

A yes means a picture went through: each candidate encoder is set up exactly as VideoExport.Create(…) sets it up for a VideoContent.Colorized export of this size, in the pixel format it would be handed, and one picture is encoded. Opening alone is not enough; an encoder can open and refuse its first frame. A radiometric export through a lossy codec is twice as tall, and VideoExport.Create(…) probes that shape for itself.

public void WriteFrame(ThermalFrame frame)

Write one 16-bit thermal frame.

  • Throws SdkIOException: The file could not be written: a full drive, a removed one. Kept, so every later write and VideoExport.Finish raise the same, because the video is now missing a picture.

For VideoContent.Radiometric only; a colorized export raises InvalidOperationException and names the property to change. Timed by VideoExportOptions.PaceByArrival: there is no per-frame timestamp on this path, because a frame carries its own capture stamp and that counts from the transport's epoch rather than from the start of the video.

public void WritePicture(ReadOnlySpan<byte> bgra, int width, int height, int stride = 0, Nullable<TimeSpan> timestamp = default)

Write one colour picture.

  • bgra: BGRA8 pixels, row-major: byte 0 blue, 1 green, 2 red, 3 alpha. The same layout ThermalCamera.OnColorImage(…) delivers, and the one a Windows bitmap and Avalonia's Bgra8888 want.

  • width: Must equal VideoExportOptions.Width. A video stream has one frame size for its whole length and the encoder is opened once, so this cannot vary per frame; it is carried and validated rather than ignored, so a caller that changes its surface size mid-export is told rather than producing a file of sheared pictures.

  • height: Must equal VideoExportOptions.Height.

  • stride: Row stride in bytes, or zero for the tight width * 4. This is what makes a caller-composed surface usable: a GPU readback, a Windows DIB and a Cairo surface are all padded to an alignment, and a stride computed from the width shears a padded buffer progressively down the frame.

  • timestamp: When this picture belongs, measured from the start of the video, or null to use VideoExportOptions.PaceByArrival. This is what keeps a recording's gaps in the video. Counting frames closes them and arrival time follows the speed the replay is being fed at, so neither describes the file being exported. Quantised to one VideoExportOptions.FrameRate period, so a gap shorter than one frame period closes.

  • Throws SdkConfigurationException: bgra is shorter than stride * height, the dimensions disagree with the configuration, or stride is below width * 4. Also raised, and kept the same way as an SdkIOException, when the file system will not let the file grow any further.

  • Throws SdkIOException: The file could not be written: a full drive, a removed one. Kept, so every later write and VideoExport.Finish raise the same, because the video is now missing a picture.