At least for the recent months, I have been used to spending my free time watching videos on my laptop, and since my laptop has an integrated GPU, AMD Radeon Vega 8, I was thinking about what if I can accelerate video processing using GPU and reduce the load of CPU.
The media players that I mostly use to watch videos are Firefox (for online videos) and MPV (for offline videos), and referring to the list of video acceleration support between different applications [1], the only method that is supported by both Firefox and MPV is VA-API, which is
an open source application programming interface that allows applications such as VLC media player or GStreamer to use hardware video acceleration capabilities, usually provided by the graphics processing unit (GPU). [2]
In order to enable VA-API for my ADM GPU, the driver "radeonsi" should be added [3]:
$ nano /etc/portage/make.conf VIDEO_CARDS="amdgpu radeonsi"
Also, for applications that support VA-VAP, the USE flag "vaapi" should be included [4]:
$ nano /etc/portage/make.conf USE="vaapi"
After that, update the whole system to apply these changes. However, we still need to do additional settings inside MPV and Firefox respectively to make them work with VA-API while playing videos.
MPV Settings
Simply add the below line to MPV's configuration file, or use the option --hwdec=vaapi while opening it:
$ nano ~/.config/mpv/mpv.conf hwdec=vaapi
To verify if MPV have VA-API enabled, play a video in MPV and hit the key "i" to get its running details:
Firefox Settings
Open the page about:config in Firefox, make sure the below two options are set to true:
gfx.webrender.all true media.ffmpeg.vaapi.enabled true
However, I was not able to find the option media.ffmpeg.vaapi.enable in my Firefox. After channelling my Google-fu, I found:
115esr needs "hwcaccel" and "wayland" USE flags enabled to get hardware acceleration for Firefox. X and wayland can be enabled simultaneously. >116 was fixed to have hardware acceleration without wayland support. [5]
According to that, since my firefox version was 102esr, I had to add additional USE flags hwaccel and wayland (note that even for Xorg, the USE flag wayland is needed):
$ nano /etc/portage/package.use/firefox www-client/firefox hwaccel wayland
To verify if Firefox works fine with VA-API enabled, execute the following command and check out the output:
$ MOZ_LOG="PlatformDecoderModule:5" firefox 2>&1 | grep "VA-API"
Thanks for reading :)