Articles about linux, tech, etc


Hardware accelaration on linux with VA-API

So I've always had issues with software decoding, as I use a laptop primarily, and software decoding is not only slow and eats up cpu usage, but it also impacts battery life significantly. Recently I've discovered(unsure how I didn't realize this before), that hardware decoding is disabled by default. So I set out to fix that. I'd figure there'd be some hurdles, but no, it's that easy.

First, I checked what driver I need for my card, HD Graphics 620, that's integrated intel graphics, so I needed x11-libs/libva-intel-driver(check here for your driver). It installed quite quickly and I was able to move on to the next step.

I installed media-video/libva-utils, and ran vainfo. this will give a large, somewhat confusing output, but the gist of it is those with VAEntrypointVLD are codecs you can decode from, and VAEntrypointEncSlice is those which you can encode to(less imporant). So to get what I have hardware decoder support for it's a simple vainfo | grep VAEntrypointVLD.

As you can see in my case, all the most important codecs are there. So next to enable it. This is done on a per application basis, but is simple enough in most where you'd actually, consume media. I followed the instructions for a few programs on this article on the arch wiki. Gstreamer simply required me installing media-plugins/gst-plugins-vaapi. In firefox it is enabled by default if supported. Kodi requires a simple change of the hardware backends setting. Flash player allows you to enable it in mms.cfg, or a simple settings change in embedded content.

Now for the weird one. Mpv. Believe it or not, mpv actually recommends against using hardware decoders. As it says in the manpage, "Hardware decoding is not enabled by default, because it is typically an additional source of errors. It is worth using only if your CPU is too slow to decode a specific video." which on a proper setup is very much not the case. It specifically recommends against putting hwdec(hw decoding flag) in the config, "Or at least change it to hwdec=auto-safe.". However I don't care and I know my laptop has good vaapi support, so I set hwdec=vaapi in my mpv.conf. And it works great. I tested with streaming a 4k video, as beforehand I got quite serious audio/video desynchronization on anything above 1080p, and... it plays perfectly fine, no issues, no going out of sync. So I'd call that a success.