Linux - VAAPI: Nuc, Chromebox, HSW, IVB, Baytrail with Ubuntu 14.04

  Thread Rating:
  • 14 Votes - 4.79 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
fritsch Offline
Team-XBMC Developer
Posts: 7,175
Joined: Aug 2011
Reputation: 160
Location: Karlsruhe
Information  VAAPI: Nuc, Chromebox, HSW, IVB, Baytrail with Ubuntu 14.04
Post: #1
Preface:
This howto assumes, that you are able to create a file on a linux filesystem. Furthermore it assumes, that you are able to apt-get.

Make sure to read the part about how to fix the GPU HANG by installing special 3.18.0 kernel builds beneath.

14/09/11 Overview

VPP BOB was made working in the meantime on SNB, IVB and HSW. IVB supports MADI (Motion Adaptive Deinterlacing), though there is a little bug in the driver that it produces little artifacts. On HSW even MCDI (Motion Compensation Deinterlacing) and MADI is working now. Though, you need a special driver that wsnipex is packaging in his vaapi ppa (see beneath). Ubuntu Trusty does not ship a new enough version, as a result VAAPI-BOB will produce green artifacts on HSW and MCDI and MADI will jump like hell.

Furthermore the ppa (https://launchpad.net/~wsnipex/+archive/...nta-master (remark: everything was merged into kodi)) can automatically use a high quality software deinterlacer Yadif or BOB OpenGL Deinterlacer. It can seamlessly use the before mentioned GPU Deinterlacing (VAAPI-BOB, VAAPI-MADI, VAAPI-MCDI). Those methods can be selected when watching a specific movie by changing the relevant options via the movie reel. VAAPI-MCDI is not available on a Baytrail as this is an IVB based chip.

The best quality of the cpu deinterlacers gives the filter called Deinterlace that is the implementation also referred to as Yadif - that costs a lot of CPU cycles (so be warned here). If you have a HSW chip you can use the VAAPI-MCDI deinterlacer which has awesome quality while keeping CPU load low. On Baytrail chips I currently suggest using the OpenGL Bob deinterlacer - cause the GPU is maxed out when using any of the VAAPI methods. I hope we can optimize this in the future when using the new EGL surface sharing API which was introduced in libva 0.3.6.

Summary:
HSW: VAAPI-MCDI
IVB: VAAPI-BOB (cause of the artifacts mentioned above)
Baytrail / SNB / In general HD2000: BOB (which is done in the renderer and costs nearly nothing, not VPP-BOB).

This ppa provides a helix version of current master. The code will also be used in OpenELEC 5.0 - OpenELEC 4.2 is still Gotham based. The most code was already merged upstream to xbmc, but I suggest keeping the fernetmenta-master ppa for now as most fixes are first actively developed in there.

Some visual comparison:
Bob: https://dl.dropboxusercontent.com/u/5572...h1-bob.mp4
Yadif: https://dl.dropboxusercontent.com/u/5572...-yadif.mp4

Installation
-1.) Hardware Requirements / Software Requirements
SNB, IVB, HSW Intel Hardware
Ubuntu Trusty mini iso installed x64. Download link for example here: http://archive.ubuntu.com/ubuntu/dists/t...t/mini.iso
If you have a UEFI only system, you need to use the server iso as your basis, as the mini iso won't boot in UEFI mode. Server iso is http://cdimage.ubuntu.com/ubuntu-server/...-amd64.iso

0.) Basic Installation and script tuning
After the mini iso is installed, continue with the following steps:

Code:
sudo apt-get update
sudo apt-get install ssh python-software-properties software-properties-common udisks upower xorg alsa-utils mesa-utils git-core librtmp0 lirc libmad0 lm-sensors libmpeg2-4 avahi-daemon libnfs1 consolekit pm-utils libva1 vainfo libva-intel-vaapi-driver linux-firmware
sudo apt-get dist-upgrade

Allow every user (everyone) to start X11
Code:
sudo dpkg-reconfigure x11-common

Create the xbmc user and it add it the relevant groups. If you have created the xbmc user during installation only do the usermod part.
Code:
sudo adduser xbmc
sudo usermod -a -G cdrom,audio,video,plugdev,users,dialout,dip xbmc


To use the following upstart procedure you need to create /etc/init/xbmc.conf to start xbmc via upstart. That scripts does only wait for your HDMI device, if you want to wait for networking, you have to add that.
Code:
# xbmc-upstart
# starts XBMC on startup by using xinit.
# by default runs as xbmc, to change edit below.
env USER=xbmc

