OptrisOptrisDocumentation

Documentation/OTC SDK/optris_sdk — Python API referencev12.0

VideoExport

class optris_sdk.video.VideoExport

A video being written.

Create one with create. It is a context manager; use it as one, or call close yourself.

VideoExport — properties

encoder_name

Which encoder actually opened, by FFmpeg's name for it.

mjpeg, libx264, h264_mf, av1_vaapi. Worth showing or logging: VIDEO_CODEC_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.

keeps_temperatures

Whether this export keeps every temperature it is handed.

Added in 12.0.28. True for a VIDEO_CONTENT_RADIOMETRIC export through VIDEO_CODEC_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 VIDEO_CONTENT_COLORIZED export, which never had any. Ask it before telling anyone the file is a radiometric one.

VideoExport — methods

create(cls, path, width, height, frame_rate, codec = None, content = None, preset = None, bitrate_kbps = None, mjpeg_quality = None, pace_by_arrival = None)

Open a video file for writing.

Every keyword left at None keeps the SDK's own default, which is read from the ABI rather than copied here.

  • Parameter path — where to write.
  • Parameter width — frame width in pixels. For VIDEO_CONTENT_COLORIZED this is the size of your picture, which need not be the camera's: an application that draws its regions, labels and readings into a larger buffer sets that buffer's size here and those are in the video too.
  • Parameter height — frame height in pixels. See width.
  • Parameter frame_rate — declared output rate in Hz, which must be greater than zero. It sets the stream's time base as well as the rate the file announces, so it is also the resolution a per-frame timestamp is quantised to.
  • Parameter codec — one of the VIDEO_CODEC_* values. VIDEO_CODEC_MJPEG by default.
  • Parameter content — VIDEO_CONTENT_RADIOMETRIC by default.
  • Parameter preset — one of the VIDEO_PRESET_* values. H.264 and H.265 only.
  • Parameter bitrate_kbps — target bitrate, or 0 for the encoder's quality mode.
  • Parameter mjpeg_quality — 2 (best) to 31 (worst), 2 when left None. Ignored by every other codec.
  • Parameter pace_by_arrival — time each frame by when it arrives rather than by how many came before. False by default, which is right for an export; True for a live take passed through from a camera. Overridden per frame by timestamp_s on write_picture, which is the right answer for exporting a recording and is neither of these.
  • Raises ~optris_sdk.errors.NotSupportedError — the requested codec has no encoder in this build. Ask is_codec_available first to tell that apart from a configuration mistake.
  • Raises ~optris_sdk.errors.InvalidArgumentError — a zero dimension, a frame rate that is not greater than zero, or an empty path.

write_frame(frame)

Write one 16-bit thermal frame.

For VIDEO_CONTENT_RADIOMETRIC only; a colorized export raises optris_sdk.errors.StateError and names the setting to change.

Timed by pace_by_arrival: 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.

write_picture(bgra, width, height, stride = 0, timestamp_s = None)

Write one colour picture.

A **writable** buffer is read in place. An immutable one
(`bytes`) is copied first, because ctypes cannot take an
address into immutable storage without one. At 640x480 that
copy is 1.2 MB a frame, so a `bytearray` or a NumPy array
is the path to use for a long export.

**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 `frame_rate`
period, so a gap shorter than one frame period closes.
  • Parameter bgra — BGRA8 pixels, row-major: byte 0 blue, 1 green, 2 red, 3 alpha. Anything supporting the buffer protocol -- bytes, bytearray, a memoryview, a NumPy array.
  • Parameter width — must equal the width the export was created with. 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.
  • Parameter height — must equal the height the export was created with.
  • Parameter stride — row stride in bytes, or 0 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.
  • Parameter timestamp_s — when this picture belongs, in seconds from the start of the video, or None to use pace_by_arrival.
  • Raises ~optris_sdk.errors.InvalidArgumentError — bgra is shorter than stride * height, the dimensions disagree with the configuration, or stride is below width * 4.
  • Raises ~optris_sdk.errors.StateError — the export was created for radiometric content, or finish has been called.

finish()

Flush the encoder and close the container.

Idempotent. A write afterwards raises optris_sdk.errors.StateError rather than being accepted and going nowhere.

Raises optris_sdk.errors.IoError when the encoder's last pictures, the trailer or the close could not be written, or when an earlier write was refused (a full drive, a removed one), and optris_sdk.errors.OutOfRangeError when the file system would not let the file grow. The file is then not a whole video, and calling this again raises the same.

close()

Release the export, finishing the file if it was not finished. Safe to call more than once.

__enter__()

__exit__(*_)

__repr__()