XMBC Part IV: Accelerated Video Playback with an ATI HD5450

26 01 2011

I use my HTPC primarily for video playback, watching high definition movies and series. As you can see in one of my previous posts, I have an Ati Graphics Card in my HTPC. This card supports so called Video Acceleration (VA), which is just a fancy name for the ability to decode certain video files, like H264 encoded MKV-files. The advantage of watching video with VA is that the video decoding is entirely done by the GPU, leaving the CPU to do other important things.

Now if you have an NVidea graphics card, enabling VA isn’t that big of a deal. But enabling VA with an Ati card can be quite challenging. So this post is for all those XBMC users whom do not have that much linux experience (like me…) and would like the benefits of VA.

Because of the length of this blog, I have split it into three parts:

  1. Installing the graphics card drivers. You will need to get the latest official drivers from the Ati website and install them.
  2. Installing the Video Acceleration libraries. The actual Video Acceleration libraries are distributed in yet another package.
  3. Recompiling XBMC. The standard XBMC doesn’t support Video Acceleration for Ati card, so we need to manually compile XBMC ourselves.

Now if you are a Windows user like me, you are used to searching the internet for free software, download it, and install the software using the provided installation program. While that is also possible with Ubuntu, there is also another mechanism. In this post we will extensively use the Advanced Packaging Tool, or in short APT. Using apt-commands we can do all the above (search, download, and install) with one simple command. I won’t go into that much detail about the commands as you are used from me, as that will probably lengthen this post even more.

Part 1: Installing the graphics card drivers

  1. Exit XBMC. You can use the most right button on the bottom of the screen to exit XBMC.
    images
  2. Open a command line terminal and update the APT index. You will need an internet connection as this command will instruct APT to retrieve the available package listings and the update its internal package index.
    sudo apt-get update
  3. Now update all currently installed packages.
    sudo apt-get upgrade
  4. Before we download the needed drivers, create a directory to bundle everything together.
    mkdir VAAPI
    cd VAAPI
  5. Ati provides the Catalyst drivers as their recommended drivers for Linux based systems. The current version is the Ati Catalyst 10.12 driver, but you can check the Ati website to find the latest version. Download the latest drivers using the wget command.
    wget https://a248.e.akamai.net/f/674/9206/0/www2.ati.com/drivers/linux/ati-driver-installer-10-12-x86.x86_64.run
  6. As you can see, this command ends with .run. To make sure we can actually run this file change the permissions of this file.
    chmod +x ati-driver-installer-10-12-x86.x86_64.run
  7. The next statement will execute the file. Specifically it will run the file and instruct it to build the needed packages for an Ubuntu/lucid operating system. If you have another (version of) operating system, you might want to change this parameter.
    sudo ./ati-driver-installer-10-12-x86.x86_64.run –-buildpkg Ubuntu/lucid
  8. The packages will be saved in the current directory. Install all these packages. Tip: use the * wildcard.
    sudo dpkg -i *.deb
  9. After the packages are deployed, configure the Ati display drivers.
    sudo aticonfig –initial
  10. Now reboot your system. As soon as XBMC is fully loaded again, switch back to the command line interface (Ctrl+1).
    sudo reboot
  11. The following command will test your driver configuration. The –display 0:0 parameter tells the command what display is used. If you receive an error like “Unable to find display”, play around with the parameter, using various options like 0:1 or 1:1.
    fgl_glxgears -display 0:0
  12. If the above command succeeded a 3D moving cube is present on your display, but you will have to switch back to XBMC to see it (Ctrl+7 ). If your screen is all messed up like mine, you can try another configuration:
    sudo aticonfig –initial –tls=0
    sudo reboot

