---
title: "ClikaRT::io::VideoWriter"
sidebar_label: "VideoWriter"
description: "Encode a stream of channels-last RGB [H, W, 3] UInt8 frames to a video file, with an optional audio track. Move-only. Every fallible method raises ClikaRT::Error on failure."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/io/video.h`

Encode a stream of channels-last RGB `[H, W, 3]` UInt8 frames to a video file, with an optional audio track. Move-only. Every fallible method raises [`ClikaRT::Error`](../Error.md) on failure.

## Static member functions

### open(string\_view, string\_view, double, int, …) {#open}

<div class="api-signature">

`static` [`VideoWriter`](./VideoWriter.md) **`open`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::string_view` `path`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::string_view` `codec`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `fps`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int` `width`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int` `height`<br />
)

</div>

Open a writer to `path` producing `codec` at `fps` and `width`×`height`. An empty `codec` picks the first encoder the discovered set offers along a fixed preference list (h264, hevc, vp9, mpeg4) and logs the pick; a named codec is kept as given and fails when its encoder is absent, naming the encoders found. `path` / `codec` are copied.

<div class="api-declared">

Declared in `ClikaRT/io/video.h`, line 169

</div>

### open(string\_view, string\_view, double, int, …) {#open-2}

<div class="api-signature">

`static` [`VideoWriter`](./VideoWriter.md) **`open`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::string_view` `path`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::string_view` `codec`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `fps`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int` `width`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int` `height`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`const` [`AudioTrack`](./AudioTrack.md)`&` `audio`<br />
)

</div>

Open a writer to `path` producing `codec` at `fps` and `width`×`height`. An empty `codec` picks the first encoder the discovered set offers along a fixed preference list (h264, hevc, vp9, mpeg4) and logs the pick; a named codec is kept as given and fails when its encoder is absent, naming the encoders found. `path` / `codec` are copied.

<div class="api-declared">

Declared in `ClikaRT/io/video.h`, line 181

</div>

## Member functions

### VideoWriter() {#VideoWriter}

<div class="api-signature">

**`VideoWriter`**(`VideoWriter&&`) `noexcept`

</div>

<div class="api-declared">

Declared in `ClikaRT/io/video.h`, line 187

</div>

### operator=() {#operator-assign}

<div class="api-signature">

[`VideoWriter`](./VideoWriter.md)`&` **`operator=`**([`VideoWriter`](./VideoWriter.md)`&&`) `noexcept`

</div>

Move-assign: transfers the writer.

<div class="api-declared">

Declared in `ClikaRT/io/video.h`, line 189

</div>

### \~VideoWriter() {#VideoWriter-2}

<div class="api-signature">

**`~VideoWriter`**()

</div>

Finalizes the container if still open, then releases the writer.

<div class="api-declared">

Declared in `ClikaRT/io/video.h`, line 191

</div>

### write\_frame() {#write_frame}

<div class="api-signature">

`void` **`write_frame`**(`const` [`Tensor`](../Tensor.md)`&` `frame`)

</div>

Append one `[H, W, 3]` UInt8 frame (geometry must match the writer's). An undefined tensor is refused like any other frame the writer cannot take: a caller holding one after a lookup that missed gets an error, never a crash. A quantized frame is refused with `INVALID_ARGUMENT`: its codes are not pixel values, so dequantize it first ([`ops::dequantize`](../ops/dequantize.md#dequantize)).

<div class="api-declared">

Declared in `ClikaRT/io/video.h`, line 200

</div>

### write\_audio() {#write_audio}

<div class="api-signature">

`void` **`write_audio`**(`const` [`Tensor`](../Tensor.md)`&` `samples`)

</div>

Append interleaved audio samples to the track declared at [`open`](./VideoWriter.md#open): `[frames, channels]` (or `[frames]` for a mono track), a float dtype in \[-1, 1\] or Int16 PCM codes, on any device. The first call pins the PCM dtype the track is written at. Refused on a writer opened without a track, on a channel count other than the declared one, on a second dtype mid-track, and on quantized samples (their codes are not sample values, so dequantize them first with [`ops::dequantize`](../ops/dequantize.md#dequantize)); [`close`](./VideoWriter.md#close) refuses a declared track that received none.

<div class="api-declared">

Declared in `ClikaRT/io/video.h`, line 211

</div>

### close() {#close}

<div class="api-signature">

`void` **`close`**()

</div>

Finalize the file (also runs implicitly on destruction if not called).

<div class="api-declared">

Declared in `ClikaRT/io/video.h`, line 215

</div>
