OptrisOptrisDocumentation

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

VideoExport

pub struct VideoExport

A video being written.

Created by VideoExport::create and closed when dropped; the drop finishes the file if VideoExport::finish was not called. Call finish explicitly anyway, so that a failure to flush is a status you can see rather than one thrown away in a destructor.

Examples

Export a recording's colour picture, keeping the file's own timing:

# fn main() -> optris_sdk::Result<()> {
use optris_sdk::{
    VideoCodec, VideoContent, VideoExport, VideoExportConfig, VideoPicture,
};

let mut config = VideoExportConfig::new("shift2.mkv", 640, 480, 32.0)?;
config.content = VideoContent::Colorized;
config.codec = if VideoExport::is_codec_available(VideoCodec::H264)? {
    VideoCodec::H264
} else {
    VideoCodec::Mjpeg
};

let mut export = VideoExport::create(&config)?;
println!("encoding with {}", export.encoder_name()?);

let surface = vec![0u8; 640 * 480 * 4];
let mut picture = VideoPicture::new(&surface, 640, 480);
picture.timestamp_us = Some(0);
export.write_picture(picture)?;

export.finish()?;
# Ok(())
# }

VideoExport — methods

pub fn is_codec_available(codec: VideoCodec) -> Result<bool>

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

Ask before choosing. Which encoders exist is a property of the build and of the machine: 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 an export creates it for a colour export of this size, in the pixel format it would be handed, and one picture is encoded. That makes it worth caching rather than asking per frame.

Errors

Returns Status::InvalidArgument for a codec value the library does not know.

pub fn is_codec_available_at(codec: VideoCodec, width: u32, height: u32) -> Result<bool>

Whether the linked FFmpeg can encode codec at this size.

Several hardware encoders have a minimum resolution (h264_nvenc is one) and VideoExport::create probes the same encoder list at the size in the configuration. Measured on one desktop: H.264 answers true at 640x480 and a create at 64x48 then returns Status::NotSupported, with a message telling the caller to ask first. VideoExport::is_codec_available passes zeroes, which probe at 640x480 and are the right answer for building a menu before a size is known.

Errors

Returns Status::InvalidArgument for a codec this library does not know.

pub fn create(config: &VideoExportConfig) -> Result<Self>

Open a video file for writing.

Errors

Returns Status::NotSupported when the requested codec has no encoder in this build (ask VideoExport::is_codec_available first to tell that apart from a configuration mistake), Status::Io when the file cannot be created, and Status::InvalidArgument for a zero dimension, a non-positive frame rate or an empty path.

pub fn write_frame(&mut self, frame: Frame<'_>) -> Result<()>

Write one 16-bit thermal frame.

For VideoContent::Radiometric only. The frame's dimensions must match the configuration.

Timed by the configuration's pacing: 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.

Errors

Returns Status::InvalidState on a colorized export, which names the field to change, and after VideoExport::finish.

pub fn write_picture(&mut self, picture: VideoPicture<'_>) -> Result<()>

Write one colour picture.

For VideoContent::Colorized only.

Errors

Returns Status::InvalidArgument when the picture's bytes are short for stride * height, when its dimensions disagree with the configuration, or when stride is below width * 4; and Status::InvalidState on a radiometric export, which names the field to change, and after VideoExport::finish.

pub fn finish(&mut self) -> Result<()>

Flush the encoder and close the container.

Call this before reading the file. A video is not a valid file until its trailer is written, and an encoder holds frames back: stopping at the last write leaves a truncated stream that some players show part of and others refuse.

Idempotent. A write afterwards reports Status::InvalidState rather than being accepted and going nowhere.

Errors

Returns Status::Io 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 Status::OutOfRange when the file system would not let the file grow. The file is then not a whole video, and calling this again returns the same.

pub fn encoder_name(&self) -> Result<String>

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.

Errors

Returns Status::InvalidHandle if the export is not valid.

pub fn keeps_temperatures(&self) -> Result<bool>

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.

Errors

Returns Status::InvalidHandle if the export is not valid.