Part 2: Installing the Video Acceleration libraries

  1. Switch to the command line interface, if you haven’t already done so. Open the directory we created earlier en dowload the VA drivers. As you can see, the VA drivers aren’t supplied by Ati, but a certain enhousiasic called G. Beauchesne.
    cd VAAPI
    wget http://www.splitted-desktop.com/~gbeauchesne/xvba-video/xvba-video-latest.i686.deb
    wget http://www.splitted-desktop.com/~gbeauchesne/libva/libva-latest.tar.gz
  2. Before we can install the VA drivers, we need some other packages, quite al lot of them actually. Luckily you can download and install all of them with one command. The package manager will only download and install missing packages and automatically update any old packages.
    sudo apt-get install cdbs autotools-dev libdrm-dev x11proto-xext-dev libxext-dev libxfixes-dev libgl-dev pkg-config automake1.9 libtool libgl-mesa-dev
  3. The Video Acceleration drivers are bundled together in a Tar-archive. For all those Windows users, just compare it to a .zip or .cab. Untar the packages:
    tar -xvzf libva-latest.tar.gz
  4. The drivers are placed in a subdirectory within your current directory, in my case “libva-0.31.1”. Enter this directory, you can use the ls command if you are unsure about the directory.
    cd libva-0.31.1/
  5. The next step is to build the packages.
    dpkg-buildpackage -rfakeroot -uc -us
  6. The packages are placed one directory up. Don’t ask me why, I have no idea.
    cd ..
  7. The build command generated 4 packages, together with the package we downloaded in step 1, there will be 5 packages in this directory. Install these packages. See note as bottom if you have version 0.31-1 sds5)
    sudo dpkg -i libva1_0.31.1-1+sds4_i386.deb
    sudo dpkg -i libva-dev_0.31.1-1+sds4_i386.deb
    sudo dpkg -i libva1-dbg_0.31.1-1+sds4_i386.deb
    sudo dpkg -i libva-driver-i965_0.31.1-1+sds4_i386.deb
    sudo dpkg -i xvba-video-latest.i686.deb
  8. Now the Video Acceleration drivers are all installed. As a final step, reboot your system.
    sudo reboot

Part 3: Recompiling XBMC

  1. Congratulation, you made it through the most difficult part of this post. These last few steps are all about recompiling XBMC, but before you can compile XBMC you will need to install even more packages. Quit XBMC and install these packages.
    sudo apt-get install git-core make g++ gcc gawk pmount libtool nasm yasm automake cmake gperf zip unzip bison libsdl-dev libsdl-image1.2-dev libsdl-gfx1.2-dev libsdl-mixer1.2-dev libfribidi-dev liblzo2-dev libfreetype6-dev libsqlite3-dev libogg-dev libasound-dev python-sqlite libglew-dev libcurl3 libcurl4-gnutls-dev libxrandr-dev libxrender-dev libmad0-dev libogg-dev libvorbisenc2 libsmbclient-dev libmysqlclient-dev libpcre3-dev libdbus-1-dev libhal-dev libhal-storage-dev libjasper-dev libfontconfig-dev libbz2-dev libboost-dev libenca-dev libxt-dev libxtst-dev libxmu-dev libpng-dev libjpeg-dev libpulse-dev mesa-utils libcdio-dev libsamplerate-dev libmms-dev libmpeg3-dev libfaad-dev libflac-dev libiso9660-dev libass-dev libssl-dev fp-compiler gdc libwavpack-dev libmpeg2-4-dev libmicrohttpd-dev libmodplug-dev libssh-dev gettext cvs
  2. Now that we have all packages in place, download the very latest source code from git. Git is a source code control repository that the developers of XBMC use to store their source code, track changes, etc. For the convenience, make another directory to store the source code.
    mkdir XBMC-source
    cd XBMC-source
    sudo git clone git://xbmc.git.sourceforge.net/gitroot/xbmc/xbmc
  3. After the download is completed, run the bootstrap script.
    sudo ./bootstrap
  4. The next script will set the compile options. We need the parameter –-prefix=/usr to tell the compiler the location of XBMC so that it will overwrite the current installation of XMBC with our new freshly compiled version. The most important option is the ––enable-vaapi . This tells the compiler to create XBMC with Video Acceleration Application Programming Interface (VAAPI).
    sudo ./configure –prefix=/usr –enable-vaapi
  5. After we configured the compile time options, we can compile our own version of XBMC. My CPU supports hyperthreading, so I use the –j2 option for multi-threaded compilation. If you have a dual-, quad-. hexa-core processor you can also use this option; if unsure just omit this option.
    sudo make -j2
  6. After compilation of XBMC, we can install XBMC.
    sudo make install
  7. The final step in the command line interface is to reboot your system.
    sudo reboot
  8. In XBMC navigate to your video settings and enable VAAPI.
    VAAPI
  9. Start your favourite H264 encoded (full definition) movie. While playing press “o” to see some system information. The video decoder should be something like “ff-h264-vaapi”. As you can see in this screenshot, the video encoding is done by the graphical card, and the processor is almost down to 0%.
    VAAPI h264