emits xbmc-started
description     "XBMC-barebones-upstart-script"
author          "Matt Filetto"

start on (filesystem and stopped udevtrigger)
stop on runlevel [016]

# tell upstart to respawn the process if abnormal exit
respawn
respawn limit 10 5
limit nice 21 21

script
exec su -c "xinit /usr/bin/kodi --standalone -- /usr/bin/X -nolisten tcp :0" $USER
# the following two are to get an idea, if you want to user a window manager
# sudo apt-get install fluxbox and comment the above exec line
# only one exec line is allowed.
#   exec su -c "xinit /usr/bin/fluxbox -- /usr/bin/X -nolisten tcp :0" $USER
end script
# remove all those to set Full rgb range make sure to change HDMI2 to match your device
# starting from the next line, including end script
# post-start script
# sleep 1
# DISPLAY=:0 xrandr --output HDMI2 --set "Broadcast RGB" Full
# end script

edit /etc/security/limits.conf and add before the end. remember xbmc is the username, not the application. This will allow your user to get the audio thread a bit more priority.
Code:
xbmc             -       nice            -1

Last thing is missing some permissions to shutdown, suspend the computer, therefore create the file /etc/polkit-1/localauthority/50-local.d/custom-actions.pkla with the following content (don't introduce line breaks, especially the Action= line must be exactly one line (especially no linebreaks or auto ".." in freedesktop.udisks.*), verify this):
Code:
[Actions for xbmc user]
Identity=unix-user:xbmc
Action=org.freedesktop.upower.*;org.freedesktop.consolekit.system.*;org.freedesk​top.udisks.*;org.freedesktop.login1.*
ResultAny=yes
ResultInactive=yes
ResultActive=yes

[Untrusted Upgrade]
Identity=unix-user:xbmc
Action=org.debian.apt.upgrade-packages;org.debian.apt.update-cache
ResultAny=yes
ResultInactive=yes
ResultActive=yes


1.) Installation of the repository and the new packages
Code:
sudo apt-add-repository ppa:team-xbmc/unstable (* this can be changed after helix final)
sudo apt-add-repository ppa:wsnipex/vaapi (see *)
sudo apt-get update
sudo apt-get install kodi kodi-bin
sudo apt-get dist-upgrade

3.) XBMC settings
System->Settings->System->Video Settings:
Vertical Sync: Let Driver decide

System ->Video->Acceleration:
Enable HQ Scalers for scaling above: 20%
Allow hardware acceleration (VDPAU): off
Allow hardware acceleration (VAAPI): On
Use Mpeg-2 VAAPI: Yes
Use Mpeg-4 VAAPI: if you like
UseVC-1 VAAPI: off (this causes vc1 interlaced to segfault, when on)
Adjust Refreshrate to match video: On

If you experience kernel hangs (dmesg will tell), you can set Prefer VAAPI Render: Off that will force the swfilter even when progressive / VAAPI BOB is in use.

System -> Video -> Playback
Sync Playback to Display: On
Sync Method: Video Clock (Drop/Dupe)
Adjust display refresh rate to match video: On Start / Stop

