Skip to content
re2zeroPublic

About

A hardware-first, software-fallback H.264/HEVC/VP9/AV1 codec library for Linux.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ucodec

简体中文 · English

A hardware-first, software-fallback H.264/HEVC/VP8/VP9/AV1 codec library for Linux. Pure C++17 with a C11 public API, CMake build, deb packaging.

Release history: debian/changelog. Repository state: main tracks origin/main.

License

Licensed under the GNU Lesser General Public License, version 3 or later (LGPL-3.0-or-later):

Every source file carries an SPDX header. src/parse/ is implemented from the published bitstream specifications; the clause map, process limitation and project-owner acceptance are in docs/PROVENANCE.md.

Binary licensing reality (not legal advice): the core libucodec shared object is LGPL-3.0-or-later and has no link-time dependency on x264/x265. The GPL-2+ x264/x265 encoders live in the separate ucodec-26x plugin package, which the core dlopens only when it is installed. Loading that plugin makes the combined process GPL-3.0-or-later; without it, H.264/HEVC software encode refuses honestly with UNSUPPORTED. See Compliance.

Architecture

architecture

Capability surface

Application Reuses Not in the library
Remote desktop — controlled end encoding (RAM / DMA-BUF input, low latency) ACK backpressure, QoS, networking
Remote desktop — controller end decoding + EGL rendering same
Screen recorder encoding (continuous, B-frames) muxing, UI, resolution negotiation
Player / media app decoding + EGL render subset demuxing, clock, seek, A/V sync

The fallback chain is explicit and always reported: ucodec_probe verifies capabilities once per process (per DRM node vaInitialize + trial encode/decode), sessions walk each codec's ordered chain (VA-API → NVENC → SW where offered) with every hop recorded in get_path_reason() — no silent degradation. ucodec_probe_nodes() exposes every node's own codec trial matrix, and ucodec_enc_config.render_node / ucodec_dec_config.render_node pin a session to one VAAPI node (empty = automatic best node for that codec; an explicit unusable node is reported, never silently replaced).

Current codec matrix

Codec Encode Decode
H.264 VAAPI 8-bit, NVENC 8-bit, x264 8-bit (GPL plugin) VAAPI 8-bit progressive, NVDEC 8/10-bit, OpenH264 8-bit
HEVC VAAPI Main/Main10 8/10-bit, NVENC 8/10-bit, x265 8/10-bit (GPL plugin) VAAPI Main/Main10 8/10-bit, NVDEC 8/10-bit, libde265 8/10-bit
VP9 libvpx Profile0/2 8/10-bit (no NVENC VP9 encode) VAAPI P0 8-bit / P2 10-bit, NVDEC 8/10-bit, libvpx 8/10-bit
VP8 libvpx 8-bit libvpx 8-bit
AV1 NVENC 8/10-bit, SVT-AV1 8/10-bit NVDEC 8/10-bit, dav1d 8/10-bit

Not supported: H.264 10-bit, 12-bit, 4:2:2/4:4:4, interlaced, VP9 P1/P3, AV1 P1/P2, VA-API VP9/AV1 encode, VA-API AV1 decode. VP8 is software-only: no direct VA-API/NVDEC VP8 engine is claimed, so its capability bits stay 0; VP8 has no in-band colour description and only 8-bit 4:2:0 exists by definition. 10-bit encode is served by x265/SVT-AV1 (software), libvpx (VP9 Profile 2), VAAPI (HEVC Main 10) and NVENC (HEVC Main 10 / AV1 where the driver has a 10-bit encoder); a driver without one answers UNSUPPORTED and the chain continues. Open capability gaps (hardware / upstream / distro) are tracked in docs/TECH-DEBT.md and summarized under Open items; API-level limitations are listed in docs/API.md.

