How to watch videos with GPU assistance

Post tutorials, HOWTO's and other useful resources here.
fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

How to watch videos with GPU assistance

Post#1 by fulalas » 27 Mar 2017, 01:55

This tutorial explains how to move the load from CPU to GPU when watching videos. This is specially useful if you:

1- don't have a CPU powerful enough to handle heavy videos;
2- want to reduce CPU fan speed/noise;
3- want to watch videos while doing some heavy CPU task on the background;
4- want to save energy/battery life once GPU decoding is more optimized than CPU decoding;
5- are a geek and just want to try new technologies :)

I recommend using SMPlayer as the frontend (i.e. graphic interface) and Mpv as backend (i.e. video engine-player). However you can try different combinations, like pure Mpv or SMPlayer + MPlayer or Vlc, etc.

---Intel Cards---
You need both libva and libva-intel-driver:

http://www.mediafire.com/file/qi8jvi3t8 ... x86_64.xzm
http://www.mediafire.com/file/p204l75n8 ... x86_64.xzm

After loading both modules, go to the terminal and run:

Code: Select all

vainfo
If you see something similar to this you're good to go:

Code: Select all

libva info: VA-API version 0.39.4
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib64/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) Kabylake - 1.7.3
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      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
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointEncSlice
      VAProfileVP9Profile2            : VAEntrypointVLD
If you can't see any supported profile/entrypoints, you're probably missing some dependency. In this case, run the following commands and check what's missing:

Code: Select all

ldd /usr/lib64/dri/i965_drv_video.so

Code: Select all

ldd /usr/lib64/libva.so.1.3904.0
Please, note that 'libva.so.1.3904.0' is the current libva-intel-driver version used in the first version of this tutorial. Maybe you need to check what's the version you have downloaded and run ldd pointing to the actual file name.

---Nvidia Cards---
Both Nvidia proprietary drivers and Mesa drivers already come with vdpau lib, so you don't need to load any additional module.

---AMD/ATI Cards---
I don't have a card from this brand, but you can check this Arch tutorial and see if it.

---Configuring SMPlayer player---
Now you need to set SMPlayer to use GPU assistance. Go to Preferences -> Performance -> Decoding -> Hardware decoding and:

If you're using an Intel video card, set 'vaapi'
If you're using a Nvidia video card, set 'vdpau'

---Testing---
Now try to watch really heavy videos, like Bug Buck Bunny 4k @ 60 FPS or Crowd Run 4k @ 50 FPS and see if CPU usage is always bellow 10%.

To make sure everything is in place, call Mpv directly from terminal passing the correct flag according to your video card:

Intel:

Code: Select all

mpv path_to_the_video --hwdec vaapi
Nvidia or AMD/ATI:

Code: Select all

mpv path_to_the_video --hwdec vdpau
Mpv should print something like this:

Code: Select all

Using hardware decoding (vaapi).                                                                                                      
VO: [opengl] 1920x1080 vaapi
Last edited by fulalas on 27 Mar 2017, 20:49, edited 2 times in total.

jssouza
Legendary
Legendary
Posts: 1165
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm

Re: How to watch videos with GPU assistance

Post#2 by jssouza » 27 Mar 2017, 05:24

Hi fulalas,

ffmpeg, libva, libvdpau etc. are already present in 002-xorg. Apart from them being older versions, is there any other reason to upgrade to the newer versions that you have shared? (Newer hardware support perhaps?)

I tried your instructions on stock porteus on a laptop with intel driver:

Code: Select all

libva info: VA-API version 0.38.1
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib64/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_38
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.38 (libva 1.6.2)
vainfo: Driver version: Intel i965 driver for Intel(R) Haswell Mobile - 1.6.2
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264MultiviewHigh      :	VAEntrypointVLD
      VAProfileH264MultiviewHigh      :	VAEntrypointEncSlice
      VAProfileH264StereoHigh         :	VAEntrypointVLD
      VAProfileH264StereoHigh         :	VAEntrypointEncSlice
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileH264MultiviewHigh      :	VAEntrypointVLD
      VAProfileH264MultiviewHigh      :	VAEntrypointEncSlice
      VAProfileH264StereoHigh         :	VAEntrypointVLD
      VAProfileH264StereoHigh         :	VAEntrypointEncSlice
And Edit->Preferences->Video Output in GNOME Mplayer from "xv" to "vaapi". GNOME MPlayer stopped playing video files after this change. Reverting to xv played video files, although I assume on CPU and not on the GPU.

Seems like the culprit is Mplayer itself:

Code: Select all

guest@porteus:~$ mplayer -vo help
MPlayer 1.3.0-5.3.0 (C) 2000-2016 MPlayer Team
Available video output drivers:
	vdpau	VDPAU with X11
	xv	X11/Xv
	gl_nosw	OpenGL no software rendering
	x11	X11 ( XImage/Shm )
	xover	General X11 driver for overlay capable video output drivers
	sdl	SDL YUV/RGB/BGR renderer (SDL v1.1.7+ only!)
	gl	OpenGL
	gl_tiled	X11 (OpenGL) - multiple textures version
	dga	DGA ( Direct Graphic Access V2.0 )
	fbdev	Framebuffer Device
	fbdev2	Framebuffer Device
	matrixview	MatrixView (OpenGL)
	aa	AAlib
	caca	libcaca
	v4l2	V4L2 MPEG Video Decoder Output
	xvidix	X11 (VIDIX)
	cvidix	console VIDIX
	null	Null video output
	mpegpes	MPEG-PES to DVB card
	yuv4mpeg	yuv4mpeg output for mjpegtools
	png	PNG file
	jpeg	JPEG file
	tga	Targa output
	pnm	PPM/PGM/PGMYUV file
	md5sum	md5sum of each frame
	mng	MNG file
No vaapi :unknown:

Update:
vaapi does not look to be officially supported - http://mplayerhq.hu/design7/info.html. Seems need to use an unofficial repository https://github.com/gbeauchesne/mplayer-vaapi.
Mpv it is then. :wink:

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

Re: How to watch videos with GPU assistance

Post#3 by fulalas » 27 Mar 2017, 05:59

Porteus 3.2.2 default libva/libva-intel-driver doesn't work here with my Kaby Lake. The version is really too old.

And, yeah, MPlayer isn't the best option anymore. I use Mpv because of this and this (long reading, but highly recommended if you're a video addicted). :good:

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

Re: How to watch videos with GPU assistance

Post#4 by fulalas » 27 Mar 2017, 06:42

If you want to by-pass the update of FFMpeg and its dependencies, you can go with Mpv 0.21.0, which seems old but in fact is from the ending of 2016 and it works flawlessly (in fact, it's my current version right now):

http://www.mediafire.com/file/f99xeqx58 ... -1_SBo.xzm

hypomania
Samurai
Samurai
Posts: 130
Joined: 10 Mar 2011, 10:50
Distribution: Windows phone
Location: Saudi Arabia

Re: How to watch videos with GPU assistance

Post#5 by hypomania » 30 Mar 2017, 00:52

thank you,
I tied x11 before read your post and I notice the noise of fan when play blu-ray video. even on xubuntu.
and there is no problem with vlc.
does mplayer has been died !

Post Reply