When playing some 720p file or lower (do you get why?) open the movie icon and set Deinterlace: Auto and Deinterlace Method to: Deinterlace (if it causes too much cpu load, choose Bob (Celeron Baytrail and Celeron 847 Nucs(!)) - also set Scaling algorithm to Lanczos 3 optimized (also not for Baytrail and Celeron Nucs, only for HD3000 and faster). Save for all files.

If you are running a Baytrail NUC or a 847 Celeron NUC or comparable - choose Scaling: Bilinear and Deinterlace-Method: BOB

advancedsettings.xml in /home/xbmc/.kodi/userdata/advancedsettings.xml should contain (don't create that file / directory as root - use the xbmc user, e.g. mkdir -p /home/xbmc/.kodi/userdata/):
Code:
<advancedsettings>
   <loglevel hide="false">0</loglevel>
  <cputempcommand>sensors|sed -ne "s/Core 0: \+[-+]\([0-9]\+\).*/\1 C/p"</cputempcommand>
  <gui>    
    <algorithmdirtyregions>3</algorithmdirtyregions>
    <nofliptimeout>0</nofliptimeout>
  </gui>    
<video>
  <latency>
    <delay>50</delay>
    <refresh>
      <min>23</min>
      <max>24</max>
      <delay>175</delay> <!-- set to zero or adjust if audio seems out of sync with 24p movies -->
     </refresh>
  </latency>
</video>
</advancedsettings>

Especially the RSS Reader produces high CPU load. You can disable that one under Appearance setting.

Howto update kodi
As kodi is a normal ubuntu package, installed via the ppa, it's as simple as:
Code:
sudo apt-get update
sudo apt-get upgrade

Fancy Splash?
Code:
sudo apt-get update
sudo apt-get install plymouth-label v86d
wget https://dl.dropboxusercontent.com/u/55728161/plkodi/kodibuntu-plymouth-theme_0.1.0%7Etrusty1_all.deb https://dl.dropboxusercontent.com/u/55728161/plkodi/plymouth-theme-kodibuntu-logo_0.1.0%7Etrusty1_all.deb https://dl.dropboxusercontent.com/u/55728161/plkodi/plymouth-theme-kodibuntu-text_0.1.0%7Etrusty1_all.deb
sudo dpkg -i *kodibuntu*deb
Remeber to edit /etc/default/grub and to change:
Code:
GRUB_CMDLINE_LINUX_DEFAULT=""
to
Code:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
Don't forget to run 'sudo update-grub' after you changed that line.

We are now done. A final reboot and everything should work:
Code:
sudo reboot


Troubleshooting
In order to get any help, please provide the following logs.
Code:
sudo apt-get install pastebinit
dmesg | pastebinit
cat ~/.kodi/temp/kodi.log | pastebinit
cat /var/log/Xorg.0.log | pastebinit
DISPLAY=:0 vainfo | pastebinit
dpkg -l |grep mesa | pastebinit
id | pastebinit
aplay -L | pastebinit

Audio
Check if you audio device is muted
You can use alsamixer -c0 or alsamixer -c1 to do it manually, or use something like:
Code:
amixer set 'IEC958',0 unmute

If you want to run pulseaudio, please see the xbmc wiki before: http://wiki.xbmc.org/index.php?title=PulseAudio

IRC Channel
Out of historical reasons, you can join #xbmc-xvba for discussing this howto. The channel name shall make us remember forever, that best hardware is worth nothing, if there are no drivers for it :-)

Happy penguin:
[Image: amd-dolby-truehd-320.jpg]

Current Issues
- MADI / MACI are non working on all architectures, we disabled them in code
- As of 14/08/20 MADI and MCDI could be enabled. Intel has fixed the issues Make sure you use the driver in the wsnipex vaapi ppa
- To use VAAPI BOB on HSW, you need to build libva-driver-intel 1.3.2 or higher from source, alternatively you can install that driver from wsnipex vaapi repository
- To use VAAPI MCDI/MADI on HSW, you need to build my ppa or ppa14 branch on my github which has picked the vebox fixes.
- There is an upstream bug in mesa/dri/libva which cause out of a sudden to start tearing. If you press stop xbmc gui will hang and you can see a kernel hang with dmesg. Upstream report is here: https://bugs.freedesktop.org/show_bug.cgi?id=78960 A workaround is to disable "Prefer VAAPI Render method" under Video -> Acceleration (Expert Mode). This will produce a bit more CPU load but will cure that error.

[History]
14/01/05: Update to kernel 3.13-rc7
14/01/12: Update to kernel 3.13-rc8
14/01/20: Update to kernel 3.13 final
14/01/30: Update to kernel 3.13.1
14/02/06: Told howto update.
14/02/07: Update to kernel 3.13.2
14/02/14: Update to kernel 3.13.3
16/02/14: Add code to set Display to RGB Full mode
14/02/22: Update to kernel 3.13.4
14/02/24: Update to kernel 3.13.5
14/04/09: Update to Ubuntu trusty
14/04/16: Coming from Saucy? Upgrade: http://forum.xbmc.org/showthread.php?tid...pid1677121
14/06/30: SwFilter Option has been removed. If you want to force a copy to system run disable the new setting: Prefer VAAPI Render in Video -> Acceleration. This is not needed in general, cause when Deinterlace or Bob is active this is automatically bypassed.
*14/08/23: Added wsnipex vaapi ppa to the howto. This will install an experimental intel-driver that can do MCDI and MADI. Beware it will crash roughly every 30 minutes when doing deinterlacing :-)
14/08/30: The crash has been fixed and you should be able to run MCDI without crashing
14/09/11: Rewrite of the indroduction part and settings.
14/10/20: Change The server iso to point to the trusty one.
14/11/18: Added login1 permissions to the pkla file. Replace yours if you don't have suspend / power off options anymore. Thanks to wsnipex.

Update 14/12/13 concerning the GPU HANG
Chris Wilson has finally fixed the GPU HANG! Thanks very much. You can download prebuild 3.18 kernels from here: https://bugs.freedesktop.org/show_bug.cgi?id=83677#c143
For installation do (first part is updating of the firmware, which is needed for wireless devices):
Code:
mkdir 3.18
cd 3.18
wget http://es.archive.ubuntu.com/ubuntu/pool/main/l/linux-firmware/linux-firmware_1.140_all.deb
sudo dpkg -i *linux-firmware*deb

wget https://dl.dropboxusercontent.com/u/55728161/linux-headers-3.18.0-ickle75%2B_3.18.0-ickle75%2B-10.00.Custom_amd64.deb https://dl.dropboxusercontent.com/u/55728161/linux-image-3.18.0-ickle75%2B_3.18.0-ickle75%2B-10.00.Custom_amd64.deb

sudo dpkg -i *3.18*ickle75*deb
Background:
When watching interlaced Content and MCDI / VAAPI-BOB or MCDI is selected this would implicitely use the VAAPI Render Method, which caused the GPU HANG issues on the chromebox. You need to run the patched 3.18.x kernel from above that has this issue fixed. Hopefully kernel 3.19 will have the fix mainlined.
(This post was last modified: Yesterday 13:42 by fritsch.)
find quote
Frank-NL Offline
Donor
Posts: 153
Joined: Sep 2012
Reputation: 2
Post: #2
A thank you to everybody involved. I currently use a i3 3220 with a GT610. The picture quality is great, but I'm wasting the built in GPU.

What are going to be the minimum requirements for T/S deinterlacing? The 3220 has
HD Graphics 2500, which is not really powerful.
find quote
fritsch Offline
Team-XBMC Developer
Posts: 7,175
Joined: Aug 2011
Reputation: 160
Location: Karlsruhe
Post: #3
Quote:Temporal / Spatial Deinterlacing will come during the end of the year. VPP is technically ready to use it, but - for now - no backend has implemented it (intel's job).

Nobody knows - cause it does not exist in the intel world for now.
find quote
Frank-NL Offline
Donor
Posts: 153
Joined: Sep 2012
Reputation: 2
Post: #4
OK. I guess I will have to wait for it to try. I really like T/S and the GT610 does of lot of it on my HTPC with 1080i live tv.
find quote
Hörnchen Offline
Junior Member
Posts: 3
Joined: May 2009
Reputation: 0
Post: #5
(2013-05-26 00:23)fritsch Wrote:  (*) Some Sandybridge chips need to have RC6 disabled. This has nothing to do with this version, but is a hw, driver, mesa bug - which is also existing with other versions. You know, that you are affected when your machine freezes instantly while watching some channels. To workaround it:
Code:
sudo edit /etc/default/grub
change the following line:
GRUB_CMDLINE_LINUX_DEFAULT="splash quiet"
to read:
GRUB_CMDLINE_LINUX_DEFAULT="i915.i915_enable_rc6=0 splash quiet"
afterwards:
sudo update-grub
sudo reboot

This workaround is not necessary if you disable RC6 in the Bios.
On the Biostar Celeron 847 Board RC6 can be disabled in the GPU Settings.
find quote
fritsch Offline
Team-XBMC Developer
Posts: 7,175
Joined: Aug 2011
Reputation: 160
Location: Karlsruhe
Post: #6
Yeah - no such bios setting on my Asus - and doing it in the OS has more flexibility. Did you already test the VPP? Does it work as you expected? You see the difference at all?
(This post was last modified: 2013-05-26 12:59 by fritsch.)
find quote
Morrtin Offline
Member
Posts: 67
Joined: Jul 2011
Reputation: 0
Location: Vienna
Post: #7
Hey Fritsch. I like to give it a try and preparing a fresh installation of Ubuntu. But before I would like to see how it look like before the change. Do you have video material where I have to deinterlace? I have no LiveTV :-(
find quote
fritsch Offline
Team-XBMC Developer
Posts: 7,175
Joined: Aug 2011
Reputation: 160
Location: Karlsruhe
Post: #8
Yes - of course: check that one: https://dl.dropboxusercontent.com/u/5572...erlaced.ts
Check the horicontal lines while, moving and also check that it jumps like hell - if you enable "deinterlacing" with current code
find quote
Morrtin Offline
Member
Posts: 67
Joined: Jul 2011
Reputation: 0
Location: Vienna
Post: #9
Thanks. When I play the movie now (De-interlace video: Off) I see horizontal lines when the cow is moving.

When I change my settings to:

De-interlace video: Auto
De-interlace method: Auto select
Video scaling method: Bilinear

I don't see this horizontal lines. For me it looks good. But as it is cold outside, I like to make a new server base installation, I will try it out anyway.
find quote
fritsch Offline
Team-XBMC Developer
Posts: 7,175
Joined: Aug 2011
Reputation: 160
Location: Karlsruhe
Post: #10
Did you test with the "new" ppa? (obviously you did) Could you get me your xbmc.log? To see everything works fine, including vainfo?
(This post was last modified: 2013-05-26 15:17 by fritsch.)
find quote
Morrtin Offline
Member
Posts: 67
Joined: Jul 2011
Reputation: 0
Location: Vienna
Post: #11
I tested it with official one -> ppa:team-xbmc/ppa

I just finished installing the base system. If you want I can install my usual system to get you a log and vainfo, or I could use the new vaapi ppa and test it there.

What shell it be? :-)
find quote
fritsch Offline
Team-XBMC Developer
Posts: 7,175
Joined: Aug 2011
Reputation: 160
Location: Karlsruhe
Post: #12
With the typical ppa, there is no deinterlacing at all - it just has that option and seems to double fps. You will see a whole lot jumping pixel up, pixel down, especially when you watch the logo of the station on the upper right, this is the reason for this VPP testing :-). Here, I made another sample, to better illustrate: https://dl.dropboxusercontent.com/u/55728161/tennis.ts
(This post was last modified: 2013-05-26 15:39 by fritsch.)
find quote
Frank-NL Offline
Donor
Posts: 153
Joined: Sep 2012
Reputation: 2
Post: #13
I tested the PPA this morning. Libva-glx1 was not updated automatically for some reason so first XBMC didn't want to start because of the video driver.

After that was fixed, everything seemed to work really well. Promising developments.

However I switched back to the GT610 because I couldn't fix the colorspace due to xrandr not working and swichting between refresh rates was really slow. I think I will give it a try again when there is a stable OE build with Gotham final.

Tested on Quantal by the way.
find quote
fritsch Offline
Team-XBMC Developer
Posts: 7,175
Joined: Aug 2011
Reputation: 160
Location: Karlsruhe
Post: #14
Thanks for the feedback, will add the libva-glx1 into the installation howto. Colorspace issues, can be workarounded or done via

Code:
for Limited:
DISPLAY=:0 xrandr --output HDMI1 --set "Broadcast RGB" "Limited 16:235"
xor for FULL:
DISPLAY=:0 xrandr --output HDMI1 --set "Broadcast RGB" "Full"

you need a recent kernel (best 3.9.x for this to work). It may be that the 3.9.0 kernel correctly identifies your TV / Color Range out of the box without doing anything additional.

-> Gotham for now sucks balls on vaapi, as mpeg-2 is severely broken within ffmpeg, all you get is a nice segfault :-).

