Video acceleration API (VAAPI) allows us to use GPU in applications that support it (MPV, VLC, ffmpeg for example). Thus, the load on the processor is significantly reduced. This is an effective way to use computer resources because GPU works better with matrices (frames of the video) than the processor.
VAAPI is a really good choice. It works perfect with a simple task, like watching a video. So, if you are using a simple and portable computer with a built-in GPU (Intel processors), but when you watch a video in the media player (VLC, MPV) it lags, then the method below will help you to solve this problem. The necessary drivers and VAAPI will be installed
In this article we will not consider how to install it for each video card separately. We will look at a universal path that works for any GPU model that supports VAAPI.
Notes before we start
VAAPI and VDPAU are completely different API’s. BUT. VDPAU may serve as a translation layer for VAAPI. In other words, VAAPI may work through VDPAU. If some application supports only VAAPI, but your system supports only VDPAU, then you’ll fine because VAAPI can work through VDPAU.
What API my GPU driver supports?
Intel graphics (VAAPI):
Very long list of supported models. It seems only VAAPI is supported. VDPAU is not required.
Nouveau (open-sourced driver for NVIDIA GPU):
Supports both VAAPI and VDPAU for GeForce 8 series and newer. if there are no supported profiles, use the method in the end of this article.
NVIDIA proprietary driver:
Supports only VDPAU and requires additional package (see this article: MPV with NVIDIA driver). It also requires GeForce 8 series and newer. Note that VAAPI is able to use VDPAU for work (emulation mode) .
VDPAU for Radeon R300 and newer.
VA-API for Radeon HD 2000 and newer.
Proprietary driver is based on open-sourced driver, so it also works.
How To install VAAPI
sudo apt install mesa-va-drivers
This command will install everything we need.
To show what things are supported by GPU, install vainfo utility:
sudo apt install vainfo
We should see something like that:
These are all supported profiles.
How To install VDPAU
VDPAU is another API for video cards. But VAAPI may use VDPAU as translation layer. In some cases, the driver could use only VDPAU, but application supports only VAAPI. Then VAAPI will use VDPAU and everything will work. So, if your video card supports VDPAU you had better install it.
sudo apt install mesa-vdpau-drivers
Special testing utility for VDPAU:
sudo apt install vdpauinfo
Then run it:
We should see something like that:
And that’s all.
VDPAU for NVIDIA proprietary driver (GeForce 8 and newer)
See the first paragraph of the article – NVIDIA + VDPAU + MPV = 1% of CPU consumption
VAAPI vs VDPAU. Which one is better?
There is no exact answer. Drivers and video card series are different. You can only experiment with this and choose one.
How To use VAAPI/VDPAU in mpv?
To use VAAPI:
mpv --hwdec=vaapi --vo=vaapi "FILENAME"
To use VDPAU:
mpv --hwdec=vdpau --vo=vdpau "FILENAME"
To play youtube h264 videos in the best resolution(and 60 fps if available) with VAAPI:
mpv --hwdec=vaapi --vo=vaapi --ytdl-format="bestvideo[ext=mp4][height<=?1080]+bestaudio[ext=m4a]" "link on youtube"
There is no supported profiles in VAAPI and VDPAU (nouveau NVIDIA)
I had such a problem. My NVIDIA GeForce GT 610 is not supported by VAAPI and VDPAU (when using nouveau driver). But when i extracted firmware from proprietary NVIDIA driver it started working! I followed the instructions below:
mkdir /tmp/nouveau cd /tmp/nouveau wget https://raw.github.com/imirkin/re-vp2/master/extract_firmware.py wget http://us.download.nvidia.com/XFree86/Linux-x86_64/325.15/NVIDIA-Linux-x86_64-325.15.run # For 64-bit Linux systems OR wget http://us.download.nvidia.com/XFree86/Linux-x86/325.15/NVIDIA-Linux-x86-325.15.run # For 32-bit Linux systems sh NVIDIA-Linux-x86_64-325.15.run --extract-only # 64-bit .run file OR sh NVIDIA-Linux-x86-325.15.run --extract-only # 32-bit .run file python2 extract_firmware.py # This script is for python version 2 only sudo mkdir /lib/firmware/nouveau sudo cp -d nv* vuc-* /lib/firmware/nouveau/
Here we download a script and driver. The script is needed to extract firmware from the driver. I tried to extract firmware from NVIDIA driver version 390, but it didn’t work. It looks like it only works with this version of the driver. Now you can check your vainfo and vdpauinfo outputs.
NVIDIA proprietary driver supports only by VDPAU. Therefore, with this proprietary firmware we need to use VDPAU only.
Here is MPV example, CPU usage is about ~1% (1080p, h264, 30 fps, 5828 kb/s bitrate):
mpv --hwdec=vdpau --vo=vdpau Video.mp4 # Nouveau with proprietary firmware works only with VDPAU