decode only.Expand description
A video file’s pictures one at a time, in display order, for playback.
decode_video walks a whole file and calls back
with every picture, in decode order. A player wants the opposite: the next
picture to show, when it is due, and nothing held that is not needed. That
is VideoReader: open a file, call next_frame
for each picture in display order, and rewind to go
round again.
use threers_codec::decode::VideoReader;
let mut video = VideoReader::open(std::fs::read("clip.mp4").unwrap()).unwrap();
while let Some((seconds, frame)) = video.next_frame().unwrap() {
let rgba = frame.to_rgba();
let _ = (seconds, rgba);
}The containers are those decode_video reads:
MP4/MOV (H.264, HEVC, AV1), WebM/Matroska (VP9, AV1) and IVF (VP9, AV1).
An Annex B elementary stream has no timing and no index, so it is decoded
whole when opened and shown at 30 frames a second.
Pictures decode in hardware where the build and machine have it:
VideoToolbox on macOS (videotoolbox; H.264, HEVC, AV1 on M3 and later,
VP9), NVDEC on NVIDIA (nvidia) and VAAPI on Linux (vaapi), in that
order, with the native decoders behind them for anything the hardware will
not take. backend says which is in use;
open_software keeps to the native ones.
Display order comes from the container’s timestamps, which are all known before the first picture is decoded: a picture goes out as soon as every sample that could show earlier has been decoded. A stream with B-frames holds back only the pictures it reorders, not a fixed window.
Structs§
- Coded
Sample - One coded sample: where its bytes are, its timestamps, and when it shows.
- Demuxed
- A video track as a decoder is fed it: the codec and its configuration
record, and every coded sample in decode order with when it shows. What
VideoReaderreads, and what a platform decoder outside this crate (the browser’s WebCodecs, say) can be given instead; seewebcodecs. - Video
Reader - A video file, read a picture at a time in display order. See the module docs.
Functions§
- demux
- Demux MP4/MOV, WebM/Matroska or IVF held in memory. An Annex B stream has no container to demux and is refused.