Tech stack & portability

  • Language: C++17 internals / C11 public headers
  • Build: CMake, component install, standard Debian packaging (below)
  • No FFmpeg / libavcodec / libavformat / libavutil dependency. Every chain slot is a direct engine:
    • VA-API VLD decode for H.264 / HEVC / VP9 and direct VA encode for H.264 / HEVC (src/hw/va/);
    • NVENC / NVDEC through the driver SDK, dlopened at runtime (optional build, src/hw/nv/);
    • upstream software engines: SVT-AV1 encode, OpenH264 / libde265 decode, libvpx VP8/VP9 encode+decode, dav1d AV1 decode (src/sw/); x264 / x265 encode in the separate GPL plugin (src/plugin/), loaded at runtime when ucodec-26x is installed. The core library links those non-GPL codec libraries directly; only libva / libdrm / EGL / GLESv2 stay out of the public headers.
  • Capabilities are claimed only where a direct engine exists. VA-API VP9 / AV1 encode and VA-API AV1 decode are not offered; the chain falls through to NVENC / software and the probe reports the capability as 0.
  • libva / libdrm / EGL / GLESv2: runtime dynamic linking; nothing leaks into the public headers
  • NVENC/NVDEC: optional build (-DUCODEC_ENABLE_NVENC=ON), drivers dlopened at runtime — no hard deb dependency, honest refusal on driver-less machines

Compliance summary (engineering view, not legal advice)

Area Status
This library (first-party code) LGPL-3.0-or-later
Dependency licenses libva / libdrm: MIT. libvpx / dav1d / OpenH264 / SVT-AV1: BSD-style. libde265: LGPL-3+. x264 / x265 are GPL-2+ and are only linked by the separate ucodec-26x plugin; the core libucodec has no link-time dependency on them.
LGPL build Available now. The core builds and installs without x264/x265 (-DUCODEC_BUILD_26X_PLUGIN=OFF, tests off); readelf -d libucodec.so has no x264/x265 NEEDED entry. The GPL encoders are opt-in via the ucodec-26x package.
Plugin ABI src/engine/plugin_api.h (ABI v1, symbol ucodec_plugin_entries_v1). The loader scans UCODEC_PLUGIN_PATH, $XDG_DATA_HOME/ucodec/plugins (or ~/.local/share/ucodec/plugins), <libdir>/ucodec/plugins and the build-tree plugins/ directory; a missing or ABI-mismatched plugin is skipped, and the x264/x265 rows refuse with UNSUPPORTED + a reason. ucodec_plugin_query() reports the package/module to download, ucodec_plugin_rescan() picks up a newly installed plugin, and ucodec_plugin_set_missing_cb() notifies the app. The library never performs network I/O. Loading a GPL plugin makes the combined process GPL-3.0-or-later.
Provenance src/parse/ is a specification-based implementation (ITU-T H.264/H.265, the VP9 Bitstream & Decoding Process Specification, ISO/IEC 14496-15); the current sources contain no FFmpeg source. The per-file clause map, table provenance and verification evidence are in docs/PROVENANCE.md. The project owner accepted this provenance on 2026-11-28; the process limitation is documented there.
Patent pools H.264: moderate (single pool, ~$0.20/unit with the first 100k units/year free, core patents expiring). HEVC: high (three stacked pools, no free-content exemption — do FTO before commercial shipping). AV1: royalty-free pool (AOMedia). MP4 container: low (MPEG-4 Systems patents largely expired — and the library ships no muxer at all).
debs every binary package ships /usr/share/doc/<pkg>/copyright

Build & verify

cmake -B build && cmake --build build -j
cd build && ctest        # 38 tests with GBM/EGL available; hardware legs SKIP honestly

Gates: default / NVENC+Werror / ASan builds (test count follows the build shape); soak long-run stability (fd/RSS drift, double-gated); perf gate 1080p ≥ 60 FPS; ABI export surface (abi_exports); libFuzzer smoke for the five parser targets (-DUCODEC_BUILD_FUZZERS=ON, clang; see docs/TESTING.md §4.6). CI jobs live in .github/workflows/ci.yml (hosted runners) and hardware.yml (self-hosted ucodec-hw runner). On NVENC/NVDEC machines run GPU/soak tests serially; -jN can trigger the known NVDEC init latch. See docs/TESTING.md.

Packaging (debs)

Standard Debian packaging (debhelper / dpkg):

dpkg-buildpackage -us -uc -b
# -> libucodec0 / libucodec-dev .debs next to the source tree

