Skip to main content

Module decode

Module decode 

Source
Expand description

Native video decoding for the command line, the Python module and desktop builds.

A Decoder yields every frame of a file’s first video track once, in presentation order, with the timestamp the container gives it. Screen recordings are variable frame rate, so nothing here resamples to a constant rate: a frame is never duplicated or dropped. Frames keep the decoder’s own 4:2:0 planes (PixelFormat) and coded orientation; VideoInfo::rotation says how to turn them for display, and the colour tags say how to read the planes, so an HDR (PQ or HLG) recording reaches the kernels’ converter with its signal untouched.

Backends: the system decoder on macOS (AVFoundation) and Windows (Media Foundation), and a user-installed ffmpeg/ffprobe run as a child process on every system. Linux has no single system decoder API, so it uses ffmpeg. ffmpeg is never linked or bundled; Error::ToolMissing says how to install it.

The driver reads videos through this module (VideoSource); use it directly when you only need the frames. It is an implementation layer like kernels and engine: its API may change in minor versions. Options and Backend are re-exported at the crate root as DecodeOptions and DecodeBackend.

use long_screen::decode::{open, Frame, Options};
use std::path::Path;

let mut decoder = open(Path::new("recording.mov"), &Options::default())?;
println!("{:?}", decoder.info());
let mut frame = Frame::default();
while decoder.read_frame(&mut frame)? {
    println!("frame {} at {:.3} s", frame.index, frame.timestamp);
}

Structs§

Colour
The stream’s colour tags. None means untagged.
Frame
One decoded frame.
Options
How to open a file.
Plane
One plane of a frame: byte offset of its first row in Frame::data and bytes between rows.
VideoInfo
What the file holds, as the chosen backend reads it.

Enums§

Backend
Which decoder reads the file.
Error
Why a file could not be read.
Matrix
The YUV matrix of the planes.
PixelFormat
How a frame’s bytes are laid out. Every format is 4:2:0 with chroma planes of ceil(w/2) × ceil(h/2) samples. 10-bit formats store each sample in a little-endian u16.
Primaries
The colour primaries.
Transfer
The transfer function the samples code.

Traits§

Decoder
Reads a file’s frames in presentation order.

Functions§

open
Opens path for decoding with options.backend.
probe
The file’s VideoInfo as options.backend would decode it, without decoding.