Friday, December 26, 2008

XBMC on Gentoo

Lately I have been a little obsessed with multimedia software. I have been trying out several different media center packages to see what each has to offer, and whats good/bad/ugly about each.

The most recent package I am trying out now is XBMC (xbox media center). I think this was originally developed for the 1st gen xbox console to turn it into a powerful media center. It has since been modified and adapted for multi platform (Linux, Win, OS X, Xbox etc). It has a lot to offer, but this write up is concerned mainly with getting it running on Gentoo, and not a review of the software itself.

The linux ports are geared toward ubuntu, but there is now an ebuild for gentoo, and (of course), the source is also readily available for anyone to check out and build on their own. One of the nice things about gentoo is its ability to track and emerge dependencies automatically, so I decided to give the ebuild a shot. Here's what I did (your system and experience may vary)

1. If you do not already have a portage overlay dir, you will need to create one. This is where you will store the ebuild file and patches for your system to use and keep separate from its "proper" portage dirs:

# mkdir -p /usr/local/overlay # make this dir as your primary overlay. You can place other packages here for testing.
# mkdir -p /usr/local/overlay/media-tv/xbmc/files # I chose to use media-tv, but you could use another approved component type.

2. Next, grab the latest ebuild file and patches. They are listed and available from the gentoo bugzilla page for the ebuild request (http://bugs.gentoo.org/198849).

# wget -O /usr/local/overlay/media-tv/xbmc/xbmc-8.10-r4.ebuild http://bugs.gentoo.org/attachment.cgi?id=176341
# wget -O /usr/local/overlay/media-tv/xbmc/files/xbmc.readsector.patch http://bugs.gentoo.org/attachment.cgi?id=176344

3. Make sure you have the PORTDIR_OVERLAY environment variable set in your make.conf:

# echo 'PORTDIR_OVERLAY="/usr/local/overlay"' >> /etc/make.conf

4. Next, update your ebuild manifest:

# ebuild /usr/local/overlay/media-tv/xbmc/xbmc-8.10-r4.ebuild digest
>>> Downloading 'http://ufpr.dl.sourceforge.net/sourceforge/xbmc/XBMC-8.10.src.tar.gz'
--2008-12-26 20:51:00-- http://ufpr.dl.sourceforge.net/sourceforge/xbmc/XBMC-8.10.src.tar.gz
Resolving ufpr.dl.sourceforge.net... 200.17.202.1, 200.236.31.1
Connecting to ufpr.dl.sourceforge.net|200.17.202.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 121992403 (116M) [application/x-gzip]
Saving to: `/usr/portage/distfiles/XBMC-8.10.src.tar.gz'

100%[==================================================================>] 121,992,403 710K/s in 2m 51s

2008-12-26 20:53:53 (697 KB/s) - `/usr/portage/distfiles/XBMC-8.10.src.tar.gz' saved [121992403/121992403]

>>> Creating Manifest for /usr/local/overlay/media-tv/xbmc

5. Next, add xbmc to package.keywords, since gentoo will see it as a masked package:
# echo "media-tv/xbmc **" >> /etc/portage/package.keywords

6. Finally, emerge xbmc

# emerge -av xbmc
My system emerged 15 packages total, and everything compiled just fine. I now have a working xbmc install on my Gentoo machine, and am poking at all the features and stuff now. So far it looks pretty slick!

Monday, December 1, 2008

Tversity for PS3 running in VirtualBox


My PS3 is now a big part of my media for my living room. It functions as my DVD player (Blu-Ray too of course), games, all sorts of video files, pics, audio, card reader etc. I was looking for a way to stream more of my content from my computer to the PS3, and there are lots of options out there, but I settled on TVersity. Its free for one, has a nice UI, is capable of streaming tons of content (youtube, hulu, CNN etc), capable of playback of tons of filetypes, and actually does encoding on the fly if needed. It also got great reviews so I decided to go with that.

One little catch though is that TVersity is Windows only right now. They mention something about porting it to linux in the future, but its not available yet. Since I only run Gentoo on my box, I tried to get it running in Wine, to no avail. So, I decided to install VirtualBox and then install Windows inside this instance and get it running there. Virtualbox is awesome, and installed perfectly, and I installed windows inside it as the guest OS. I ran into a few issues configuring it later, such as by default VirtualBox runs behind NAT, using the host interface for network, which is actually quite nice for being able to access the internet from within the instance, but sucks because its invisible to you LAN.

I then needed to setup an ethernet bridge so that my host and guest could both use the same interface, yet have individual ip's on my LAN, which would make my guest WinXP instance able to serve TVersity to my PS3 over my local network. I ran into a few more issues along the way (my linux kernel didnt have support compiled in for ethernet bridging etc). I grabbed a new kernel source (gentoo-sources; 2.6.26-r3) and compiled in support for bridging. Worked like a charm. After I got this working, I wrote a small bash script to create a bridge that allows both the host and guest os's to share the same device for network:
vbox_setup.sh:

#!/bin/bash

# Script to setup ethernet bridge for virtualbox guest os to share with
# primary eth0 device. By default, virtualbox guest os uses NAT behind its
# host's ip. This sets up an ethernet bridge that allows both the host and
# the guest os to share the same ethernet device on separate ips. Both host
# and guest will have individual ip's visible on the LAN.
# Script based on instructions found at: http://www.scottro.net/vboxbridge.html

# Author: Noah Maxwell (noah.maxwell@gmail.com)

echo "Adding br0..."
brctl addbr br0
sleep 2
echo "Bringing down eth0 interface..."
ifconfig eth0 0.0.0.0
sleep 2
echo "Adding br0 to eth0..."
brctl addif br0 eth0
sleep 2
echo "Assigned new ip to br0..."
dhcpcd br0
echo "Adding user: nmaxwell"
VBoxTunctl -b -u nmaxwell
ifconfig tap0 up
echo "Adding br0 to tap0..."
brctl addif br0 tap0
echo "Done!"
I can now see both my host Gentoo install and my guest WinXP install as individual nodes on my local network.

Next I setup a samba share for my video and audio directories on my Gentoo box, so that my WinXP instance could access that content, and finally stream it to my PS3. I finally got it working tonight, and it is awesome!

For avi files, it needs to transcode them on the fly, so the startup time takes a couple seconds, so I just pause it for 10-15 seconds before playing the content back and it plays flawlessly. Mp3's play perfectly too. Another cool thing about TVeristy is that it automatically updates its library every 24 hours automatically (or you can force a sync at anytime), so that I can add/remove or edit any content on the shared directories and TVersity keeps the library updated. This works well for me since I do all my video processing/encoding and stuff on my linux box.

This is the short story anyway, and it probably took me about 8 hours total to get all of this setup and working correctly, but it was fun and challenging. And yes, I am still hoping for a linux client for TVersity at some point, which will just mean my setup will be more efficient, but it was a good excuse to play with VirtualBox, and now I have a full WinXP instance I can launch from within Gentoo as well, so I no longer need to dual boot to use any windows apps.

Monday, November 24, 2008

fixfiles.py - A python script to rename files

Tired of crazy filenames with lots of spaces, CAPS and other characters on your linux machine? Many *nix users transfer files from windows or mac computers where filenames with spaces and other characters included in them dont matter so much. Here in the linux world, some people care about the excessive use of escaping all those spaces when addressing those filenames.

I wrote a simple python script to help me fix this for myself. The script will rename files that contain uppercase, ampersand or spaces and convert them into characters a bit more friendly to you while managing your files on your linux machine. Here is an example of it in action:

$ fixfiles.py /home/nmaxwell/foo/
Renaming: foo/YaDDA YAdda YaddA to: foo/yadda__yadda_yadda__
Renaming: foo/File With CAPS & Stuff to: foo/file_with_caps_-and-_stuff
Renaming: foo/BaZ to: foo/baz
Renaming: foo/Bar to: foo/bar
Renaming: foo/fOO to: foo/foo

As shown, it just searches filenames in a given directory, and renames them to be a little friendlier for you by changing the characters to something easier to manage.

Download fixfiles.py

Wednesday, November 19, 2008

Resizing avi or mpg video files for pmp devices

Recently I was looking for a small linux program to resize my avi and mpg files down to a smaller resolution to fit on my pmp device (Cowon D2), but didn't find much in the way of lightweight programs to do this. Up until now, I have just been using transcode on the cli with a bunch of options, but got tired of typing `history | grep transcode` or Ctrl+r to search my bash history for the exact params I used last time.

So, I just scripted this into a tiny python program to do what I wanted. Its called mini-encoder.py and simply resizes an avi or mpg file down to a resolution of 320x240, which is the native resolution on my Cowon D2 pmp player. The script also does some checks to make sure you are using the right input files, and that they actually exist!

The resolution is also hard-coded in the script itself, so if you want to use it and need a different resolution, just alter the resolution setting in the script. I am planning on adding a command line option to specify a resolution of choice, but haven't got around to doing it yet. Hope someone else finds this useful too. Enjoy!

Click on the link below to download the script (I have this hosted @ box.net):

Download mini-encoder.py