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. ForVIDEO_CONTENT_COLORIZEDthis 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. Seewidth. - 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 theVIDEO_CODEC_*values.VIDEO_CODEC_MJPEGby default. - Parameter
content—VIDEO_CONTENT_RADIOMETRICby default. - Parameter
preset— one of theVIDEO_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 leftNone. Ignored by every other codec. - Parameter
pace_by_arrival— time each frame by when it arrives rather than by how many came before.Falseby default, which is right for an export;Truefor a live take passed through from a camera. Overridden per frame bytimestamp_sonwrite_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. Askis_codec_availablefirst 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, amemoryview, 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 tightwidth * 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, orNoneto usepace_by_arrival. - Raises
~optris_sdk.errors.InvalidArgumentError—bgrais shorter thanstride * height, the dimensions disagree with the configuration, orstrideis belowwidth * 4. - Raises
~optris_sdk.errors.StateError— the export was created for radiometric content, orfinishhas 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.