Packages: libucodec0 (runtime: libucodec.so, the zero-copy libucodec-egl.so helper and the ucodec-probe CLI) · libucodec-dev (headers + CMake find_package(ucodec) config with imported targets + pkg-config files) · ucodec-26x (optional GPL x264/x265 plugin, installed under /usr/lib/<triplet>/ucodec/plugins/; a user-local copy under $XDG_DATA_HOME/ucodec/plugins is also discovered). libucodec0 only Suggests the plugin, so a default install stays LGPL. Future companions follow the same ucodec-<family> package / libucodec-<family>.so module pattern; the loader scans the plugin directory, so no core change is needed. The EGL helper stays a separate .so — the core library does not link EGL/GLESv2 — and ships in the same runtime package. Plain C consumers can build with cc app.c $(pkg-config --cflags --libs ucodec); the shared libraries export only the public C surface (hidden visibility + linker version script).

Package names follow the SONAME major: current major is 0, so the runtime package is libucodec0. A future major bump is a deliberate release decision and requires the corresponding Debian rename; this tree does not pre-announce a 1.x package name.

Post-build checks (no root needed) plus the installed-package smoke suite:

tests/packaging/check_debs.sh ..   # dpkg-deb/readelf/nm content gate
autopkgtest ../libucodec0_*.deb ../libucodec-dev_*.deb \
    ../ucodec-26x_*.deb . -- null  # core-smoke + plugin-smoke

core-smoke installs the runtime without the plugin, round-trips VP9 and asserts H.264/HEVC software encode is honestly UNSUPPORTED; plugin-smoke installs ucodec-26x, checks discovery through the installed <libdir>/ucodec/plugins layout and round-trips H.264/HEVC. See docs/PACKAGING.md for the package/licence boundary, dependency rules and the full gate.

Open items (not done)

These gaps are tracked in docs/TECH-DEBT.md. None has a placeholder implementation: the probe reports the capability as 0 and the session chain either falls through to the next real engine or refuses with UNSUPPORTED.

