24
December
2021
16:20

Setting up hardware video acceleration: brief instructions

24 December 2021 16:20

I configured video acceleration on my netbook (single-core AMD C-30 processor, AMD Radeon HD 6250 video card), and I’m sharing my experience.

For hardware-accelerated video playback, three conditions must be met:
1) Hardware acceleration due to the graphics adapter with support for hardware acceleration and graphics adapter drivers,
2) Enable VA and VDPAU (you need to check that they are enabled),
3) Setting up the Mozilla Firefox web browser.

I followed the instructions according to the guide on https://wiki.archlinux.org/title/
Hardware_video_acceleration#ATI/AMD

In order:

1) Installed the necessary packages (since I have AMD - I used amdgpu, and for integrated Intel graphics you will need the Intel-prime package

Ubuntu only:

sudo apt install ubuntu-restricted-extras

For all Linux OS:

sudo apt-get install linux-firmware mpv vdpauinfo

If AMD graphics:

sudo apt-get install xserver-xorg-video-amdgpu 

If Intel graphics:

sudo apt install intel-gpu-tools
sudo intel_gpu_top

If nVidia graphics - either use a proprietary driver with closed source code ("nvidia"), or Open-Source driver "nouveau"- I recommend it. On Ubuntu based OS, the Nouveau driver is built into the system.
You just need to check the file /etc/X11/xorg.conf, which driver is used, "nvidia" or "nouveau". In the case of ATI/AMD, the file contains the line "Driver " amdgpu".

Addition from 08/18/2023: the X server configuration is located in the folder /usr/share/X11/xorg.conf.d и файле /etc/X11/xorg.conf.
Practice has shown that having an xorg.conf file is desirable (commands do not work without it inxi -Gxx или inxi -G --extra 2).
You need to reboot, select additional recovery options ("Advanced recovery options") and enter the "root" menu, where you run the commands:

X -configure
cp /root/xorg.conf.new /etc/X11/xorg.conf

2) Reboot. We check on any video downloaded from the Internet (.mp4 file) that the system is working hardware video acceleration_ (it is advisable to take a test file with a resolution of 720p, for example 1280x720, a frame rate of 25fps and a length of no more than 2 minutes) in the video playback program.

Video file examples:Sample - MP4 files.

wget url_видео_файла

mpv --hwdec=auto "filename.mp4" 

The video clip will start playing in a full-screen window. You can estimate the frame rate by eye to see if there are any gaps.
After playback ends, input focus will return to the terminal, where you need to read the last 2 lines:
If there is a mention vaapi, then hardware acceleration of the video card and driver works.

In case of playback errors, use the inxi version of the video card and look for a solution on the Internet with drivers:

lspci | grep -i display
inxi -Gxxz

If there is no hardware video acceleration, the remaining points do not make sense; we are looking for third-party drivers.
(Guide to installing drivers for nVidia video cards in Ubuntu 20.04).
My video player hardware acceleration turned on immediately. I continue...

VAINFO check

sudo apt-get install vainfo 
vainfo

The output should show that the video card supports at least the main codecs: mpeg2 and h.264.

VAProfileH264, etc.:

libva info: VA-API version 1.7.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/r600_drv_video.so
libva info: Found init function __vaDriverInit_1_7
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.7 (libva 2.6.0)
vainfo: Driver version: Mesa Gallium driver 21.2.6 for AMD PALM (DRM 2.50.0 / 5.4.0-139-generic, LLVM 12.0.0)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple : VAEntrypointVLD
      VAProfileMPEG2Main : VAEntrypointVLD
      VAProfileVC1Simple : VAEntrypointVLD
      VAProfileVC1Main : VAEntrypointVLD
      VAProfileVC1Advanced : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264Main : VAEntrypointVLD
      VAProfileH264High : VAEntrypointVLD
      VAProfileNone : VAEntrypointVideoProc

If error -1 occurs, then download and install vdpau-va-driver.

Note: VA is a special application programming interface (API) developed by Intel to use hardware acceleration. (Video Acceleration API).

VDPAU check

grep -iE 'vdpau | dri driver' /var/log/Xorg.0.log

It should be written that VDPAU driver (in this case RADEON) installed:

[61.505](II)RADEON(0): [DRI2] DRI driver: r600
[61.505](II)RADEON(0): [DRI2] VDPAU driver: r600

Note: VDPAU is an open source software interface for video decoration on Unix. (Video Decode and Presentation API for Unix)

3)Setting up Mozilla FireFox for hardware YouTube video playback:

First of all, you need to install the extension "h264ify":
https://addons.mozilla.org/ru/
firefox/addon/h264ify/

Secondly, check that the WebRender container is enabled and running in FireFox.

about:support

In the section "Solution log" when acceleration is turned on by the device, the following should be used:values:

  • in the column HW_COMPOSITING - available
  • in the WebRender - available column

Let's configure the configuration a little:
about:config
and then changed the keys:
media.ffmpeg.vaapi.enabled=true(enable hardware acceleration of FFmpeg playback using VAAPI)
media.navigator.mediadatadecoder_vpx_enabled=true(allows hardware acceleration of WebRTC - video conferencing)
media.rdd-vpx.enabled=false(disable built-in software decoder VP8/VP9)
media.peerconnection.video.vp9_enabled=false(disabling the slow VP9 codec - addition from 07/05/2024)

Check in the extensions panel that the extension is enabled in FireFox h264ify. Restart FireFox.
After the specified settings, the video is played with low CPU load.

P.S. Some instructions recommend adding an export variable to ~/.profile , instructions for Wayland or Xorg. I didn't do this:instructions.

4) Disable window composer compton(consumes CPU resources - note dated 07/05/2024) and reboot

 sudo apt remove compton && sudo shutdown -r now

What was and became:

  • before enabling hardware video acceleration: YouTube did not play in the window (frozen frame, audio only). Single-core processor utilization is about 90%.
  • when AMD Radeon HD hardware acceleration is enabled: video is played in 480p video in a window without skipping 25fps, and in full screen video is 25 fps; video resolution 720p full screen - 25fps; maximum resolution Full HD 1080p - frame rate about 25 fps (at the beginning of playback about 10-15 seconds there are frame drops - 10-15 frames per second).

Sources:
https://wiki.archlinux.org/title/Hardware_video_acceleration
https://wiki.archlinux.org/title/Firefox#Hardware_video_acceleration
*https://discourse.ubuntu.com/t/enabling-accelerated-video-decoding-in-firefox-on-ubuntu-21-04/22081



Related publications