Add CUDA/NVIDIA support in image - #440
Conversation
biglittlebigben
left a comment
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
Please remove options that are not supported yet
| } | ||
|
|
||
| if c.VideoEncoderBackend == "" { | ||
| c.VideoEncoderBackend = EncoderBackendAuto |
There was a problem hiding this comment.
We should default to software, at least for now.
| if nvh264EncoderAvailable() { | ||
| resolved = config.EncoderBackendNVENC | ||
| } else { | ||
| log.Warnw("nvenc video encoder requested but nvh264enc is unavailable, falling back to software", nil) |
There was a problem hiding this comment.
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.
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_backendconfig 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/videoscaleand decode remain onCPU); the NVENC element uploads internally. No GStreamer rebuild is required —
the
nvcodecplugin (nvh264enc) is already present in thelivekit/gstreamerbase image; only the NVIDIA container runtime is needed.How it works
video_encoder_backend: auto | software | nvenc | vaapi(defaultauto).autoprobes fornvh264enconce at startup. If available, H.264 layers useNVENC; otherwise they use
x264encexactly as before.backend"). If
nvencis requested but unavailable, it logs a warning andfalls back to software.
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 againstgst-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