N卡LinuxB站视频硬解-使用nvidia-vaapi-driver

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.enabledtrueRequired, enables the use of VA-API.
media.rdd-ffmpeg.enabledtrueRequired, default on FF97. Forces ffmpeg usage into the RDD process, rather than the content process.
media.av1.enabledfalseOptional, 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-enabledtrueRequired, 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-enabledtrueRequired 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,证明已经在使用硬件解码了。

硬解成功

  • 10
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lyre丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值