feat: update video encoding to use nvautogpuh264enc for NVIDIA driver 590+ support. (#667)

This commit is contained in:
Miroslav Šedivý
2026-07-31 14:28:19 +02:00
committed by GitHub
parent baf6eee8a9
commit e6239d6a51
4 changed files with 33 additions and 8 deletions
+7 -1
View File
@@ -162,7 +162,13 @@ func NewVideoPipeline(rtpCodec codec.RTPCodec, display string, pipelineSrc strin
return "", err return "", err
} }
pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! nvh264enc name=encoder preset=2 gop-size=25 spatial-aq=true temporal-aq=true bitrate=%d vbv-buffer-size=%d rc-mode=6 ! h264parse config-interval=-1 ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline"+pipelineStr, display, fps, bitrate, vbvbuf) // nvautogpuh264enc (GStreamer 1.22+) works better with NVIDIA drivers 590+; fall back to nvh264enc for older setups
nvencElem := "nvh264enc"
if err := gst.CheckElement("nvautogpuh264enc"); err == nil {
nvencElem = "nvautogpuh264enc"
}
pipelineStr = fmt.Sprintf(videoSrc+"video/x-raw,format=NV12 ! %s name=encoder preset=2 gop-size=25 spatial-aq=true temporal-aq=true bitrate=%d vbv-buffer-size=%d rc-mode=6 ! h264parse config-interval=-1 ! video/x-h264,stream-format=byte-stream,profile=constrained-baseline"+pipelineStr, display, fps, nvencElem, bitrate, vbvbuf)
default: default:
// https://gstreamer.freedesktop.org/documentation/openh264/openh264enc.html?gi-language=c#openh264enc // https://gstreamer.freedesktop.org/documentation/openh264/openh264enc.html?gi-language=c#openh264enc
// gstreamer1.0-plugins-bad // gstreamer1.0-plugins-bad
+11
View File
@@ -199,6 +199,17 @@ func CheckPlugins(plugins []string) error {
return nil return nil
} }
func CheckElement(element string) error {
elementcstr := C.CString(element)
factory := C.gst_element_factory_find(elementcstr)
C.free(unsafe.Pointer(elementcstr))
if factory == nil {
return fmt.Errorf("required gstreamer element %s not found", element)
}
C.gst_object_unref(C.gpointer(factory))
return nil
}
//export goHandlePipelineBuffer //export goHandlePipelineBuffer
func goHandlePipelineBuffer(pipelineID C.int, buf C.gpointer, bufLen C.int, duration C.guint64, deltaUnit C.gboolean) { func goHandlePipelineBuffer(pipelineID C.int, buf C.gpointer, bufLen C.int, duration C.guint64, deltaUnit C.gboolean) {
defer C.g_free(buf) defer C.g_free(buf)
+9 -5
View File
@@ -263,7 +263,7 @@ See documentation for [ximagesrc](https://gstreamer.freedesktop.org/documentatio
ximagesrc display-name={display} show-pointer=true use-damage=false ximagesrc display-name={display} show-pointer=true use-damage=false
! videoconvert ! queue ! videoconvert ! queue
! video/x-raw,format=NV12 ! video/x-raw,format=NV12
! nvh264enc ! nvautogpuh264enc
name=encoder name=encoder
preset=2 preset=2
gop-size=25 gop-size=25
@@ -290,7 +290,7 @@ See documentation for [ximagesrc](https://gstreamer.freedesktop.org/documentatio
ximagesrc display-name={display} show-pointer=true use-damage=false ximagesrc display-name={display} show-pointer=true use-damage=false
! cudaupload ! cudaconvert ! queue ! cudaupload ! cudaconvert ! queue
! video/x-raw(memory:CUDAMemory),format=NV12 ! video/x-raw(memory:CUDAMemory),format=NV12
! nvh264enc ! nvautogpuh264enc
name=encoder name=encoder
preset=2 preset=2
gop-size=25 gop-size=25
@@ -306,6 +306,10 @@ See documentation for [ximagesrc](https://gstreamer.freedesktop.org/documentatio
This configuration requires [Nvidia GPU](https://developer.nvidia.com/cuda-gpus) with [NVENC](https://developer.nvidia.com/nvidia-video-codec-sdk) support and [Cuda](https://developer.nvidia.com/cuda-zone) support. This configuration requires [Nvidia GPU](https://developer.nvidia.com/cuda-gpus) with [NVENC](https://developer.nvidia.com/nvidia-video-codec-sdk) support and [Cuda](https://developer.nvidia.com/cuda-zone) support.
:::tip
`nvautogpuh264enc` (GStreamer 1.22+) is the recommended encoder for NVIDIA driver 590 and newer. It auto-selects the correct memory path and replaces the older `nvh264enc`. On older GStreamer or driver versions, substitute `nvautogpuh264enc` with `nvh264enc`.
:::
</TabItem> </TabItem>
</Tabs> </Tabs>
@@ -318,7 +322,7 @@ Overview of available encoders for each codec is shown in the table below. The e
| VP8 | [vp8enc](https://gstreamer.freedesktop.org/documentation/vpx/vp8enc.html?gi-language=c) | [vaapivp8enc](https://github.com/GStreamer/gstreamer-vaapi/blob/master/gst/vaapi/gstvaapiencode_vp8.c) | ? | | VP8 | [vp8enc](https://gstreamer.freedesktop.org/documentation/vpx/vp8enc.html?gi-language=c) | [vaapivp8enc](https://github.com/GStreamer/gstreamer-vaapi/blob/master/gst/vaapi/gstvaapiencode_vp8.c) | ? |
| VP9 | [vp9enc](https://gstreamer.freedesktop.org/documentation/vpx/vp9enc.html?gi-language=c) | [vaapivp9enc](https://github.com/GStreamer/gstreamer-vaapi/blob/master/gst/vaapi/gstvaapiencode_vp9.c) | ? | | VP9 | [vp9enc](https://gstreamer.freedesktop.org/documentation/vpx/vp9enc.html?gi-language=c) | [vaapivp9enc](https://github.com/GStreamer/gstreamer-vaapi/blob/master/gst/vaapi/gstvaapiencode_vp9.c) | ? |
| AV1 | [av1enc](https://gstreamer.freedesktop.org/documentation/aom/av1enc.html?gi-language=c) | ? | [nvav1enc](https://gstreamer.freedesktop.org/documentation/nvcodec/nvav1enc.html?gi-language=c) | | AV1 | [av1enc](https://gstreamer.freedesktop.org/documentation/aom/av1enc.html?gi-language=c) | ? | [nvav1enc](https://gstreamer.freedesktop.org/documentation/nvcodec/nvav1enc.html?gi-language=c) |
| H264 | [x264enc](https://gstreamer.freedesktop.org/documentation/x264/index.html?gi-language=c) | [vaapih264enc](https://gstreamer.freedesktop.org/documentation/vaapi/vaapih264enc.html?gi-language=c) | [nvh264enc](https://gstreamer.freedesktop.org/documentation/nvcodec/nvh264enc.html?gi-language=c) | | H264 | [x264enc](https://gstreamer.freedesktop.org/documentation/x264/index.html?gi-language=c) | [vaapih264enc](https://gstreamer.freedesktop.org/documentation/vaapi/vaapih264enc.html?gi-language=c) | [nvautogpuh264enc](https://gstreamer.freedesktop.org/documentation/nvcodec/nvautogpuh264enc.html?gi-language=c) / [nvh264enc](https://gstreamer.freedesktop.org/documentation/nvcodec/nvh264enc.html?gi-language=c) |
| H265 | [x265enc](https://gstreamer.freedesktop.org/documentation/x265/index.html?gi-language=c) | [vaapih265enc](https://gstreamer.freedesktop.org/documentation/vaapi/vaapih265enc.html?gi-language=c) | [nvh265enc](https://gstreamer.freedesktop.org/documentation/nvcodec/nvh265enc.html?gi-language=c) | | H265 | [x265enc](https://gstreamer.freedesktop.org/documentation/x265/index.html?gi-language=c) | [vaapih265enc](https://gstreamer.freedesktop.org/documentation/vaapi/vaapih265enc.html?gi-language=c) | [nvh265enc](https://gstreamer.freedesktop.org/documentation/nvcodec/nvh265enc.html?gi-language=c) |
@@ -422,14 +426,14 @@ The default encoder uses `h264` for video and `aac` for audio, muxed in the `flv
! videoconvert ! videoconvert
! queue ! queue
! video/x-raw,format=NV12 ! video/x-raw,format=NV12
! nvh264enc name=encoder preset=low-latency-hq gop-size=25 spatial-aq=true temporal-aq=true bitrate=2800 vbv-buffer-size=2800 rc-mode=6 ! nvautogpuh264enc name=encoder preset=low-latency-hq gop-size=25 spatial-aq=true temporal-aq=true bitrate=2800 vbv-buffer-size=2800 rc-mode=6
! h264parse config-interval=-1 ! h264parse config-interval=-1
! video/x-h264,stream-format=byte-stream,profile=high ! video/x-h264,stream-format=byte-stream,profile=high
! h264parse ! h264parse
! mux. ! mux.
``` ```
This configuration requires [Nvidia GPU](https://developer.nvidia.com/cuda-gpus) with [NVENC](https://developer.nvidia.com/nvidia-video-codec-sdk) support and [Nvidia docker image](/docs/v3/installation/docker-images#nvidia) of neko. This configuration requires [Nvidia GPU](https://developer.nvidia.com/cuda-gpus) with [NVENC](https://developer.nvidia.com/nvidia-video-codec-sdk) support and [Nvidia docker image](/docs/v3/installation/docker-images#nvidia) of neko. Use `nvautogpuh264enc` for NVIDIA driver 590+ (GStreamer 1.22+), or substitute `nvh264enc` for older setups.
</TabItem> </TabItem>
</Tabs> </Tabs>
+6 -2
View File
@@ -128,7 +128,7 @@ services:
! video/x-raw,framerate=25/1 ! video/x-raw,framerate=25/1
! cudaupload ! cudaconvert ! queue ! cudaupload ! cudaconvert ! queue
! video/x-raw(memory:CUDAMemory),format=NV12 ! video/x-raw(memory:CUDAMemory),format=NV12
! nvh264enc ! nvautogpuh264enc
name=encoder name=encoder
preset=2 preset=2
gop-size=25 gop-size=25
@@ -157,6 +157,10 @@ services:
See available [Nvidia Docker Images](/docs/v3/installation/docker-images#nvidia). See available [Nvidia Docker Images](/docs/v3/installation/docker-images#nvidia).
:::tip
`nvautogpuh264enc` (GStreamer 1.22+) is the recommended encoder for NVIDIA driver 590 and newer. It automatically selects the correct memory path (CUDA or system) and replaces `nvh264enc`. If you are on an older driver or GStreamer version, substitute `nvautogpuh264enc` with `nvh264enc`.
:::
:::note :::note
If your Nvidia GPU does not support CUDA, you can use the pipeline below without `cudaupload` and `cudaconvert`. This should work with older GPUs, but the performance might be lower. If your Nvidia GPU does not support CUDA, you can use the pipeline below without `cudaupload` and `cudaconvert`. This should work with older GPUs, but the performance might be lower.
::: :::
@@ -185,7 +189,7 @@ services:
! videoconvert ! queue ! videoconvert ! queue
! video/x-raw,format=NV12 ! video/x-raw,format=NV12
# highlight-end # highlight-end
! nvh264enc ! nvautogpuh264enc
name=encoder name=encoder
preset=2 preset=2
gop-size=25 gop-size=25