I took me quite a few hours to get the hang of this. I hope you enjoyed this rather lengthy post and can now enjoy Video Acceleration playback of your favourite movies.


Read the rest of this entry »





XBMC Part III: Adding a hard drive

16 01 2011

In one of my previous posts I explained how to install XBMC Live on a USB pen drive. My USB pen drive is 8 gigabyte large; while that is enough for XMBC to run, the 8 gig is not even enough to store one (High Definition) movie nowadays.

For that reason I added a 2 terabyte internal hard drive to my HTPC system. The hard drive is fresh from the factory,  and is ready for its first run. Before you continue with this how-to, be aware that any data present on the hard drive will be irreversibly deleted.

  1. Open a command line terminal and list all available fixed disks.
    sudo fdisk –l
  2. In the output of fdisk command search for your new hard drive. You can probably find by the size of your hard disk. Also, there shouldn’t be any partitions on the hard drive (if it is a new hard drive). Remember the path of the hard drive; in this case it’s: /dev/sda
    Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
  3. The next step is to create a partition on the hard drive using fdisk <disk>.
    sudo fdisk /dev/sda
  4. This command will open the fdisk prompt. I am going to create one NTFS partition on the hard drive occupying the entire disk. Your setup can differ from mine, so feel free to create other partitions. Below, I will show the transcript of my setup. You can press m to see more information about the available commands.

    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-243201, default 1): 1
    Last cylinder, +cylinders or +size{K,M,G} (1-243201, default 243201):
    Using default value 243201

    Command (m for help): t
    Selected partition 1

    Hex code (type L to list codes): 7
    Changed system type of partition 1 to 7 (HPFS/NTFS)

    Command (m for help): w

  5. You can check the partitions of your hard drive using the fdisk –l command.
    sudo fdisk –l
  6. It will show the newly created partitions on the hard drive.
    Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
    255 heads, 63 sectors/track, 243201 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
        Device Boot      Start         End      Blocks   Id  System

       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1      243201  1953512001    7  HPFS/NTFS

  7. To create a NTFS filesystem on the new partition use the mkfs.ntfs command (make filesystem).
    sudo mkfs.ntfs /dev/sda1

    or

    sudo mkfs.ntfs –f –L Data /dev/sda1
  8. The latter of the above commands uses the option –f for fast creation of the filesystem. If you don’t specify this option, creating a 2Gig NTFS filesystem can take up to 4 hours. The –L Data options assigns the label “Data” to the filesystem.
    sudo mkfs.ntfs –f –L Data /dev/sda1
  9. Create a new directory in the user folder. This directory will ‘point’ to the new hard drive. I will name this directory Data as it will contain my data. Replace <user> with your username. 
    mkdir /home/<user>/Data
  10. Now that the partition is created and has a filesystem, the new disk can be mounted. The file fstab contains the filesystem table. Open this text file using the nano.
    sudo nano /etc/fstab
  11. Add the following line to fstab text file. Press Ctrl+X to save, Y to confirm. 
    /dev/sda1 /home/<user>/Data ntfs rw 0 0
  12. Mount the hard drive. The option –a will use the fstab file to mount the drives. 
    sudo mount -a

The hard drive is now ready to use.





XMBC Part II: Connecting the internet

14 01 2011