ID Item Blocked by Current behavior
TD-01 VA-API VP9 encode Hardware: Intel Gen11+ (Ice Lake/Tiger Lake or newer) or AMD VCN exposing VAProfileVP9Profile0 + VAEntrypointEncSlice vp9 encode falls through to libvpx (NVENC has no VP9 encoder under SDK 12.1)
TD-02 VA-API AV1 encode Hardware: Intel DG2/Arc or AMD RDNA3+ (VCN4) exposing VAProfileAV1Profile0 + VAEntrypointEncSlice av1 encode falls through to SVT-AV1
TD-03 VA-API AV1 decode Hardware: Intel DG2/Arc or AMD RDNA2+ (VCN3) exposing VAProfileAV1Profile0 + VAEntrypointVLD av1 decode falls through to dav1d
TD-05 12-bit / 4:2:2 / 4:4:4 public format surface Hardware with those codec units + distributable test content; public-format decision first Out-of-contract shapes answer UNSUPPORTED (the RTX 5090's AV1 4:4:4 encoder was measured UNSUPPORTED)
TD-06 I010-only VA-API driver delivery A VA-API driver exposing only I010 surfaces has not appeared in the fleet Direct VA decode delivers P010; no evidence to add an I010 branch
TD-28 libde265 ignores pic_output_flag Upstream bug, still present in libde265 1.1.3 (66 output frames vs the 49 flagged pictures) Cross-validation compares by pts and pins 49; de265's output set is not treated as authoritative
TD-33 OpenH264 decode threads Upstream threaded output is non-deterministic (2.7.0: 2/4 threads differ across runs and from single-thread) Decoding runs on the calling thread; ucodec_decoder_set_threads returns UNSUPPORTED
TD-35 libde265 1.0.16 uninitialized-heap read Fixed upstream in 1.1.3; the current distro candidate is still 1.0.16 Software HEVC output remains constrained until the distro upgrade; tests pin HeapFillScope

NVIDIA hardware does not close the VA-API rows: the RTX 5090 fleet machine exposes no VA-API. Its AV1 8/10-bit encode/decode and VP9 decode are already verified (TD-04/TD-31/TD-32 closed); NVENC has no VP9 encoder under SDK 12.1.

Known limitations (current)

  • 10-bit encode is served by x265 / SVT-AV1 (software), libvpx (VP9 Profile 2), VAAPI (HEVC Main 10) and NVENC (HEVC Main 10 / AV1 where the driver exposes a 10-bit encoder). H.264 10-bit / 12-bit / 4:2:2 / 4:4:4 / interlaced decode are outside the current contract.
  • NVDEC DMA-BUF output is built on a linear GBM buffer mapped into CUDA through EGL (desktop NVIDIA cannot export CUDA memory as a dma-buf; CU_DEVICE_ATTRIBUTE_DMA_BUF_SUPPORTED is 0). The decoded surface is copied GPU-to-GPU, never through host memory. Builds without libgbm answer UNSUPPORTED honestly. Mid-stream resolution changes are not supported on NVDEC.
  • Decoder PTS follows the display position; the multi-frame packet rules (VP9 superframes/show_existing, dav1d multi-TU, B-frame reorder) are pinned by tests — see API.md "PTS semantics".
  • Encoder runtime fallback rebuilds a failed hardware session on the software engine of the same codec row (once per session, the undelivered picture is re-submitted so it is never lost, the next picture is a keyframe, dts stays strictly increasing; frames still buffered in the failed session are lost and the stream has a discontinuity - see API.md). DMA-BUF input sessions never fall back. Keyframe requests (ucodec_encoder_request_keyframe) and dynamic bitrate retargeting (ucodec_encoder_set_bitrate, in-place or via an internal session restart per engine) are available; framerate/RC-mode reconfiguration is not. Colour metadata (ucodec_encoder_set_color_info / ucodec_decoder_get_color_info) covers the SDR triple/range on every encoder except VP8 (whose colour lives in the container) and HDR10 static metadata (mastering display + content light level) on x265, SVT-AV1 and VAAPI H.264/HEVC; x264, libvpx VP8/VP9 and NVENC under SDK 12.1 answer UNSUPPORTED for descriptions they cannot carry (see API.md).
  • Per-session thread budgets and rate control are available: ucodec_encoder_set_sw_tuning (preset / threads / lookahead / bframes / vbv_ms on x264, x265 and libvpx VP8/VP9; preset / threads on SVT-AV1) and ucodec_decoder_set_threads (libde265, dav1d, libvpx), both before the first picture/packet. A budget is an upper bound and never changes the decoded pictures. Low-latency software sessions are constant bitrate (a one-second VBV: libvpx and SVT-AV1 have native CBR, x264/x265 use their ABR+VBV CBR shape), recording sessions stay VBR/ABR with an optional vbv_ms bound; SVT-AV1 1.7 has no VBV knob. The software recording profile is memory-bounded by default (x264/x265 frame threads follow a frame-pool budget; SVT-AV1 gets at most 4 logical processors and runs enc_mode 9 by default: 53-62 fps / 1.4-1.5 GB at 1080p, enough for real-time 1080p30; 4K stays below real time on software). OpenH264 and hardware sessions have no decoder thread knob (UNSUPPORTED); dav1d's default frame threads buffer a few pictures, so pass 1 for the lowest decode latency (see API.md).
  • The core library is LGPL-3.0-or-later and links no x264/x265. H.264/HEVC software encode requires the optional GPL ucodec-26x plugin; without it those chain rows answer UNSUPPORTED with a reason naming the package. Loading the plugin makes the combined process GPL-3.0-or-later.
  • src/parse/ is a specification-based reimplementation (P0-5/TD-36); see docs/PROVENANCE.md for the clause map, process caveat and acceptance record.

Documents

  • DESIGN — current architecture & invariants
  • DESIGN-ENGINES — current direct-engine contract
  • TECH-DEBT — open capability debt (hardware / upstream)
  • API — public API semantics & known limitations
  • TESTING — current test matrix, boundary checklist, gates
  • PROVENANCE — parse-layer spec clause map, table provenance and clean-room caveat
  • PACKAGING — deb layout, licence/dependency boundary, package gate and autopkgtest smoke

About

A hardware-first, software-fallback H.264/HEVC/VP9/AV1 codec library for Linux.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages