Skip to content

Add CUDA/NVIDIA support in image - #440

Open
tormodhope wants to merge 1 commit into
livekit:mainfrom
tormodhope:gpu-support
Open

Add CUDA/NVIDIA support in image#440
tormodhope wants to merge 1 commit into
livekit:mainfrom
tormodhope:gpu-support

Conversation

@tormodhope

Copy link
Copy Markdown

Summary

Adds an optional hardware H.264 video encoder (NVIDIA NVENC) to the transcode
pipeline. The encoder is selected per node via a new video_encoder_backend
config option, with automatic detection and a transparent fallback to the
existing software path.

Only the H.264 encode is moved to the GPU.
Frames stay in system memory (videoconvert/videoscale and decode remain on
CPU); the NVENC element uploads internally. No GStreamer rebuild is required —
the nvcodec plugin (nvh264enc) is already present in the
livekit/gstreamer base image; only the NVIDIA container runtime is needed.

How it works

  • New video_encoder_backend: auto | software | nvenc | vaapi (default auto).
  • auto probes for nvh264enc once at startup. If available, H.264 layers use
    NVENC; otherwise they use x264enc exactly as before.
  • Selection is resolved per ingress and logged ("resolved video encoder
    backend"). If nvenc is requested but unavailable, it logs a warning and
    falls back to software.
  • VP8 and audio are unchanged (NVENC has no VP8 path). Output is identical:
    H.264 baseline byte-stream simulcast — the room/SFU and clients see no
    difference.

NVENC is configured for real-time WebRTC: rc-mode=cbr,
preset=low-latency-hq, tune=ultra-low-latency, bframes=0,
zerolatency=true (verified against gst-inspect-1.0 nvh264enc, GStreamer 1.26).

Configuration

node-level; GPU is a property of the node, not the ingress

video_encoder_backend: auto # auto | software | nvenc | vaapi

@tormodhope
tormodhope requested a review from a team as a code owner June 15, 2026 20:41
@CLAassistant

CLAassistant commented Jun 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@biglittlebigben biglittlebigben left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch! A few comments. Please also update the README to indicate how to setup NVENC based encoding, particularly in a docker and kubernetes environment.

Comment thread build/ingress/Dockerfile
# capability is required for NVENC and is NOT part of the runtime default
# (compute,utility), so set it explicitly. These are no-ops without the NVIDIA
# runtime, so the image still runs CPU-only elsewhere.
ENV NVIDIA_DRIVER_CAPABILITIES=compute,video,utility

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be opt in, at least for now: setting the docker container to support nvenc should be gated behind a parameter passed in on container start.

Comment thread pkg/config/config.go
EncoderBackendAuto EncoderBackend = "auto" // use a hardware encoder if available, else software
EncoderBackendSoftware EncoderBackend = "software" // x264enc / vp8enc
EncoderBackendNVENC EncoderBackend = "nvenc" // NVIDIA NVENC (nvh264enc)
EncoderBackendVAAPI EncoderBackend = "vaapi" // VA-API (not yet implemented)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove options that are not supported yet

Comment thread pkg/config/config.go
}

if c.VideoEncoderBackend == "" {
c.VideoEncoderBackend = EncoderBackendAuto

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should default to software, at least for now.

Comment thread pkg/media/output.go
if nvh264EncoderAvailable() {
resolved = config.EncoderBackendNVENC
} else {
log.Warnw("nvenc video encoder requested but nvh264enc is unavailable, falling back to software", nil)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the encoder backend is set to NVENC, we should call nvh264EncoderAvailable on startup and fail to start the service if we fail to initialize NVENC.

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.

3 participants