If you followed the tutorial in my previous blog, you probably ended up with a XBMC environment that boots from an USB pen drive. As you might have noticed, the internet connection is broken. This is because the XMBC was installed in a virtual environment with simulated hardware. Now that the XBMC boots from ‘real’ hardware some configurations (including the network configuration) are incorrect.

As I explained I am not a Linux guru; until a few days ago I only knew the command ls and that is because Microsoft decided to implement it into Microsoft Powershell. In this post I will explain how to set up a internet connection for the XBMC environment. We will use simple commands from the command line interface. Most of these commands are abbreviations and I will try to give some background information so the abbreviated commands will stick better.

Note that any changes we make to the XMBC install on the USB pen drive will render the installation more and more dedicated to a single machine.

So let’s get started:

  1. When XBMC boots it will automatically login and show the graphical user interface of XBMC. To switch to the command line interface (CLI) you need to press ctrl+alt+1 or ctrl+alt+2, etc. By default, there are 6 simultaneous CLI’s available.
  2. Log in with your username and password. Note that the password prompt will not display any characters as you type.
  3. The command ifconfig displays information about the Interface Configuration. Only information about the active network connections will show up.  
    ifconfig
  4. If your configuration is close to my configuration the command will display the active network connection lo
    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mark 255.0.0.0
  5. The network connection Lo is the Loopback connection. It allows the machine to find itself. This is the only active connection currently. The command ifconfig –a will display all network connections; active and inactive.  
    ifconfig –a
  6. The result of the previous command shows that another network connection is available, in my case the eth1 (ethernet). If you have a WiFi card it might show up as ra0 or something alike. 
    eth1

    lo

    Link encap: Ethernet
    BROADCASE MULTICAST MTU:1500 METRIC 1

    Link encap:Local Loopback
    inet addr:127.0.0.1 Mark 255.0.0.0

  7. To enable the eth0 network connection, we can simply use the command ifconfig eth0 up. However the next time the system boots, the eth0 connection might be disabled again. To make sure the network connection will be enabled every time, we are going to make some changes to the interfaces file.  
    sudo nano /etc/network/interfaces
  8. Let’s review this command before we move on. Because the interfaces file is a system file, we need special persmissions to edit this file. The command sudo will elavate the current priviliges. Sudo stands for substitute user do (or Super User do). Any commands following this will be executed as the root user. Nano is a light weight text editor in linux, nothing more, nothing less. And finally /etc/network/interfaces is the file to edit. All together; open the interfaces file in a text editor with root permissions.
  9. My file looks something like below:  
    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    auto eth0
    iface eth0 inet dhcp

  10. . Notice that it defines eth0 is my primary network interface, while the ifconfig shows that it should be eht1. Change both occurrences of the eth0 to eth1. To save this file press ctrl+x en press Y to confirm.
  11.   Now that the the interfaces file is reconfigured, reload the network interfaces.  
    sudo /etc/init.d/networking restart
  12. The init.d directory contains start-up scripts. These scripts are automatically executed every time the system starts. The script networking is responsible for loading the network interfaces. In short; this command uses elevated privileges to restart the networking script.
  13. To test if we have an internet connection we can simply ping a URL look google. The –c 1 stands for count 1, meaning it will only ping 1 time. 
    ping http://www.google.com –c 1
  14. If all if configured right, it should generate a response displaying the time in milliseconds to reach the google.com.If  you see errors, double-check the network settings and your modem/router settings.

To return to the XMBC grahpical user interface press ctrl+alt+7. You can now use any options that needs an internet connection.





Installing XBMC Live on an USB Pen drive

13 01 2011

I recently bought an Home Theater PC (HTPC). It is not a state-of-the-art machine but I am hoping it will ‘do the trick’. In a series of posts on this blog I will explain how to setup a HTPC with XBMC. My HTPC exists of the following components:

Casing Fujitsu-Siemens Scaleo E
Motherboard FIC Triton i915G
Processor Intel Pentium 4 651 3.4Ghz x64 (Cedar Mill)
Processor cooler Passive Socket775
Memory 4x 512 MB DDR SDRAM PC3200
Graphics Club3D HD5450 512MB DDR3 LowProfile Silent
Hard Disk Samsung EcoGreen F4EG, 2TB 5400rpm
Optical Drive DVD Brander Lite-ON IDE
USB Pen Drive Transcent 8GB JetFlash 300 USB2.0

I am a Microsoft Windows user and have virtually no experience with Linux based systems. So off course I could take the easy way and install Microsoft Windows 7 and the Windows version of XMBC on it. However, I am not going to take the easy way.

You will need a USB pen drive with of least 2 GB, but a pen drive of 8 GB (or more) is recommended.  

Enough chatter; let’s get started!

  1. Download the XBMC Live CD from http://xbmc.org/download/. The current release is the Dharma version 10.0. It is about 413 MB large
  2. We are going to prepare the USB disk on another machine (told you I am a Windows fan). Download and install Oracle Virtual Box from http://www.virtualbox.org/wiki/Downloads. Virtual Box lets us create a virtual machine. If you are new to virtualization, don’t worry. I will guide you through it.
  3. Open Virtual Box and create a new virtual machine using the New-button.
    001.OracleVirtualBox
  4. Choose a suitable name for the Virtual Machine and select the Operating System Unix and Version Ubuntu.
    002.OracleVirtualBox_NewMachine
  5. In the next wizard step we can choose how much memory to assign to the virtual machine. The recommended value is 512 MB, which is already the default value in my case.  
    003.OracleVirtualBox_RAM
  6. We downloaded a Live version of XBMC, so we don’t need a hard disk. Uncheck the Boot Hard Disk checkbox. Virtual Box will ask for a confirmation to ask whether we are sure we don’t want to add a hard disk. Just press continue
    004.OracleVirtualBox_HardDisk
  7. Virtual Box will present a summary of the choices. It should look something like this. Press Finish to create the virtual machine.
    005.OracleVirtualBox_Summary
  8. After the virtual machine is created, Virtual Box will present the starting screen with the new virtual machine.
    006.OracleVirtualBox_MachineCreated
  9. Select the newly created virtual machine and press Settings. Navigate to the Storage tab and select the CD/DVD-Rom icon. Choose for the option to add a Virtual CD/DVD Disk and select the downloaded XCMB image.007.OracleVirtualBox_AddImage
  10. Plug in your USB pen drive (if you didn’t do it already) and navigate to the USB tab. Check the checkbox to enable USB 2.0  and add your USB device.007.OracleVirtualBox_AddUSB
  11. Now is it time to boot the virtual machine. Return to the Virtual Box main screen, select the virtual machine and press the Start-button. If you configured everything correct the new virtual machine will show the XBMC boot screen. Select the option Install XBMCLive.
    007.OracleVirtualBox_BootXBMCLive
  12. Select the XBMC default language and your country. I will install XBMC in Dutch because I live in the Netherlands.
    010.XBMCInstall_Language
  13. The XBMC installer will automatically detect your hardware, network settings, etc. The next screen will present some choices where you can choose how to partition your USB pen drive. Mine USB pen drive is empty and I do not plan to use it for any other purpose other than running XBMC. Therefor I chose the option Guided – Use Entire Disk. This option will create an ext4 partition for XBMC and a separate swap partition.
    011.XBMCInstall_Partitions
  14. Confirm the USB pen drive by selecting the corresponding disk.012.XBMCInstall_PartitionsUSB
  15. Warning! The next step will delete any data on the USB pen drive! Select Finish partitioning and write changes to disk.
    013.XBMCInstall_PartitionsFinish
  16. The XBMC installer will now partition the USB pen drive and copy the necessary files to USB pen drive. This can take a while so I suggest getting a cup of coffee.
    014.XBMCInstall_Installing
  17. Supply the XBMC installer with your name, username and password to further personalize your XBMC environment. The installer will continue to make some more adjustments and reboot. Congratulations! XMBC is now installed on a USB pen drive.

Now you can unplug your USB pen drive and use it any machine able to boot from USB. Settings (dand other data) will be saved directly to the USB pen drive. In the next post I will explain how to connect to the internet.