OptrisOptrisDocumentation

Documentation/OTC SDK/OTC SDK — C++ API referencev12.0

optris::sdk::rec::VideoExporter

Thread safety: Thread safety Not thread-safe. Call WriteFrame() from a single thread.

Public static functions

Create

static std::unique_ptr< VideoExporter > Create(const VideoExportConfig &config)

Create a video exporter.

Opens the output file, initializes the codec and container.

Parameters

Name Description
config Export configuration.

Returns: The exporter, with its output file open.

Exceptions

Name Description
InvalidArgumentException if output_path is empty, if width or height is zero, or if frame_rate is not greater than zero.
FeatureNotSupportedException if this build's FFmpeg has no encoder for codec -- ask IsCodecAvailable() first.
IoException if the output file cannot be opened.

IsCodecAvailable

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

Whether this build can encode with codec.

Which encoders exist is a property of the FFmpeg that was linked, not of the SDK, and it differs between platforms: the Windows build is LGPL, so the GPL-licensed x264 and x265 are absent from it while MJPEG, VP9, AV1 and FFV1 are present. Anything that offers the user a choice of codec should build the list from this rather than from the enum, or it will offer something that fails when it is picked.

Says nothing about whether the encoder is fast enough for a particular job. Measured on one desktop at 640x480: MJPEG ~914 frames/s, H.264 ~732, H.265 ~248, VP9 ~128, FFV1 ~352, and AV1 ~8 -- so AV1 is available and still far too slow to encode a 32 Hz camera live.

Parameters

Name Description
codec The codec to ask about.
width Frame width the caller will actually ask for, or 0 for a 640x480 probe.
height Frame height, with the same rule.

A yes means a picture went through. Each candidate encoder is set up exactly as Create() sets it up for a colour export (VideoContent::kColorized) of this size, in the pixel format Create() would hand it, and one picture is encoded. Opening alone is not enough: Windows' software H.265 encoder opens and then refuses its first frame, and av1_qsv opens in NV12 and refuses the YUV420P it used to be given. And every container that can hold the codec is asked to take the result: Windows' hardware H.265 encoder writes MP4 and not Matroska, so a machine whose only H.265 encoder it is gets a no for kH265, while an MP4 export still works. A VAAPI encoder is still answered by opening alone, because feeding it would mean an upload to the GPU.

A radiometric export through a lossy codec is twice as tall, and Create() probes that shape for itself, going on to the next encoder when one does not take it.

Pass the size you are going to use. Create() probes the same encoder list at the configured size, so a probe at a different size can answer yes where Create() then fails with kCodecNotFound -- measured with IsCodecAvailable(kH264) against a 64x48 export. Several hardware encoders have a minimum resolution; h264_nvenc is one. Zero probes at 640x480, for a caller who only wants to build a menu.

BackendLicense

static std::string BackendLicense()

The licence of the FFmpeg this SDK was linked against.

"LGPL version 3 or later" for a shippable build. Anything beginning "GPL" means the video backend was built with --enable-gpl -- which is what linking x264 or x265 requires -- and a proprietary product linking it could not be distributed.

Reports libavcodec only. That is the headline, and on its own it is not enough to clear a build: see BackendComponentLicenses().

Public because it is the one fact about the backend that changes what a caller is allowed to do with the result, and because the alternative to being able to ask is finding out from a lawyer. FfmpegLicence in the test suite fails the build over it.

BackendComponentLicenses

static std::vector< std::pair< std::string, std::string > > BackendComponentLicenses()

The licence of every FFmpeg library the SDK loads, by name.

Pairs of (library, licence): "avcodec", "avformat", "avutil", "swscale", "swresample".

Why this is not the same question as BackendLicense(). The five libraries are resolved independently by the dynamic loader, so a process can load an LGPL libavcodec on top of a GPL libavutil -- and avcodec_license() still answers "LGPL version 3 or later", because it reports the licence libavcodec was compiled with and knows nothing about its siblings. That is not hypothetical: it is what happens when the SDK carries its own LGPL FFmpeg under an ELF RUNPATH rather than an RPATH, because RUNPATH applies only to the object that declares it and is not inherited by libavcodec's own dependencies, which then resolve from the system path.

So the shippable condition is that all five report LGPL, and asking libavcodec alone is a check that cannot see the failure it exists to catch.

Public functions

~VideoExporter

~VideoExporter()

VideoExporter

VideoExporter(const VideoExporter &)=delete

operator=

VideoExporter & operator=(const VideoExporter &)=delete

WriteFrame

void WriteFrame(const optris::sdk::ThermalFrame &frame)

Encode and write a frame.

For FFV1: copies raw 16-bit data directly. For lossy codecs: splits each 16-bit pixel into MSB/LSB and packs into the Y plane of a double-height YUV420P frame, and in a Matroska file also writes the 16-bit data to the lossless track (see VideoContent::kRadiometric).

