硬體視頻加速

出自 Arch Linux 中文维基

硬體視頻加速 讓顯卡進行視頻的解碼和編碼,以減少CPU的負載並節省電力。

Linux 中有多種方式可以實現視頻加速:

大致的總覽對比和應用支持,參見頁面下發的比較表格。

安裝[編輯 | 編輯原始碼]

Intel[編輯 | 編輯原始碼]

Intel graphics 開源驅動支持 VA-API:

參閱 VAAPI 支持的硬體和功能

NVIDIA[編輯 | 編輯原始碼]

Nouveau 開源驅動支持 VA-API 和 VDPAU:

NVIDIA 專有驅動通過 nvidia-utils 支持以下硬體:

AMD/ATI[編輯 | 編輯原始碼]

AMDGPUATI 開源驅動支持 VA-API 和 VDPAU:

  • Radeon HD 2000 和更新的 GPU 的 VA-API 由 libva-mesa-driver 支持
  • Radeon R600 和更新的 GPU 的 VDPAU 由 mesa-vdpau 支持

AMDGPU PRO 專有驅動是基於 AMDGPU 驅動的,所以支持 VA-API、VDPAU 和 AMF。

注意:
  • You may need to force your application to use AMDGPU PRO Vulkan Driver.
  • HEVC encoding may not be available on GPUs older than Navi.

翻譯層[編輯 | 編輯原始碼]

  • libva-vdpau-driver — VDPAU 作後端的 VA-API.
https://cgit.freedesktop.org/vaapi/vdpau-driver || libva-vdpau-driver, libva-vdpau-driver-vp9-gitAUR
  • libvdpau-va-gl — OpenGL/VAAPI 做後端的 VDPAU 驅動,僅支持 H.264.
https://github.com/i-rinat/libvdpau-va-gl || libvdpau-va-gl
  • nvidia-vaapi-driverCUDA NVDEC 作為後端的 VA-API.
https://github.com/elFarto/nvidia-vaapi-driver/ || libva-nvidia-driver
注意:

驗證[編輯 | 編輯原始碼]

你的系統可能可以開箱即用而無需任何其他配置就能完美工作。因此你最好通過如下方法查看是否如此。

提示:
  • mpv with its command-line support is great for testing hardware acceleration. Look at the log of mpv --hwdec=auto video_filename and see hwdec for more details.
  • For Intel GPU, use intel-gpu-tools and run intel_gpu_top as root to monitor the GPU activity during video playback for example. The video bar being above 0% indicates GPU video decoder/encoder usage.
  • Use nvtop to check "DEC" (decoder) usage on the top lines while playing a video, for AMD, Intel and NVIDIA.
  • For AMD GPU, use radeontop to monitor GPU activity. Unlike intel-gpu-tools, there is currently no way to see decode/encode usage on radeontop [3].
  • For any GPU, you can compare CPU usage with a tool like htop. Especially for higher resolution videos (4k+), CPU usage when VA-API is enabled and working should be dramatically lower on laptops and other relatively low-power devices.

檢驗 VA-API[編輯 | 編輯原始碼]

運行 libva-utils 包提供的 vainfo 來檢查 VA-API 的設置:

$ vainfo
libva info: VA-API version 0.39.4
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.39 (libva 1.7.3)
vainfo: Driver version: Intel i965 driver for Intel(R) Skylake - 1.7.3
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSliceLP
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointEncSliceLP
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointEncSliceLP
      VAProfileH264MultiviewHigh      :	VAEntrypointVLD
      VAProfileH264MultiviewHigh      :	VAEntrypointEncSlice
      VAProfileH264StereoHigh         :	VAEntrypointVLD
      VAProfileH264StereoHigh         :	VAEntrypointEncSlice
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointEncPicture
      VAProfileVP8Version0_3          :	VAEntrypointVLD
      VAProfileVP8Version0_3          :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice

VAEntrypointVLD 指的是你的顯卡能夠解碼這個格式,VAEntrypointEncSlice 指的是你的顯卡可以編碼這個格式。

上面的例子裡,i965 驅動正在運行,所以你可以看見這一行:

libva info: Trying to open /usr/lib/dri/i965_drv_video.so

如果運行 vainfo 的時候出現了下面的錯誤提示:

libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit

你要重新配置正確的驅動,詳見Hardware video acceleration#Configuring VA-API.

Verifying VDPAU[編輯 | 編輯原始碼]

Install vdpauinfo to verify if the VDPAU driver is loaded correctly and retrieve a full report of the configuration:

$ vdpauinfo
display: :0   screen: 0
API version: 1
Information string: G3DVL VDPAU Driver Shared Library version 1.0

Video surface:

name   width height types
-------------------------------------------
420    16384 16384  NV12 YV12 
422    16384 16384  UYVY YUYV 
444    16384 16384  Y8U8V8A8 V8U8Y8A8 

Decoder capabilities:

name                        level macbs width height
----------------------------------------------------
MPEG1                          --- not supported ---
MPEG2_SIMPLE                    3  9216  2048  1152
MPEG2_MAIN                      3  9216  2048  1152
H264_BASELINE                  41  9216  2048  1152
H264_MAIN                      41  9216  2048  1152
H264_HIGH                      41  9216  2048  1152
VC1_SIMPLE                      1  9216  2048  1152
VC1_MAIN                        2  9216  2048  1152
VC1_ADVANCED                    4  9216  2048  1152
...

配置[編輯 | 編輯原始碼]

Although the video driver should automatically enable hardware video acceleration support for both VA-API and VDPAU, it may be needed to configure VA-API/VDPAU manually. Only continue to this section if you went through #Verification.

The default driver names, used if there is no other configuration present, are guessed by the system. However, they are often hacked together and may not work. The guessed value will be printed in the Xorg log file, which is ~/.local/share/xorg/Xorg.0.log if rootless, or /var/log/Xorg.0.log if Xorg is running as root. To search the log file for the values of interest:

$ grep -iE 'vdpau | dri driver' xorg_log_file
(II) RADEON(0): [DRI2] DRI driver: radeonsi
(II) RADEON(0): [DRI2] VDPAU driver: radeonsi

In this case radeonsi is the default for both VA-API and VDPAU.

注意: If you use GDM, run journalctl -b --grep='vdpau | dri driver' as root instead.

This does not represent the configuration however. The values above will not change even if you override them.

Configuring VA-API[編輯 | 編輯原始碼]

You can override the driver for VA-API by using the LIBVA_DRIVER_NAME environment variable:

注意:
  • You can find the installed drivers in /usr/lib/dri/. They are used as /usr/lib/dri/${LIBVA_DRIVER_NAME}_drv_video.so.
  • Some drivers are installed several times under different names for compatibility reasons. You can see which by running sha1sum /usr/lib/dri/* | sort.
  • LIBVA_DRIVERS_PATH can be used to overrule the VA-API drivers location.
  • Since version 12.0.1 libva-mesa-driver provides radeonsi instead of gallium.

Configuring VDPAU[編輯 | 編輯原始碼]

You can override the driver for VDPAU by using the VDPAU_DRIVER environment variable.

The correct driver name depends on your setup:

  • For Intel graphics you need to set it to va_gl.
  • For the open source AMD driver set it to the proper driver version depending on your GPU, see #Verification.
  • For the open source Nouveau driver set it to nouveau.
  • For NVIDIA's proprietary version set it to nvidia.
注意:
  • You can find the installed drivers in /usr/lib/vdpau/. They are used as /usr/lib/vdpau/libvdpau_${VDPAU_DRIVER}.so.
  • Some drivers are installed several times under different names for compatibility reasons. You can see which by running sha1sum /usr/lib/vdpau/*.
  • For hybrid setups (both NVIDIA and AMD), it may be necessary to set the DRI_PRIME environment variable. For more information see PRIME.

Configuring applications[編輯 | 編輯原始碼]

Multimedia frameworks:

Video players:

Web browsers:

Multimedia recording/streaming:

Troubleshooting[編輯 | 編輯原始碼]

Failed to open VDPAU backend[編輯 | 編輯原始碼]

You need to set VDPAU_DRIVER variable to point to correct driver. See #Configuring VDPAU.

VAAPI init failed[編輯 | 編輯原始碼]

An error along the lines of libva: /usr/lib/dri/i965_drv_video.so init failed is encountered. This can happen because of improper detection of Wayland. One solution is to unset $DISPLAY so that mpv, MPlayer, VLC, etc. do not assume it is X11. Another mpv-specific solution is to add the parameter --gpu-context=wayland.

This error can also occur if you installed the wrong VA-API driver for your hardware.

Video decoding corruption or distortion with AMDGPU driver[編輯 | 編輯原始碼]

When experiencing video decoding corruption or distortion with AMDGPU driver, set allow_rgb10_configs=false as environment variable or driconf. [4]

Comparison tables[編輯 | 編輯原始碼]

VA-API drivers[編輯 | 編輯原始碼]

Codec libva-intel-driver [5] intel-media-driver [6] libva-mesa-driver [7] [8] libva-vdpau-driver
(VDPAU adapter)
libva-nvidia-driver
(NVDEC adapter)
Decoding
MPEG-2 GMA 4500 and newer Broadwell and newer Radeon HD 6000 and newer
GeForce 8 and newer1
See #VDPAU drivers See #NVIDIA driver only
H.263/MPEG-4 Visual4 Radeon HD 6000 and newer
VC-1 Sandy Bridge and newer Broadwell and newer Radeon HD 2000 and newer
GeForce 9300 and newer1
H.264/MPEG-4 AVC GMA 45002, Ironlake and newer Radeon HD 2000 and newer
GeForce 8 and newer1
H.265/HEVC 8bit Cherryview/Braswell and newer Skylake and newer Radeon R9 Fury and newer
H.265/HEVC 10bit Broxton and newer Broxton/Apollo Lake and newer Radeon 400 and newer
VP8 Broadwell and newer Broadwell and newer
VP9 8bit Broxton and newer
Hybrid: Haswell refresh to Skylake3
Broxton/Apollo Lake and newer Raven Ridge + Radeon RX 5000 and newer See #VDPAU drivers5
VP9 10bit & 12bit Kaby Lake and newer Kaby Lake and newer
AV1 8bit & 10bit Tiger Lake and newer Radeon RX 6600 and higher/newer
Encoding
MPEG-2 Ivy Bridge and newer Broadwell and newer
except Broxton/Apollo Lake
6
H.264/MPEG-4 AVC Sandy Bridge and newer Broadwell and newer Radeon HD 7000 and newer
H.265/HEVC 8bit Skylake and newer Skylake and newer Radeon 400 and newer
H.265/HEVC 10bit Kaby Lake and newer Kaby Lake and newer Raven Ridge + Radeon RX 5000 and newer
VP8 Cherryview/Braswell and newer
Hybrid: Haswell to Skylake3
VP9 8bit Kaby Lake and newer Icelake and newer
VP9 10bit & 12bit
AV1 8bit & 10bit Alchemist and newer Radeon RX 7900 and higher/newer

VDPAU drivers[編輯 | 編輯原始碼]

Codec Color
depth
mesa-vdpau [10] [11] nvidia-utils libvdpau-va-gl
(VA-API adapter)
Decoding
MPEG-2 8bit Radeon R600 and newer
GeForce 8 and newer1
GeForce 8 and newer
H.263/MPEG-4 Visual 8bit Radeon HD 6000 and newer
GeForce 200 and newer1
GeForce 200 and newer
VC-1 8bit Radeon HD 2000 and newer
GeForce 9300 and newer1
GeForce 8 and newer2
H.264/MPEG-4 AVC 8bit Radeon HD 2000 and newer
GeForce 8 and newer1
GeForce 8 and newer See #VA-API drivers
H.265/HEVC 8bit Radeon R9 Fury and newer GeForce 900 and newer3
10bit Radeon 400 and newer 4
VP9 8bit Raven Ridge + Radeon RX 5000 and newer GeForce 900 and newer3
10bit/12bit 4
AV1 8bit Radeon RX 6600 and higher/newer GeForce 30 and newer5
10bit 4
  • 1 Up until GeForce GTX 750.
  • 2 Except GeForce 8800 Ultra, 8800 GTX, 8800 GTS (320/640 MB).
  • 3 Except GeForce GTX 970 and GTX 980.
  • 4 NVIDIA implementation is limited to 8bit streams [12] [13].
  • 5 Starting with driver version 510.[14]

NVIDIA driver only[編輯 | 編輯原始碼]

Codec nvidia-utils [15]
NVDEC NVENC
MPEG-2 Fermi and newer1
VC-1
H.264/MPEG-4 AVC Kepler and newer2
H.265/HEVC 8bit Maxwell (GM206) and newer Maxwell (2nd Gen) and newer
H.265/HEVC 10bit Pascal and newer
VP8 Maxwell (2nd Gen) and newer
VP9 8bit Maxwell (GM206) and newer
VP9 10bit & 12bit Pascal and newer
AV1 8bit & 10bit Ampere and newer3 Ada Lovelace and newer
  • 1 Except GM108 (not supported)
  • 2 Except GM108 and GP108 (not supported)
  • 3 Except A100 (not supported)

Application support[編輯 | 編輯原始碼]

Application Decoding Encoding Documentation
VA-API VDPAU NVDEC VA-API NVENC
FFmpeg FFmpeg#Hardware video acceleration
GStreamer GStreamer#Hardware video acceleration
Kodi Kodi#Hardware video acceleration
mpv mpv#Hardware video acceleration
VLC media player VLC media player#Hardware video acceleration
MPlayer 1 MPlayer#Hardware video acceleration
Flash 2 2 Browser plugins#Adobe Flash Player
Chromium Chromium#Hardware video acceleration
Firefox Firefox#Hardware video acceleration
GNOME/Web GStreamer ? ? GNOME/Web#Video
  • 1 VA-API support provided by mplayer-vaapiAUR instead.
  • 2 VDPAU is supported only by NPAPI plugin. PPAPI plugin to NPAPI browser experimental adapter is available that provides partial VA-API and VDPAU acceleration.