nvidia-vaapi-driver配置
- N卡驱动安装
- 安装nvidia-vaapi-driver
- 内核参数设置
- 环境变量配置
- 安装ffmpeg
- Firefox软件内参数设置
- 验证
- vainfo输出
- nvidia-settings
在使用linux系统的firefox看B站视频时发现不支持硬件解码,而笔记本开启了独显直连后只用N卡,N卡并不支持vaapi,支持vdpau,而firefox不支持使用vdpau作硬解,很矛盾。
在AUR源中的libva-nvidia-driver
可以解决这个问题,github仓库的readme中有需要配置的参数,详见elFarto的仓库。
本机环境:
-
GeForce RTX 2060(notebook)
-
显卡驱动版本:535.104.05
N卡驱动安装
使用该库需要安装闭源N卡驱动,manjaro可以在安装时选装,Debian 12需要在英伟达官网下载。先把X server停用,再安装闭源驱动。
# 查看默认X Server显示管理器
cat /etc/X11/default-display-manager
# /usr/sbin/gdm3
sudo service gdm3 stop
停用后按Ctrl+Alt+F3
进tty,再运行.run
文件按步骤安装。若需要停用开源驱动nouveau
,则在安装程序停用默认显卡驱动后,执行以下命令:
sudo update-initramfs -u
sudo reboot
重启后关闭gdm3,再执行安装程序。
安装nvidia-vaapi-driver
Manjaro使用以下命令进行安装:
#manjaro/arch linux
yay -S libva-nvidia-driver
Debian 12软件源中内置的版本为0.0.8,最新版为0.0.10,因此下载源码自行编译安装。
下载地址:https://github.com/elFarto/nvidia-vaapi-driver/archive/refs/tags/v0.0.10.zip
首先安装所需的依赖:
sudo apt install meson gstreamer1.0-plugins-bad libffmpeg-nvenc-dev libva-dev libegl-dev libgstreamer-plugins-bad1.0-dev
在源码解压位置执行如下命令:
meson setup build
sudo meson install -C build
即可安装成功。
内核参数设置
nvidia-vaapi-driver
需要将nvidia_drm
使用参数nvidia-drm.modeset=1
进行配置,在GRUB里进行配置:
sudo vim /etc/default/grub
将GRUB_CMDLINE_LINUX_DEFAULT
加上"nvidia-drm.modeset=1"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=linux nvidia-drm.modeset=1"
ESC+:+wq
退出后执行以下命令:
sudo update-initramfs -u
sudo update-grub
重启后生效。
环境变量配置
sudo vim /etc/environment
在/etc/environment
中添加以下环境变量:
# Controls which backend this library uses. Either egl (default), or direct. See direct backend for more details.
NVD_BACKEND=direct
# Disables the sandbox for the RDD process that the decoder runs in.
MOZ_DISABLE_RDD_SANDBOX=1
# For libva versions prior to 2.15, this forces libva to load the nvidia backend.
LIBVA_DRIVER_NAME=nvidia
# Required for the 470 driver series only. It overrides the list of drivers the glvnd library can use to prevent Firefox from using the MESA driver by mistake.
_EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json
ESC+:wq
退出后执行
source /etc/environment
即可生效。
安装ffmpeg
使用nvidia-vaapi-driver
需要安装支持vaapi的ffmpeg,Debian 12和Manjaro 22.1.3的软件源都含有这种ffmpeg。
sudo apt install ffmpeg
验证方法:
ffmpeg -hwaccels
输出文本中应该包含vaapi
。
Firefox软件内参数设置
地址栏输入about:config
进入参数设置页面,更改以下参数:
设置 | 值 | 原因 |
---|---|---|
media.ffmpeg.vaapi.enabled | true | Required, enables the use of VA-API. |
media.rdd-ffmpeg.enabled | true | Required, default on FF97. Forces ffmpeg usage into the RDD process, rather than the content process. |
media.av1.enabled | false | Optional, disables AV1. If your GPU doesn’t support AV1, this will prevent sites using it and falling back to software decoding. |
gfx.x11-egl.force-enabled | true | Required, this driver requires that Firefox use the EGL backend. It may be enabled by default. It is recommended to test it with the MOZ_X11_EGL=1 environment variable before enabling it in the Firefox configuration. |
widget.dmabuf.force-enabled | true | Required on NVIDIA 470 series drivers, and currently REQUIRED on 500+ drivers due to a Firefox change. Note that Firefox isn’t coded to allow DMA-BUF support without GBM support, so it may not function completely correctly when it’s forced on. |
表摘自elFarto的仓库
验证
vainfo输出
安装成功后,vainfo输出以下内容:
libva info: VA-API version 1.17.0
libva info: User environment variable requested driver 'nvidia'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.17 (libva 2.12.0)
vainfo: Driver version: VA-API NVDEC driver [direct backend]
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileH264Main : VAEntrypointVLD
VAProfileH264High : VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointVLD
VAProfileVP8Version0_3 : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain12 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD
VAProfileHEVCMain444 : VAEntrypointVLD
nvidia-settings
打开一个B站视频播放,右键视频统计信息,可以发现解码方式为AVC。
在播放视频的同时打开英伟达控制面板,可以发现,Video Engine Utilization
已经不为0,证明已经在使用硬件解码了。