Skip to content

feat: encode H.265 and VP9 and decode VP9 with VA-API on Linux, when turned on - #352

Merged
devopvoid merged 3 commits into
mainfrom
feat/linux-vaapi-hevc-encoder
Oct 11, 2026
Merged

devopvoid merged 3 commits into
mainfrom
feat/linux-vaapi-hevc-encoder

Conversation

@devopvoid

Copy link
Copy Markdown
Owner

Stacked on #348.

Adds VA-API codecs beyond H.264 for the GPUs of Intel and AMD on Linux. None of them has run on such a GPU yet, so each is off by default:

Codec Direction Turned on by Without it, or on failure
H.265 Main Encode webrtc.hardware.vaapiExperimental Not offered (no software H.265); WebRTC switches to the next negotiated codec
VP9 profile 0 Encode webrtc.hardware.vp9Encoder (same switch as on Windows) libvpx
VP9 profile 0 Decode webrtc.hardware.vaapiExperimental libvpx

Encoders

  • VaapiH265Encoder and VaapiVp9Encoder: synchronous, one reference frame, inter frames only, the driver writing the headers. Parameters follow FFmpeg's VA-API encoders. H.265 takes the block sizes and coding tools the driver reports; the encode entrypoint is found per profile, since Intel often encodes H.265 with the low-power one only.
  • VaapiEncodeSession holds what both share: configuration, context, surfaces, frame upload, rate control, reading the output. The H.264 encoder is left as it is.

Decoder

  • VA-API leaves parsing to the application. Vp9FrameHeaderParser parses the uncompressed VP9 headers per the specification. It keeps the state that carries over between frames, and works out per-segment quantizer scales and loop filter levels with libvpx's quantizer lookup, which WebRTC already links.
  • VaapiVp9Decoder decodes into ten surfaces, splits superframes, and copies frames out as NV12. Other profiles, spatial layers, inter frames that change the size, and any failure go to libvpx.

Testing

  • Every VA-API source compiles against libva and the WebRTC headers on Debian 12 (WSL). WSL has no usable VA-API device, so CI is the first real build.
  • The parser's output matched FFmpeg's trace_headers field by field on 186 frames of libvpx streams: realtime with cyclic-refresh segmentation, altref superframes with tiles, error resilience, an odd size, lossless. The "show existing frame" path has not been exercised.
  • On Windows, HardwareVideoEncoderIntegrationTest and HardwareVideoDecoderIntegrationTest pass. A new test checks that H.265 key frames from any hardware encoder are whole access units, and the VP9 hardware encoder test now also runs on Linux.

@devopvoid
devopvoid force-pushed the feat/linux-vaapi-hevc-encoder branch from 483dc4c to 189614c Compare October 11, 2026 18:42
The VA-API encoder factory offers H.265 Main as well, where the driver
encodes it (Intel, AMD), but only with the system property
webrtc.hardware.vaapiExperimental set: it has not run on such a GPU yet.
Without it, VA-API encodes H.264 alone, as before.

VaapiH265Encoder works as the H.264 one does: synchronous, one reference
frame, P-frames only, the driver writing the parameter sets and slice
headers. It takes the block sizes and coding tools the driver says it
takes (VAConfigAttribEncHEVCBlockSizes and Features), as FFmpeg's VA-API
encoder does, and FFmpeg's defaults where the driver says nothing. The
frame size is kept to whole coding blocks, so the coded picture needs no
cropping. The encode entrypoint is found per profile, since Intel drivers
often encode H.265 with the low-power one only. There is no software H.265
to fall back to: a failure is an error, upon which WebRTC switches to the
next negotiated codec. The H.264 encoder is left as it is.

The property is read like the VP9 one, through a shared reader. A new
test sends H.265 from whichever hardware encoder there is to a Java
decoder that checks every key frame is a whole access unit, so that an
encoder can be tested on a GPU that does not decode H.265.
The VA-API encoder factory offers VP9 profile 0 where the driver encodes
it (Intel), with the same switch as hardware VP9 encoding on Windows, the
system property webrtc.hardware.vp9Encoder: it has not run on such a GPU
yet. Without it, or where the driver has no VP9 encoder, libvpx encodes
VP9 as before, and takes over from a hardware encoder that fails.

VaapiVp9Encoder works as the H.265 one does: synchronous, one reference
frame, inter frames only, the driver writing the frame header. Its
parameters follow FFmpeg's VA-API VP9 encoder without B-frames: surfaces
aligned to 64, key frames only where asked for, every frame refreshing
all reference slots and the next one referring to slot 0 as its last
frame. The output goes through EncoderOutputProcessor like that of the
Windows VP9 encoder.

What the H.265 and VP9 encoders share, the configuration, context and
surfaces, uploading frames, the parameter buffers, rate control and
reading the output, moves into VaapiEncodeSession; the H.264 encoder
keeps its own copy. The VP9 hardware test runs on Linux too.
The hardware decoder factory decodes VP9 profile 0 with VA-API on the
GPUs of Intel and AMD, after NVDEC, where the driver decodes it, but only
with the system property webrtc.hardware.vaapiExperimental set: it has
not run on such a GPU yet.

VA-API leaves parsing to the application. Vp9FrameHeaderParser parses
the uncompressed headers per the VP9 specification, keeping the loop
filter deltas, segmentation and reference sizes that carry over, and
works out the quantizer scales and loop filter levels of each segment
with libvpx's quantizer lookup, which WebRTC links. Its output matched
FFmpeg's trace_headers on 186 frames of libvpx streams with hidden
frames, error resilience, segmentation, tiles, an odd size and lossless.

VaapiVp9Decoder decodes synchronously into ten surfaces, eight reference
slots and the frame being decoded, splits superframes, and copies frames
out as NV12. Profiles other than 0, spatial layers, inter frames that
change the size and any failure go to libvpx.
@devopvoid
devopvoid force-pushed the feat/linux-vaapi-hevc-encoder branch from 189614c to 8157048 Compare October 11, 2026 20:22
@devopvoid
devopvoid changed the base branch from feat/windows-hevc-codecs to main October 11, 2026 20:22
@devopvoid
devopvoid merged commit 368afbd into main Oct 11, 2026
1 check passed
@devopvoid
devopvoid deleted the feat/linux-vaapi-hevc-encoder branch October 11, 2026 20:49
SendableMetatype added a commit to EduGeyser/webrtc-java that referenced this pull request Oct 15, 2026
Brings in the work upstream added from October 11 to 15: hardware video
codecs on every platform, through Media Foundation, VideoToolbox, VA-API
and NVDEC, with WebRTC built with H.265 (devopvoid#346 to devopvoid#348, devopvoid#352, devopvoid#353, devopvoid#356,
devopvoid#359, devopvoid#371 to devopvoid#377); HEVC and AV1 decoding in the media player, with
dav1d and Vulkan Video (devopvoid#331, devopvoid#345); encoded frame injectors (devopvoid#365);
receiver source changes and audio packet infos (devopvoid#366); audio codec
factories (devopvoid#340); network thread observers called on a callback thread
(devopvoid#364); screen capture with ScreenCaptureKit (devopvoid#354); Windows audio
devices that mix more than two channels (devopvoid#358); autoninja (devopvoid#357); and
the release channels of the docs site (devopvoid#361).

Fork-side adaptations:
- The factory keeps the CreatePeerConnectionFactory overload without a
  worker thread, and still switches device capture on the network
  thread. devopvoid#355 copies WebRTC's factory setup and has the audio module
  learn a worker thread, which only matters for a worker thread distinct
  from the network thread, and WebRTC is removing those. The audio codec
  factories and hardware codec switches of devopvoid#340 and devopvoid#359 go to that
  overload.
- WebRTC stays on a commit on main, so the move to branch 8059 (devopvoid#360)
  and its fixed clang package are left out.
- The data channels variant builds WebRTC without H.265 and without the
  extra targets, leaves out the audio codec factory bindings and
  addTransceiverOfType, and skips the new tests that need audio or
  video.
- dav1d is built against the sysroot on native Linux builds as well, as
  FFmpeg is. CI installs Meson for the full variant only, checks out the
  dav1d submodule, and adds its commit to the FFmpeg cache key. The
  fork's Windows SDK step stays, without upstream's second one.
- The release workflow records the docs' version in the tagged commit,
  as upstream's now does. The docs site still builds from main, since
  this fork publishes none.
- The Maven files stay deleted: Jetty is bumped in the version catalog,
  and the docs lockfile takes upstream's bumps on top of the fork's
  newer VitePress.
- The media module's README builds with Gradle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant