Skip to main content

Module webcodecs

Module webcodecs 

Source
Available on crate feature decode only.
Expand description

What a platform decoder needs from a Demuxed track that the container does not spell out: the browser’s WebCodecs VideoDecoder takes a codec string (avc1.640028, hvc1.1.6.L120.90, av01.0.08M.08, vp09.00.41.08) and the configuration record as its description, and each chunk marked key or delta.

All of it is read from the configuration record and the coded samples, so it is plain Rust, tested natively, and used by threers’s wasm player to hand the browser’s hardware decoder the same files the native decoders read.

use threers_codec::decode::{demux, webcodecs};

let track = demux(std::fs::read("clip.mp4").unwrap()).unwrap();
let codec = webcodecs::codec_string(&track).unwrap();
let first_is_key = webcodecs::is_keyframe(&track, 0);

Functions§

codec_string
The RFC 6381 / WebCodecs codec string for track, from its configuration record (or, for VP9 without one, its first frame). None when there is not enough to say: AV1 in IVF, a damaged record.
description
The description a WebCodecs VideoDecoder is configured with: the avcC or hvcC record for H.264 and HEVC, which arrive length-prefixed and need it; the av1C for AV1 where there is one; nothing for VP9.
is_keyframe
Whether sample i can be decoded on its own: an IDR picture (H.264), an IRAP one (HEVC), a key frame (VP9), or a temporal unit opening with a sequence header or a key frame (AV1). WebCodecs wants the first chunk after a configure or reset to be one, and a decoder can start at any.