On Ubuntu installation is rather easy:
64 bit:
Code:
mkdir ~/3.9.x
cd ~/3.9.x
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9.4-saucy/linux-headers-3.9.4-030904-generic_3.9.4-030904.201305241545_amd64.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9.4-saucy/linux-headers-3.9.4-030904_3.9.4-030904.201305241545_all.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9.4-saucy/linux-image-3.9.4-030904-generic_3.9.4-030904.201305241545_amd64.deb http://mirrors.us.kernel.org/ubuntu//pool/main/l/linux-firmware/linux-firmware_1.106_all.deb
sudo dpkg -i *deb
32 bit:
Code:
mkdir ~/3.9.x
cd ~/3.9.x
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9.4-saucy/linux-headers-3.9.4-030904-generic_3.9.4-030904.201305241545_i386.deb  http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9.4-saucy/linux-image-3.9.4-030904-generic_3.9.4-030904.201305241545_i386.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9.4-saucy/linux-headers-3.9.4-030904_3.9.4-030904.201305241545_all.deb http://mirrors.us.kernel.org/ubuntu//pool/main/l/linux-firmware/linux-firmware_1.106_all.deb
sudo dpkg -i *deb
sudo reboot
(This post was last modified: 2013-05-26 16:10 by fritsch.)
find quote
Frank-NL Offline
Donor
Posts: 153
Joined: Sep 2012
Reputation: 2
Post: #15
Ah I didn't do that. I am running the stock Quantal kernel, 3.5.0-31. I am stuck with that one because the HDHomerun driver will not compile on a newer Ubuntu kernel since they removed the dvb headers for an unknown reason.

Will there be an OE Frodo build with your patches? I am not interested in the Gotham builds since they are too alpha for my taste.
(This post was last modified: 2013-05-26 16:12 by Frank-NL.)
find quote
Post Reply