Skip to main content

VideoWriter

Encodes a stream of [H, W, 3] uint8 RGB frames into a video file, with an optional audio track: open() names the file, the codec, the frame rate and the geometry; write_frame() appends one frame; close() finalizes the file (also run when the object is garbage collected, and by the with form on exit). The frames are copied as they are written and encoded at close.

__init__​

__init__(self, /, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

close​

closeclose(self) -> None

close(self) -> None

close() -> None

Encode the written frames (and the track's samples) into the file and finalize it. A declared track that received no samples is refused here. A second close() changes nothing.

open​

openopen(path: object, *, fps: float, width: int, height: int, codec: str = '', audio: clika_runtime._core.io.AudioTrack | None = None) -> clika_runtime._core.io.VideoWriter

open(path: object, *, fps: float, width: int, height: int, codec: str = '', audio: clika_runtime._core.io.AudioTrack | None = None) -> clika_runtime._core.io.VideoWriter

open(path, *, fps, width, height, codec='', audio=None) -> VideoWriter

Open a writer to path (a str or an os.PathLike; the suffix picks the container) producing width x height frames at fps. codec names the video codec; '' picks the first encoder the host offers along a fixed preference list (h264, hevc, vp9, mpeg4), and a named codec whose encoder is absent raises naming the encoders found. audio, an AudioTrack, declares a sound track whose samples arrive through write_audio(); a track with a sample rate that is not positive or no channel is refused here. Raises when no encode backend exists (video_capability() is False).

write_audio​

write_audiowrite_audio(self, samples: clika_runtime._core.Tensor) -> None

write_audio(self, samples: clika_runtime._core.Tensor) -> None

write_audio(samples) -> None

Append interleaved samples to the track declared at 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 sample dtype the track is written at. Raises InvalidArgumentError 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.

write_frame​

write_framewrite_frame(self, frame: clika_runtime._core.Tensor) -> None

write_frame(self, frame: clika_runtime._core.Tensor) -> None

write_frame(frame) -> None

Append one [H, W, 3] uint8 frame of the writer's geometry; the bytes are copied, the tensor is not retained. A frame of another shape or dtype, an undefined tensor or a quantized one (dequantize it first) raises InvalidArgumentError; a frame after close() raises with code_name FAILED_PRECONDITION.