OptrisOptrisDocumentation

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

video — functions

Writing a recording out as a video.

The SDK has been able to produce an ordinary coloured video since the exporter gained kColorized, and no application outside C++ could reach it. The radiometric export -- the thermal frames themselves -- is the right thing for an archive and the wrong one for a person watching, so "share what this recording shows" was not expressible from Python at all.

Two kinds of output, chosen by content and not by the codec:

Radiometric produces a file only this SDK can read back as temperatures. Fed with VideoExport.write_frame. It keeps every temperature through VIDEO_CODEC_FFV1, and 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: the double-height picture such a file holds moves them by degrees. VideoExport.keeps_temperatures says which one an export is.

Colorized produces an ordinary colour video any player opens and keeps no temperatures at all. Fed with VideoExport.write_picture.

Ask before you choose a codec

is_codec_available encodes a picture through each candidate encoder, set up exactly as VideoExport.create sets it up for a colour export of that size, so a True means a picture went through, not merely that FFmpeg knows the name or that the encoder opened. x264 and x265 are GPL and absent from the LGPL FFmpeg this SDK ships on Windows, and VIDEO_CODEC_AV1 falls back to libaom in software, fifty times slower than real time, when no hardware encoder works.

VIDEO_CODEC_MJPEG is the default because it is the only lossy encoder certain to be present. It is native to FFmpeg and in every build.

Finish before you read the file

A video is not a valid file until its trailer is written, and an encoder holds frames back. VideoExport.finish writes it; closing the export finishes it for you, so a forgotten finish still leaves a playable video -- but closing cannot report a flush failure, which is the reason to call it explicitly.

with optris_sdk.VideoExport.create(
    'share.mkv', width=w, height=h, frame_rate=30.0,
    content=optris_sdk.VIDEO_CONTENT_COLORIZED) as export:
  for bgra, at_s in frames:
    export.write_picture(bgra, w, h, timestamp_s=at_s)
  export.finish()

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.

is_codec_available(codec, width = 0, height = 0)

Whether the linked FFmpeg can encode codec.

Ask before choosing. See this module's own documentation for why the answer varies by build and by machine.

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 it was given. Measured on one desktop: H.264 answers True at 640x480 and a create at 64x48 then raises optris_sdk.errors.NotSupportedError, with a message telling the caller to ask this function first. 0 is the right answer for building a menu before a size is known.

  • Parameter width — the frame width you are going to ask for, or 0 for a 640x480 probe.
  • Parameter height — the frame height, with the same rule.