Parameters

Name Description
frame Thermal frame from the SDK.

Exceptions

Name Description
InvalidStateException if this exporter was configured for colorized pictures -- hand those to WritePicture().
InvalidArgumentException if the frame's dimensions are not the ones the exporter was opened at.
IoException when the file could not be written (a full drive, a removed one), and FileTooLargeException when the file system will not let it grow. Either is kept: every later write and Finish() throw the same, because the video is now missing a picture. A write after Finish() throws InvalidStateException.

WriteFrame

void WriteFrame(const optris::sdk::BgraFrame &frame)

Encode and write an already-colorized picture.

For VideoContent::kColorized only. The frame is converted from BGRA to the encoder's pixel format and written at its own size, with no bit packing: the result is an ordinary colour video.

Parameters

Name Description
frame The picture, as delivered by SetBgraCallback().

Exceptions

Name Description
InvalidStateException if the exporter was not configured for colorized content.
InvalidArgumentException if the dimensions do not match.
IoException when the file could not be written (a full drive, a removed one), and FileTooLargeException when the file system will not let it grow. Either is kept: every later write and Finish() throw the same, because the video is now missing a picture. A write after Finish() throws InvalidStateException.

WritePicture

void WritePicture(const uint8_t *bgra, size_t size_bytes, uint32_t width, uint32_t height, uint32_t stride, std::optional< uint64_t > timestamp_us)

Encode and write a picture the caller composed.

For VideoContent::kColorized only, like the overload above, and the one to use when the picture is not an SDK BgraFrame. An application that draws its regions, labels and readings over the SDK's picture has its own surface, and two things about such a surface are not expressible through BgraFrame:

  • its row stride. BgraFrame::GetStride() is width * 4 with no padding, while a GPU readback, a Windows DIB and a Cairo surface are all padded to an alignment. The other overload computes the stride from the configured width, so a padded buffer sheared.
  • when the picture belongs. A BgraFrame carries no time at all, so the only pacings available were counting frames -- which closes the gaps in a recording -- and arrival time, which follows however fast the replay is being fed. Exporting a recording wants neither: it wants the recording's own time per frame, which is the only one that keeps the video in step with what was recorded, gaps included.

Parameters

Name Description
bgra BGRA8 pixels, row-major, at least stride * height bytes.
size_bytes How many bytes bgra holds. Checked against stride * height before anything is read: every other argument describes the work rather than the memory.
width Must equal VideoExportConfig::width. A video stream has one frame size for its whole length, so this cannot vary per picture; it is validated rather than ignored.
height Must equal VideoExportConfig::height.
stride Row stride in bytes, or 0 for the tight width * 4. Below width * 4 is refused.
timestamp_us Presentation time in microseconds from the start of the video, or std::nullopt to use the pacing VideoExportConfig::pace_by_arrival selects.

Quantised to the stream's time base -- one VideoExportConfig::frame_rate period per unit -- so a gap shorter than one frame period closes. Timestamps must increase; one that does not is advanced to the next free slot, because a repeated timestamp is not a slightly wrong duration, it is a stream a demuxer may refuse.

Exceptions

Name Description
InvalidStateException if the exporter was configured for radiometric content.
InvalidArgumentException for a null pointer, a short buffer, a dimension mismatch or a stride below the row width.
IoException when the file could not be written (a full drive, a removed one), and FileTooLargeException when the file system will not let it grow. Either is kept: every later write and Finish() throw the same, because the video is now missing a picture. A write after Finish() throws InvalidStateException.

Finish

void Finish()

Flush encoder buffers and finalize the file.

Writes the container trailer. Called automatically by the destructor, which cannot say how that went; call this to find out.

Exceptions

Name Description
IoException or FileTooLargeException when the encoder's last pictures, the trailer or the close could not be written, or when an earlier write was refused. Either way the file is not a whole video. Calling it again throws the same.

EncoderName

std::string EncoderName() const

The encoder actually chosen, e.g. "h264_nvenc" or "mjpeg".

A codec names a format; several encoders may produce it, and which one ran decides the licence, the speed and where the work happened. Worth showing to anyone who asked for H.264 and wants to know whether they got the GPU or the CPU.

KeepsTemperatures

bool KeepsTemperatures() const

Whether this export keeps every temperature it is handed.

Added in 12.0.28.

True for a radiometric export through FFV1, and for one through a lossy codec into a Matroska file, which carries the frames on a lossless track as well (VideoContent::kRadiometric). False for a radiometric export through a lossy codec into an MP4, MOV or WebM file, whose packed picture does not give the temperatures back, and for a colorized export, which never had any.

Known once Create() has returned. Ask it before telling anyone the file is a radiometric one.